Rework rp2040 examples and CMake build:

- 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.
This commit is contained in:
graham sanderson
2021-05-30 18:41:07 -05:00
parent edbccb5e19
commit 95f2478146
36 changed files with 616 additions and 822 deletions

View File

@@ -1,37 +1,28 @@
# use BOARD-Directory name for project id
get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(PROJECT ${BOARD}-${PROJECT})
cmake_minimum_required(VERSION 3.5)
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake)
# Check for -DFAMILY=
if(FAMILY STREQUAL "rp2040")
cmake_minimum_required(VERSION 3.12)
include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake)
project(${PROJECT})
add_executable(${PROJECT})
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})
include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
project(${PROJECT})
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
)
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
add_executable(${PROJECT})
# Example defines
target_compile_definitions(${PROJECT} PUBLIC
CFG_TUSB_OS=OPT_OS_PICO
)
# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
)
else()
message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}")
endif()
# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Configure compilation flags and libraries for the example... see the corresponding function
# in hw/bsp/FAMILY/family.cmake for details.
family_configure_device_example(${PROJECT})