diff options
| author | Ha Thach <[email protected]> | 2021-06-12 23:16:57 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-06-12 23:16:57 +0700 |
| commit | 2b5bad7362f96ed376d0cc6e68c5ea1fc00dd4a4 (patch) | |
| tree | 75639e526899dcdbfed3e5d5aa3a3e4c505130bb /hw | |
| parent | b34724215bea28ef93fd80ed9c2e4ddc87874093 (diff) | |
| parent | e4da606164c434f24d9aa157438170f6ef5fbe2f (diff) | |
Merge pull request #889 from kilograham/master
Make examples standalone buildable via CMake
Diffstat (limited to 'hw')
| -rw-r--r-- | hw/bsp/esp32s2/family.cmake | 3 | ||||
| -rw-r--r-- | hw/bsp/esp32s3/family.cmake | 3 | ||||
| -rw-r--r-- | hw/bsp/family_common.cmake | 57 | ||||
| -rw-r--r-- | hw/bsp/family_support.cmake | 71 | ||||
| -rw-r--r-- | hw/bsp/rp2040/family.cmake | 4 |
5 files changed, 73 insertions, 65 deletions
diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index 9eb1627a1..f3d41d041 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -4,7 +4,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s2) - -# include basic family CMake functionality set(FAMILY_MCUS ESP32S2) -include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index c99c3728b..511dd58bb 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -4,7 +4,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s3/boards" "${TOP}/hw/bsp/esp32s3/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s3) - -# include basic family CMake functionality set(FAMILY_MCUS ESP32S3) -include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/family_common.cmake b/hw/bsp/family_common.cmake deleted file mode 100644 index 2544c58c6..000000000 --- a/hw/bsp/family_common.cmake +++ /dev/null @@ -1,57 +0,0 @@ -if (NOT FAMILY_MCUS) - set(FAMILY_MCUS ${FAMILY}) -endif() - -# save it in case of re-inclusion -set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") - -function(family_filter RESULT DIR) - get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - file(GLOB ONLYS "${DIR}/.only.MCU_*") - if (ONLYS) - foreach(MCU IN LISTS FAMILY_MCUS) - if (EXISTS ${DIR}/.only.MCU_${MCU}) - set(${RESULT} 1 PARENT_SCOPE) - return() - endif() - endforeach() - else() - foreach(MCU IN LISTS FAMILY_MCUS) - if (EXISTS ${DIR}/.skip.MCU_${MCU}) - set(${RESULT} 0 PARENT_SCOPE) - return() - endif() - endforeach() - endif() - set(${RESULT} 1 PARENT_SCOPE) -endfunction() - -function(family_add_subdirectory DIR) - family_filter(SHOULD_ADD "${DIR}") - if (SHOULD_ADD) - add_subdirectory(${DIR}) - endif() -endfunction() - -function(family_get_project_name OUTPUT_NAME DIR) - get_filename_component(SHORT_NAME ${DIR} NAME) - set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) -endfunction() - -function(family_initialize_project PROJECT DIR) - family_filter(ALLOWED "${DIR}") - if (NOT ALLOWED) - get_filename_component(SHORT_NAME ${DIR} NAME) - message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") - endif() -endfunction() - -# configure an executable target to link to tinyusb in device mode, and add the board implementation -function(family_configure_device_example TARGET) - # default implentation is empty, the function should be redefined in the FAMILY/family.cmake -endfunction() - -# configure an executable target to link to tinyusb in host mode, and add the board implementation -function(family_configure_host_example TARGET) - # default implentation is empty, the function should be redefined in the FAMILY/family.cmake -endfunction() diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake new file mode 100644 index 000000000..af0e00b2d --- /dev/null +++ b/hw/bsp/family_support.cmake @@ -0,0 +1,71 @@ +if (NOT TARGET _family_support_marker) + add_library(_family_support_marker INTERFACE) + + if (NOT FAMILY) + message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the camke command line") + endif() + + if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) + message(FATAL_ERROR "Family '${FAMILY}' is not known/supported") + endif() + + function(family_filter RESULT DIR) + get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + file(GLOB ONLYS "${DIR}/.only.MCU_*") + if (ONLYS) + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.only.MCU_${MCU}) + set(${RESULT} 1 PARENT_SCOPE) + return() + endif() + endforeach() + else() + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.skip.MCU_${MCU}) + set(${RESULT} 0 PARENT_SCOPE) + return() + endif() + endforeach() + endif() + set(${RESULT} 1 PARENT_SCOPE) + endfunction() + + function(family_add_subdirectory DIR) + family_filter(SHOULD_ADD "${DIR}") + if (SHOULD_ADD) + add_subdirectory(${DIR}) + endif() + endfunction() + + function(family_get_project_name OUTPUT_NAME DIR) + get_filename_component(SHORT_NAME ${DIR} NAME) + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) + endfunction() + + function(family_initialize_project PROJECT DIR) + family_filter(ALLOWED "${DIR}") + if (NOT ALLOWED) + get_filename_component(SHORT_NAME ${DIR} NAME) + message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") + endif() + endfunction() + + # configure an executable target to link to tinyusb in device mode, and add the board implementation + function(family_configure_device_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake + endfunction() + + # configure an executable target to link to tinyusb in host mode, and add the board implementation + function(family_configure_host_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake + endfunction() + + include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) + + if (NOT FAMILY_MCUS) + set(FAMILY_MCUS ${FAMILY}) + endif() + + # save it in case of re-inclusion + set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") +endif()
\ No newline at end of file diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 752eb0cab..41960b6cd 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -3,7 +3,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker) add_library(_rp2040_family_inclusion_marker INTERFACE) if (NOT BOARD) - message(FATAL_ERROR "BOARD must be specified") + message("BOARD not specified, defaulting to pico_sdk") + set(BOARD pico_sdk) endif() # add the SDK in case we are standalone tinyusb example (noop if already present) @@ -11,7 +12,6 @@ if (NOT TARGET _rp2040_family_inclusion_marker) # include basic family CMake functionality set(FAMILY_MCUS RP2040) - include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) |
