mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
95f2478146
- Examples should be CMake buildable from their own subdirectory; such a build will error out based on matching .skip.MCU_xxx or a mismatched .only.MCU_ - It should be possible to build from a higher level and use .skip.MCU_ and .only.MCU_ to filter which examples get built - The intention is for the CMakeLists.txts in the examples to be non family specific and without MCU based IFs. I have started this work, but am not really sure the state of the esp32 stuff; in any case the plan is to have everything encapsulated in the FAMILY/family.cmake - pico_examples now just includes examples/device/CMakeLists.txt and examples/host/CMakeLists.txt directly, as they also build correctly when included from there. Note that .skip.MCU_ for esp32 in the directories it wasn't previously avaiable has not been added, as the .skip is common to the regular Makefile builds also. It isn't clear whether these examples should build for esp32, but if not .skip should be added.
62 lines
2.1 KiB
CMake
62 lines
2.1 KiB
CMake
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)
|
|
if (TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD OR NOT DEFINED TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD)
|
|
set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${BOARD}-${SHORT_NAME} PARENT_SCOPE)
|
|
else()
|
|
set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE)
|
|
endif()
|
|
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()
|