diff --git a/pico_sdk_init.cmake b/pico_sdk_init.cmake index e8405b249..a21e56b26 100644 --- a/pico_sdk_init.cmake +++ b/pico_sdk_init.cmake @@ -60,4 +60,12 @@ if (NOT TARGET _pico_sdk_pre_init_marker) include(${LIST_FILE}) endforeach() endmacro() + + macro(pico_promote_common_scope_vars) + set(PICO_INCLUDE_DIRS ${PICO_INCLUDE_DIRS} PARENT_SCOPE) + set(PICO_SDK_POST_LIST_DIRS ${PICO_SDK_PRE_LIST_FILES} PARENT_SCOPE) + set(PICO_SDK_POST_LIST_FILES ${PICO_SDK_POST_LIST_FILES} PARENT_SCOPE) + set(PICO_CONFIG_HEADER_FILES ${PICO_CONFIG_HEADER_FILES} PARENT_SCOPE) + set(PICO_RP2040_CONFIG_HEADER_FILES ${PICO_RP2040_CONFIG_HEADER_FILES} PARENT_SCOPE) + endmacro() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30f334fdb..59f293366 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ function(pico_add_subdirectory subdir) else () message("Not including ${subdir} because ${replace_flag} defined.") endif () + pico_promote_common_scope_vars() endfunction() # add a link option to wrap the given function name; i.e. -Wl:wrap=FUNCNAME for gcc @@ -115,4 +116,6 @@ function(pico_add_doxygen_exclude SOURCE_DIR) set(PICO_DOXYGEN_EXCLUDE_PATHS "${PICO_DOXYGEN_EXCLUDE_PATHS} ${SOURCE_DIR}" CACHE INTERNAL "") endfunction() -include(${PICO_PLATFORM_CMAKE_FILE}) \ No newline at end of file +include(${PICO_PLATFORM_CMAKE_FILE}) + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 9b256a080..9948db0ab 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -13,4 +13,6 @@ if (NOT PICO_BARE_METAL) pico_add_subdirectory(pico_stdlib) endif() -pico_add_doxygen(${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file +pico_add_doxygen(${CMAKE_CURRENT_LIST_DIR}) + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/common/pico_base/CMakeLists.txt b/src/common/pico_base/CMakeLists.txt index af04c121c..3555dc0c3 100644 --- a/src/common/pico_base/CMakeLists.txt +++ b/src/common/pico_base/CMakeLists.txt @@ -1,40 +1,13 @@ if (NOT TARGET pico_base_headers) - # build the auto gen config headers - - set(header_content "// AUTOGENERATED FROM PICO_CONFIG_HEADER_FILES and then PICO__CONFIG_HEADER_FILES\n// DO NOT EDIT!\n") - string(TOUPPER ${PICO_PLATFORM} PICO_PLATFORM_UPPER) - - macro(add_header_content_from_var VAR) - set(header_content "${header_content}\n\n// based on ${VAR}:\n") - foreach(var IN LISTS ${VAR}) - set(header_content "${header_content}\n#include \"${var}\"") - endforeach() - endmacro() - - # PICO_CMAKE_CONFIG: PICO_CONFIG_HEADER_FILES, List of extra header files to include from pico/config.h for all platforms, type=list, default="", group=pico_base - add_header_content_from_var(PICO_CONFIG_HEADER_FILES) - - # PICO_CMAKE_CONFIG: PICO_CONFIG_RP2040_HEADER_FILES, List of extra header files to include from pico/config.h for rp2040 platform, type=list, default="", group=pico_base - # PICO_CMAKE_CONFIG: PICO_CONFIG_HOST_HEADER_FILES, List of extra header files to include from pico/config.h for host platform, type=list, default="", group=pico_base - add_header_content_from_var(PICO_${PICO_PLATFORM_UPPER}_CONFIG_HEADER_FILES) - - file(GENERATE - OUTPUT ${CMAKE_BINARY_DIR}/generated/pico_base/pico/config_autogen.h - CONTENT "${header_content}" - ) - - configure_file( include/pico/version.h.in ${CMAKE_BINARY_DIR}/generated/pico_base/pico/version.h) - add_library(pico_base_headers INTERFACE) target_include_directories(pico_base_headers INTERFACE include ${CMAKE_BINARY_DIR}/generated/pico_base) - foreach(DIR IN LISTS PICO_INCLUDE_DIRS) - target_include_directories(pico_base_headers INTERFACE ${DIR}) - endforeach() - # PICO_BUILD_DEFINE: PICO_BOARD, Name of board, type=string, default=CMake PICO_BOARD variable, group=pico_base target_compile_definitions(pico_base_headers INTERFACE PICO_BOARD="${PICO_BOARD}") target_link_libraries(pico_base_headers INTERFACE pico_platform_headers) + + list(APPEND PICO_SDK_POST_LIST_FILES ${CMAKE_CURRENT_LIST_DIR}/generate_config_header.cmake) + pico_promote_common_scope_vars() endif() \ No newline at end of file diff --git a/src/common/pico_base/generate_config_header.cmake b/src/common/pico_base/generate_config_header.cmake new file mode 100644 index 000000000..333dfa750 --- /dev/null +++ b/src/common/pico_base/generate_config_header.cmake @@ -0,0 +1,29 @@ +# build the auto gen config headers + +set(header_content "// AUTOGENERATED FROM PICO_CONFIG_HEADER_FILES and then PICO__CONFIG_HEADER_FILES\n// DO NOT EDIT!\n") +string(TOUPPER ${PICO_PLATFORM} PICO_PLATFORM_UPPER) + +macro(add_header_content_from_var VAR) + set(header_content "${header_content}\n\n// based on ${VAR}:\n") + foreach(var IN LISTS ${VAR}) + set(header_content "${header_content}\n#include \"${var}\"") + endforeach() +endmacro() + +# PICO_CMAKE_CONFIG: PICO_CONFIG_HEADER_FILES, List of extra header files to include from pico/config.h for all platforms, type=list, default="", group=pico_base +add_header_content_from_var(PICO_CONFIG_HEADER_FILES) + +# PICO_CMAKE_CONFIG: PICO_CONFIG_RP2040_HEADER_FILES, List of extra header files to include from pico/config.h for rp2040 platform, type=list, default="", group=pico_base +# PICO_CMAKE_CONFIG: PICO_CONFIG_HOST_HEADER_FILES, List of extra header files to include from pico/config.h for host platform, type=list, default="", group=pico_base +add_header_content_from_var(PICO_${PICO_PLATFORM_UPPER}_CONFIG_HEADER_FILES) + +file(GENERATE + OUTPUT ${CMAKE_BINARY_DIR}/generated/pico_base/pico/config_autogen.h + CONTENT "${header_content}" + ) + +configure_file( ${CMAKE_CURRENT_LIST_DIR}/include/pico/version.h.in ${CMAKE_BINARY_DIR}/generated/pico_base/pico/version.h) + +foreach(DIR IN LISTS PICO_INCLUDE_DIRS) + target_include_directories(pico_base_headers INTERFACE ${DIR}) +endforeach() \ No newline at end of file diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt index 13a73ad5a..9edcd7b09 100644 --- a/src/host/CMakeLists.txt +++ b/src/host/CMakeLists.txt @@ -32,4 +32,6 @@ endmacro() set(PICO_HOST_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "") function(pico_define_boot_stage2 NAME) add_executable(${NAME} ${PICO_HOST_DIR}/boot_stage2.c) -endfunction() \ No newline at end of file +endfunction() + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/rp2040/CMakeLists.txt b/src/rp2040/CMakeLists.txt index a6089de06..a19ea5ceb 100644 --- a/src/rp2040/CMakeLists.txt +++ b/src/rp2040/CMakeLists.txt @@ -4,3 +4,5 @@ pico_add_subdirectory(hardware_structs) pico_add_doxygen(${CMAKE_CURRENT_LIST_DIR}) pico_add_doxygen_exclude(${CMAKE_CURRENT_LIST_DIR}/hardware_regs) # very very big + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/rp2_common/CMakeLists.txt b/src/rp2_common/CMakeLists.txt index 8e485622e..24bcb42d0 100644 --- a/src/rp2_common/CMakeLists.txt +++ b/src/rp2_common/CMakeLists.txt @@ -71,3 +71,5 @@ endif() set(CMAKE_EXECUTABLE_SUFFIX "${CMAKE_EXECUTABLE_SUFFIX}" PARENT_SCOPE) pico_add_doxygen(${CMAKE_CURRENT_LIST_DIR}) + +pico_promote_common_scope_vars() \ No newline at end of file