Merge branch 'bugfix/even_more_cmake_fixes' into 'master'

Even more CMake fixes

See merge request idf/esp-idf!5097
This commit is contained in:
Angus Gratton 2019-06-12 08:08:04 +08:00
commit 065eb918fd
29 changed files with 240 additions and 230 deletions

View file

@ -74,35 +74,9 @@ foreach(component_target ${build_component_targets})
idf_build_get_property(build_prefix __PREFIX) idf_build_get_property(build_prefix __PREFIX)
set(__idf_component_context 1) set(__idf_component_context 1)
if(NOT prefix STREQUAL build_prefix) if(NOT prefix STREQUAL build_prefix)
add_subdirectory(${dir} ${prefix}_${_name} EXCLUDE_FROM_ALL) add_subdirectory(${dir} ${prefix}_${_name})
else() else()
add_subdirectory(${dir} ${_name} EXCLUDE_FROM_ALL) add_subdirectory(${dir} ${_name})
endif() endif()
set(__idf_component_context 0) set(__idf_component_context 0)
endforeach() endforeach()
# Establish dependencies between components
idf_build_get_property(build_components BUILD_COMPONENTS)
foreach(build_component ${build_components})
__component_get_target(component_target ${build_component})
__component_get_property(component_lib ${component_target} COMPONENT_LIB)
__component_get_property(reqs ${component_target} __REQUIRES)
foreach(req ${reqs})
__component_get_property(req_lib ${req} COMPONENT_LIB)
if(TARGET ${req_lib})
set_property(TARGET ${component_lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${req_lib})
endif()
endforeach()
get_property(type TARGET ${component_lib} PROPERTY TYPE)
if(type STREQUAL STATIC_LIBRARY)
__component_get_property(reqs ${component_target} __REQUIRES)
__component_get_property(priv_reqs ${component_target} __PRIV_REQUIRES)
foreach(req ${reqs} ${priv_reqs})
__component_get_property(req_lib ${req} COMPONENT_LIB)
if(TARGET ${req_lib})
set_property(TARGET ${component_lib} APPEND PROPERTY LINK_LIBRARIES ${req_lib})
endif()
endforeach()
endif()
endforeach()

View file

@ -31,4 +31,4 @@ register_component()
# disable --coverage for this component, as it is used as transport # disable --coverage for this component, as it is used as transport
# for gcov # for gcov
target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-profile-arcs" "-fno-test-coverage") target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-profile-arcs" "-fno-test-coverage")
target_link_libraries(${COMPONENT_LIB} gcov ${LIBC} ${LIBM} gcc) target_link_libraries(${COMPONENT_LIB} PUBLIC gcov ${LIBC} ${LIBM} gcc)

View file

@ -8,7 +8,7 @@ register_component()
# esp_app_desc structure is added as an undefined symbol because otherwise the # esp_app_desc structure is added as an undefined symbol because otherwise the
# linker will ignore this structure as it has no other files depending on it. # linker will ignore this structure as it has no other files depending on it.
target_link_libraries(${COMPONENT_LIB} "-u esp_app_desc") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_app_desc")
# cut PROJECT_VER and PROJECT_NAME to required 32 characters. # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
idf_build_get_property(project_ver PROJECT_VER) idf_build_get_property(project_ver PROJECT_VER)

View file

@ -7,4 +7,4 @@ idf_build_get_property(target IDF_TARGET)
set(scripts "${target}.bootloader.ld" set(scripts "${target}.bootloader.ld"
"${target}.bootloader.rom.ld") "${target}.bootloader.rom.ld")
target_linker_script(${COMPONENT_LIB} "${scripts}") target_linker_script(${COMPONENT_LIB} INTERFACE "${scripts}")

View file

@ -9,8 +9,8 @@ set(COMPONENT_SRCS "src/bootloader_clock.c"
if(BOOTLOADER_BUILD) if(BOOTLOADER_BUILD)
set(COMPONENT_ADD_INCLUDEDIRS "include include_bootloader") set(COMPONENT_ADD_INCLUDEDIRS "include include_bootloader")
set(COMPONENT_REQUIRES spi_flash soc) #unfortunately the header directly uses SOC registers set(COMPONENT_REQUIRES soc) #unfortunately the header directly uses SOC registers
set(COMPONENT_PRIV_REQUIRES micro-ecc efuse) set(COMPONENT_PRIV_REQUIRES micro-ecc spi_flash efuse)
list(APPEND COMPONENT_SRCS "src/bootloader_init.c" list(APPEND COMPONENT_SRCS "src/bootloader_init.c"
"src/${IDF_TARGET}/bootloader_sha.c" "src/${IDF_TARGET}/bootloader_sha.c"
"src/${IDF_TARGET}/flash_encrypt.c" "src/${IDF_TARGET}/flash_encrypt.c"
@ -55,8 +55,8 @@ else()
"src/idf/secure_boot_signatures.c") "src/idf/secure_boot_signatures.c")
set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "include_bootloader") set(COMPONENT_PRIV_INCLUDEDIRS "include_bootloader")
set(COMPONENT_REQUIRES mbedtls soc) #unfortunately the header directly uses SOC registers set(COMPONENT_REQUIRES soc) #unfortunately the header directly uses SOC registers
set(COMPONENT_PRIV_REQUIRES spi_flash efuse) set(COMPONENT_PRIV_REQUIRES spi_flash mbedtls efuse)
endif() endif()
register_component() register_component()

View file

@ -295,6 +295,6 @@ if(CONFIG_BT_ENABLED)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough -Wno-unused-const-variable) target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough -Wno-unused-const-variable)
endif() endif()
target_link_libraries(${COMPONENT_LIB} "-L${CMAKE_CURRENT_LIST_DIR}/lib") target_link_libraries(${COMPONENT_LIB} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/lib")
target_link_libraries(${COMPONENT_LIB} btdm_app) target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
endif() endif()

View file

@ -2,9 +2,9 @@ set(COMPONENT_SRCS "cxx_exception_stubs.cpp"
"cxx_guards.cpp") "cxx_guards.cpp")
register_component() register_component()
target_link_libraries(${COMPONENT_LIB} stdc++ gcc) target_link_libraries(${COMPONENT_LIB} PUBLIC stdc++ gcc)
target_link_libraries(${COMPONENT_LIB} "-u __cxa_guard_dummy") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxa_guard_dummy")
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS) if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)
target_link_libraries(${COMPONENT_LIB} "-u __cxx_fatal_exception") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_fatal_exception")
endif() endif()

View file

@ -4,7 +4,7 @@ if(BOOTLOADER_BUILD)
# For bootloader, all we need from esp32 is headers # For bootloader, all we need from esp32 is headers
set(COMPONENT_ADD_INCLUDEDIRS include) set(COMPONENT_ADD_INCLUDEDIRS include)
register_component() register_component()
target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
else() else()
# Regular app build # Regular app build
@ -34,40 +34,41 @@ else()
"task_wdt.c") "task_wdt.c")
set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_REQUIRES app_update driver esp_event efuse pthread soc) #unfortunately rom/uart uses SOC registers directly set(COMPONENT_REQUIRES driver esp_event efuse soc) #unfortunately rom/uart uses SOC registers directly
# driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t # driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
# app_update is added here because cpu_start.c uses esp_ota_get_app_description() function. # app_update is added here because cpu_start.c uses esp_ota_get_app_description() function.
set(COMPONENT_PRIV_REQUIRES set(COMPONENT_PRIV_REQUIRES
app_trace app_update bootloader_support log mbedtls nvs_flash app_trace app_update bootloader_support log mbedtls nvs_flash pthread
smartconfig_ack spi_flash vfs wpa_supplicant espcoredump esp_common esp_wifi) smartconfig_ack spi_flash vfs wpa_supplicant espcoredump esp_common esp_wifi)
set(COMPONENT_ADD_LDFRAGMENTS linker.lf ld/esp32_fragments.lf) set(COMPONENT_ADD_LDFRAGMENTS linker.lf ld/esp32_fragments.lf)
register_component() register_component()
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
# Rely on user code to define app_main # Rely on user code to define app_main
target_link_libraries(${COMPONENT_LIB} "-u app_main") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY) if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY)
# This has to be linked before esp32.project.ld # This has to be linked before esp32.project.ld
target_linker_script(${COMPONENT_LIB} "ld/esp32.extram.bss.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld")
endif() endif()
# Process the template file through the linker script generation mechanism, and use the output for linking the # Process the template file through the linker script generation mechanism, and use the output for linking the
# final binary # final binary
target_linker_script(${COMPONENT_LIB} "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" PROCESS) target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"
PROCESS "${CMAKE_CURRENT_BINARY_DIR}/ld/esp32.project.ld")
target_linker_script(${COMPONENT_LIB} "ld/esp32.peripherals.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.peripherals.ld")
target_link_libraries(${COMPONENT_LIB} gcc) target_link_libraries(${COMPONENT_LIB} PUBLIC gcc)
target_link_libraries(${COMPONENT_LIB} "-u call_user_start_cpu0") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u call_user_start_cpu0")
#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the #ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
#linker will ignore panic_highint_hdl.S as it has no other files depending on any #linker will ignore panic_highint_hdl.S as it has no other files depending on any
#symbols in it. #symbols in it.
target_link_libraries(${COMPONENT_LIB} "-u ld_include_panic_highint_hdl") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_panic_highint_hdl")
idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER) idf_build_get_property(sdkconfig_header SDKCONFIG_HEADER)
get_filename_component(config_dir ${sdkconfig_header} DIRECTORY) get_filename_component(config_dir ${sdkconfig_header} DIRECTORY)
@ -95,6 +96,6 @@ else()
# To handle some corner cases, the same flag is set in project_include.cmake # To handle some corner cases, the same flag is set in project_include.cmake
target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue) target_compile_options(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
# also, make sure we link with this option so correct toolchain libs are pulled in # also, make sure we link with this option so correct toolchain libs are pulled in
target_link_libraries(${COMPONENT_LIB} -mfix-esp32-psram-cache-issue) target_link_libraries(${COMPONENT_LIB} PUBLIC -mfix-esp32-psram-cache-issue)
endif() endif()
endif() endif()

View file

@ -9,7 +9,7 @@ if(BOOTLOADER_BUILD)
"esp32/ld/esp32.rom.newlib-funcs.ld" "esp32/ld/esp32.rom.newlib-funcs.ld"
"esp32/ld/esp32.rom.libgcc.ld" "esp32/ld/esp32.rom.libgcc.ld"
) )
target_linker_script(${COMPONENT_LIB} "${scripts}") target_linker_script(${COMPONENT_LIB} INTERFACE "${scripts}")
else() else()
# Regular app build # Regular app build
set(COMPONENT_SRCS "esp_rom.c") set(COMPONENT_SRCS "esp_rom.c")
@ -23,21 +23,21 @@ else()
"esp32/ld/esp32.rom.syscalls.ld" "esp32/ld/esp32.rom.syscalls.ld"
"esp32/ld/esp32.rom.newlib-data.ld" "esp32/ld/esp32.rom.newlib-data.ld"
) )
target_linker_script(${COMPONENT_LIB} "${scripts}") target_linker_script(${COMPONENT_LIB} INTERFACE "${scripts}")
if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND) if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
target_linker_script(${COMPONENT_LIB} "esp32/ld/esp32.rom.newlib-funcs.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.newlib-funcs.ld")
endif() endif()
if(CONFIG_NEWLIB_NANO_FORMAT) if(CONFIG_NEWLIB_NANO_FORMAT)
target_linker_script(${COMPONENT_LIB} "esp32/ld/esp32.rom.newlib-nano.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.newlib-nano.ld")
endif() endif()
if(NOT GCC_NOT_5_2_0) if(NOT GCC_NOT_5_2_0)
target_linker_script(${COMPONENT_LIB} "esp32/ld/esp32.rom.newlib-locale.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.newlib-locale.ld")
endif() endif()
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH) if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
target_linker_script(${COMPONENT_LIB} "esp32/ld/esp32.rom.spiflash.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.spiflash.ld")
endif() endif()
endif() endif()

View file

@ -8,22 +8,21 @@ set(COMPONENT_SRCS
"src/wifi_init.c") "src/wifi_init.c")
set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS) set(COMPONENT_PRIV_INCLUDEDIRS)
set(COMPONENT_REQUIRES wpa_supplicant smartconfig_ack) set(COMPONENT_PRIV_REQUIRES wpa_supplicant nvs_flash)
set(COMPONENT_PRIV_REQUIRES "nvs_flash")
if(NOT CONFIG_ESP32_NO_BLOBS) if(NOT CONFIG_ESP32_NO_BLOBS)
set(COMPONENT_ADD_LDFRAGMENTS "linker.lf") set(COMPONENT_ADD_LDFRAGMENTS "linker.lf")
endif() endif()
register_component() register_component()
target_link_libraries(${COMPONENT_LIB} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib_${IDF_TARGET}") target_link_libraries(${COMPONENT_LIB} PUBLIC "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib_${IDF_TARGET}")
if(NOT CONFIG_ESP32_NO_BLOBS) if(NOT CONFIG_ESP32_NO_BLOBS)
set(blobs coexist core espnow mesh net80211 phy pp rtc smartconfig wpa2 wpa wps) set(blobs coexist core espnow mesh net80211 phy pp rtc smartconfig wpa2 wpa wps)
foreach(blob ${blobs}) foreach(blob ${blobs})
add_library(${blob} STATIC IMPORTED) add_library(${blob} STATIC IMPORTED)
set_property(TARGET ${blob} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib_${IDF_TARGET}/lib${blob}.a) set_property(TARGET ${blob} PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib_${IDF_TARGET}/lib${blob}.a)
target_link_libraries(${COMPONENT_LIB} ${blob}) target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob})
foreach(_blob ${blobs}) foreach(_blob ${blobs})
if(NOT _blob STREQUAL ${blob}) if(NOT _blob STREQUAL ${blob})

View file

@ -25,7 +25,7 @@ set(COMPONENT_ADD_LDFRAGMENTS linker.lf)
register_component() register_component()
target_link_libraries(${COMPONENT_LIB} "-Wl,--undefined=uxTopUsedPriority") target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=uxTopUsedPriority")
set_source_files_properties( set_source_files_properties(
tasks.c tasks.c

View file

@ -32,7 +32,7 @@ if(CONFIG_HEAP_TRACING)
heap_caps_realloc_default) heap_caps_realloc_default)
foreach(wrap ${WRAP_FUNCTIONS}) foreach(wrap ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} "-Wl,--wrap=${wrap}") target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
endforeach() endforeach()
endif() endif()

View file

@ -126,7 +126,7 @@ endif()
set(COMPONENT_ADD_INCLUDEDIRS ${SRC}/include port_include) set(COMPONENT_ADD_INCLUDEDIRS ${SRC}/include port_include)
set(COMPONENT_PRIV_INCLUDEDIRS ${SRC}/include/sodium port_include/sodium port) set(COMPONENT_PRIV_INCLUDEDIRS ${SRC}/include/sodium port_include/sodium port)
set(COMPONENT_REQUIRES mbedtls vfs) set(COMPONENT_REQUIRES mbedtls)
register_component() register_component()
target_compile_definitions(${COMPONENT_LIB} PRIVATE target_compile_definitions(${COMPONENT_LIB} PRIVATE

View file

@ -2,8 +2,6 @@ set(COMPONENT_ADD_INCLUDEDIRS "port/include" "mbedtls/include")
set(COMPONENT_SRCS "mbedtls.c") set(COMPONENT_SRCS "mbedtls.c")
set(COMPONENT_REQUIRES lwip) set(COMPONENT_REQUIRES lwip)
set(MBEDTLS_PRIV_REQUIRES ${IDF_COMPONENT_REQUIRES_COMMON} soc)
register_component() register_component()
# Only build mbedtls libraries # Only build mbedtls libraries
@ -96,9 +94,4 @@ foreach(target ${mbedtls_targets})
endforeach() endforeach()
# Link mbedtls libraries to component library # Link mbedtls libraries to component library
target_link_libraries(${COMPONENT_LIB} ${mbedtls_targets}) target_link_libraries(${COMPONENT_LIB} INTERFACE ${mbedtls_targets})
# Catch usage of deprecated mbedTLS functions when building tests
if(mbedtls_test IN_LIST BUILD_TEST_COMPONENTS)
add_definitions(-DMBEDTLS_DEPRECATED_WARNING)
endif()

View file

@ -4,3 +4,9 @@ set(COMPONENT_ADD_INCLUDEDIRS ".")
set(COMPONENT_REQUIRES unity test_utils mbedtls) set(COMPONENT_REQUIRES unity test_utils mbedtls)
register_component() register_component()
idf_component_get_property(mbedtls mbedtls COMPONENT_LIB)
target_compile_definitions(${mbedtls} PUBLIC "-DMBEDTLS_DEPRECATED_WARNING")
target_compile_definitions(mbedtls PUBLIC "-DMBEDTLS_DEPRECATED_WARNING")
target_compile_definitions(mbedcrypto PUBLIC "-DMBEDTLS_DEPRECATED_WARNING")
target_compile_definitions(mbedx509 PUBLIC "-DMBEDTLS_DEPRECATED_WARNING")

View file

@ -42,8 +42,8 @@ list(APPEND COMPONENT_ADD_LDFRAGMENTS newlib.lf)
register_component() register_component()
if (LIB_PATH) if(LIB_PATH)
target_link_libraries(${COMPONENT_LIB} "-L ${LIB_PATH}") target_link_libraries(${COMPONENT_LIB} INTERFACE "-L ${LIB_PATH}")
endif() endif()
if(GCC_NOT_5_2_0) if(GCC_NOT_5_2_0)
@ -51,13 +51,13 @@ if(GCC_NOT_5_2_0)
add_library(extra INTERFACE) add_library(extra INTERFACE)
idf_component_get_property(newlib newlib COMPONENT_LIB) idf_component_get_property(newlib newlib COMPONENT_LIB)
target_link_libraries(extra INTERFACE ${LIBC} ${LIBM} gcc "$<TARGET_FILE:${newlib}>") target_link_libraries(extra INTERFACE ${LIBC} ${LIBM} gcc "$<TARGET_FILE:${newlib}>")
target_link_libraries(${COMPONENT_LIB} extra) target_link_libraries(${COMPONENT_LIB} PUBLIC extra)
else() else()
target_link_libraries(${COMPONENT_LIB} ${LIBC} ${LIBM} gcc) target_link_libraries(${COMPONENT_LIB} PUBLIC ${LIBC} ${LIBM} gcc)
endif() endif()
set_source_files_properties(heap.c PROPERTIES COMPILE_FLAGS -fno-builtin) set_source_files_properties(heap.c PROPERTIES COMPILE_FLAGS -fno-builtin)
if(EXTRA_LINK_FLAGS) if(EXTRA_LINK_FLAGS)
target_link_libraries(${COMPONENT_LIB} "${EXTRA_LINK_FLAGS}") target_link_libraries(${COMPONENT_LIB} INTERFACE "${EXTRA_LINK_FLAGS}")
endif() endif()

View file

@ -12,8 +12,7 @@ set(COMPONENT_SRCS "src/common/protocomm.c"
"src/transports/protocomm_console.c" "src/transports/protocomm_console.c"
"src/transports/protocomm_httpd.c") "src/transports/protocomm_httpd.c")
set(COMPONENT_REQUIRES protobuf-c bt) set(COMPONENT_PRIV_REQUIRES protobuf-c mbedtls console esp_http_server bt)
set(COMPONENT_PRIV_REQUIRES mbedtls console esp_http_server)
if(CONFIG_BT_ENABLED) if(CONFIG_BT_ENABLED)
if(CONFIG_BT_BLUEDROID_ENABLED) if(CONFIG_BT_BLUEDROID_ENABLED)

View file

@ -9,8 +9,7 @@ else()
"flash_ops.c" "flash_ops.c"
"partition.c" "partition.c"
"spi_flash_rom_patch.c") "spi_flash_rom_patch.c")
set(COMPONENT_REQUIRES app_update) set(COMPONENT_PRIV_REQUIRES bootloader_support app_update soc)
set(COMPONENT_PRIV_REQUIRES bootloader_support soc)
endif() endif()
set(COMPONENT_ADD_INCLUDEDIRS include) set(COMPONENT_ADD_INCLUDEDIRS include)

View file

@ -61,7 +61,7 @@ function(ulp_embed_binary app_name s_sources exp_dep_srcs)
add_dependencies(${COMPONENT_LIB} ${app_name}_artifacts) add_dependencies(${COMPONENT_LIB} ${app_name}_artifacts)
target_linker_script(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.ld) target_linker_script(${COMPONENT_LIB} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.ld)
target_add_binary_data(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.bin BINARY) target_add_binary_data(${COMPONENT_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.bin BINARY)
endif() endif()
endfunction() endfunction()

View file

@ -6,4 +6,4 @@ register_component()
# Some newlib syscalls are implemented in vfs.c, make sure these are always # Some newlib syscalls are implemented in vfs.c, make sure these are always
# seen by the linker # seen by the linker
target_link_libraries(${COMPONENT_LIB} "-u vfs_include_syscalls_impl") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u vfs_include_syscalls_impl")

View file

@ -7,4 +7,4 @@ set(COMPONENT_PRIV_REQUIRES soc)
register_component() register_component()
target_link_libraries(${COMPONENT_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/${IDF_TARGET}/libhal.a") target_link_libraries(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${IDF_TARGET}/libhal.a")

View file

@ -23,4 +23,4 @@ endfunction()
add_subdirectory(lib/tinyxml2) add_subdirectory(lib/tinyxml2)
# Link tinyxml2 to main component # Link tinyxml2 to main component
target_link_libraries(${COMPONENT_LIB} tinyxml2) target_link_libraries(${COMPONENT_LIB} PUBLIC tinyxml2)

View file

@ -195,7 +195,8 @@ function(__build_expand_requirements component_target)
# Since there are circular dependencies, make sure that we do not infinitely # Since there are circular dependencies, make sure that we do not infinitely
# expand requirements for each component. # expand requirements for each component.
idf_build_get_property(component_targets_seen __COMPONENT_TARGETS_SEEN) idf_build_get_property(component_targets_seen __COMPONENT_TARGETS_SEEN)
if(component_target IN_LIST component_targets_seen) __component_get_property(component_registered ${component_target} __COMPONENT_REGISTERED)
if(component_target IN_LIST component_targets_seen OR NOT component_registered)
return() return()
endif() endif()
@ -365,56 +366,13 @@ macro(idf_build_process target)
# Check for required Python modules # Check for required Python modules
__build_check_python() __build_check_python()
# Generate config values in different formats idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${target} APPEND)
idf_build_get_property(sdkconfig SDKCONFIG) __component_get_requirements()
idf_build_get_property(sdkconfig_defaults SDKCONFIG_DEFAULTS)
__kconfig_generate_config("${sdkconfig}" "${sdkconfig_defaults}")
__build_import_configs()
# Write the partial build properties to a temporary file.
# The path to this generated file is set to a short-lived build
# property BUILD_PROPERTIES_FILE.
idf_build_get_property(build_dir BUILD_DIR)
set(build_properties_file ${build_dir}/build_properties.temp.cmake)
idf_build_set_property(BUILD_PROPERTIES_FILE ${build_properties_file})
__build_write_properties(${build_properties_file})
# Perform early expansion of component CMakeLists.txt in CMake scripting mode. # Perform early expansion of component CMakeLists.txt in CMake scripting mode.
# It is here we retrieve the public and private requirements of each component. # It is here we retrieve the public and private requirements of each component.
# It is also here we add the common component requirements to each component's # It is also here we add the common component requirements to each component's
# own requirements. # own requirements.
idf_build_get_property(component_targets __COMPONENT_TARGETS)
idf_build_set_property(__COMPONENT_REQUIRES_COMMON ${target} APPEND)
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
foreach(component_target ${component_targets})
get_property(component_dir TARGET ${component_target} PROPERTY COMPONENT_DIR)
__component_get_requirements(error reqs priv_reqs ${component_dir})
if(error)
message(FATAL_ERROR "${error}")
endif()
list(APPEND reqs "${common_reqs}")
# Remove duplicates and the component itself from its requirements
__component_get_property(alias ${component_target} COMPONENT_ALIAS)
__component_get_property(_name ${component_target} COMPONENT_NAME)
# Prevent component from linking to itself.
if(reqs)
list(REMOVE_DUPLICATES reqs)
list(REMOVE_ITEM reqs ${alias} ${_name})
endif()
if(priv_reqs)
list(REMOVE_DUPLICATES priv_reqs)
list(REMOVE_ITEM priv_reqs ${alias} ${_name})
endif()
__component_set_property(${component_target} REQUIRES "${reqs}")
__component_set_property(${component_target} PRIV_REQUIRES "${priv_reqs}")
endforeach()
idf_build_unset_property(BUILD_PROPERTIES_FILE)
file(REMOVE ${build_properties_file})
# Finally, do component expansion. In this case it simply means getting a final list # Finally, do component expansion. In this case it simply means getting a final list
# of build component targets given the requirements set by each component. # of build component targets given the requirements set by each component.
@ -436,12 +394,19 @@ macro(idf_build_process target)
# Get a list of common component requirements in component targets form (previously # Get a list of common component requirements in component targets form (previously
# we just have a list of component names) # we just have a list of component names)
idf_build_get_property(common_reqs __COMPONENT_REQUIRES_COMMON)
foreach(common_req ${common_reqs}) foreach(common_req ${common_reqs})
__component_get_target(component_target ${common_req}) __component_get_target(component_target ${common_req})
__component_get_property(lib ${component_target} COMPONENT_LIB) __component_get_property(lib ${component_target} COMPONENT_LIB)
idf_build_set_property(___COMPONENT_REQUIRES_COMMON ${lib} APPEND) idf_build_set_property(___COMPONENT_REQUIRES_COMMON ${lib} APPEND)
endforeach() endforeach()
# Generate config values in different formats
idf_build_get_property(sdkconfig SDKCONFIG)
idf_build_get_property(sdkconfig_defaults SDKCONFIG_DEFAULTS)
__kconfig_generate_config("${sdkconfig}" "${sdkconfig_defaults}")
__build_import_configs()
# Temporary trick to support both gcc5 and gcc8 builds # Temporary trick to support both gcc5 and gcc8 builds
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.2.0) if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 5.2.0)
set(GCC_NOT_5_2_0 0 CACHE STRING "GCC is 5.2.0 version") set(GCC_NOT_5_2_0 0 CACHE STRING "GCC is 5.2.0 version")
@ -471,29 +436,8 @@ endmacro()
# generating additional binary files, generating files related to flashing, etc.) # generating additional binary files, generating files related to flashing, etc.)
function(idf_build_executable elf) function(idf_build_executable elf)
# Propagate link dependencies from component library targets to the executable # Propagate link dependencies from component library targets to the executable
idf_build_get_property(build_components BUILD_COMPONENTS) idf_build_get_property(link_depends __LINK_DEPENDS)
foreach(build_component ${build_components}) set_property(TARGET ${elf} APPEND PROPERTY LINK_DEPENDS "${link_depends}")
get_target_property(type ${build_component} TYPE)
if(type STREQUAL "INTERFACE_LIBRARY")
get_target_property(iface_link_depends ${build_component} INTERFACE_LINK_DEPENDS)
else()
get_target_property(link_depends ${build_component} LINK_DEPENDS)
get_target_property(iface_link_depends ${build_component} INTERFACE_LINK_DEPENDS)
endif()
if(iface_link_depends)
list(APPEND _link_depends ${iface_link_depends})
endif()
if(link_depends)
list(APPEND _link_depends ${link_depends})
endif()
endforeach()
idf_build_get_property(link_depends LINK_DEPENDS)
if(link_depends)
list(APPEND _link_depends ${link_depends})
endif()
set_property(TARGET ${elf} APPEND PROPERTY LINK_DEPENDS "${_link_depends}")
# Set the EXECUTABLE_NAME and EXECUTABLE properties since there are generator expression # Set the EXECUTABLE_NAME and EXECUTABLE properties since there are generator expression
# from components that depend on it # from components that depend on it

View file

@ -125,6 +125,23 @@ function(__component_dir_quick_check var component_dir)
set(${var} ${res} PARENT_SCOPE) set(${var} ${res} PARENT_SCOPE)
endfunction() endfunction()
#
# Write a CMake file containing all component and their properties. This is possible because each component
# keeps a list of all its properties.
#
function(__component_write_properties output_file)
idf_build_get_property(component_targets __COMPONENT_TARGETS)
foreach(component_target ${component_targets})
__component_get_property(component_properties ${component_target} __COMPONENT_PROPERTIES)
foreach(property ${component_properties})
__component_get_property(val ${component_target} ${property})
set(component_properties_text
"${component_properties_text}\nset(__component_${component_target}_${property} ${val})")
endforeach()
file(WRITE ${output_file} "${component_properties_text}")
endforeach()
endfunction()
# #
# Add a component to process in the build. The components are keeped tracked of in property # Add a component to process in the build. The components are keeped tracked of in property
# __COMPONENT_TARGETS in component target form. # __COMPONENT_TARGETS in component target form.
@ -184,44 +201,35 @@ endfunction()
# Given a component directory, get the requirements by expanding it early. The expansion is performed # Given a component directory, get the requirements by expanding it early. The expansion is performed
# using a separate CMake script (the expansion is performed in a separate instance of CMake in scripting mode). # using a separate CMake script (the expansion is performed in a separate instance of CMake in scripting mode).
# #
function(__component_get_requirements error requires_var priv_requires_var component_dir) function(__component_get_requirements)
idf_build_get_property(idf_path IDF_PATH) idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(build_properties_file BUILD_PROPERTIES_FILE)
idf_build_get_property(idf_target IDF_TARGET)
# This function assumes that the directory has been checked to contain a component, thus idf_build_get_property(build_dir BUILD_DIR)
# no check is performed here. set(build_properties_file ${build_dir}/build_properties.temp.cmake)
set(component_properties_file ${build_dir}/component_properties.temp.cmake)
set(component_requires_file ${build_dir}/component_requires.temp.cmake)
__build_write_properties(${build_properties_file})
__component_write_properties(${component_properties_file})
execute_process(COMMAND "${CMAKE_COMMAND}" execute_process(COMMAND "${CMAKE_COMMAND}"
-D "IDF_PATH=${idf_path}"
-D "IDF_TARGET=${idf_target}"
-D "COMPONENT_DIR=${component_dir}"
-D "BUILD_PROPERTIES_FILE=${build_properties_file}" -D "BUILD_PROPERTIES_FILE=${build_properties_file}"
-D "CMAKE_BUILD_EARLY_EXPANSION=1" -D "COMPONENT_PROPERTIES_FILE=${component_properties_file}"
-D "COMPONENT_REQUIRES_FILE=${component_requires_file}"
-P "${idf_path}/tools/cmake/scripts/component_get_requirements.cmake" -P "${idf_path}/tools/cmake/scripts/component_get_requirements.cmake"
RESULT_VARIABLE result RESULT_VARIABLE result
ERROR_VARIABLE error ERROR_VARIABLE error
) )
if(NOT result EQUAL 0) if(NOT result EQUAL 0)
set(error "${error}" PARENT_SCOPE) message(FATAL_ERROR "${error}")
return()
endif() endif()
string(REGEX REPLACE ";" "\\\\;" _output "${error}") include(${component_requires_file})
string(REGEX REPLACE "\n" ";" _output "${_output}")
list(REVERSE _output)
if(_output) file(REMOVE ${build_properties_file})
list(GET _output 1 _output) file(REMOVE ${component_properties_file})
file(REMOVE ${component_requires_file})
string(REGEX MATCH "\(.*\):::\(.*\)" _output "${_output}")
string(REPLACE ":" ";" requires "${CMAKE_MATCH_1}")
string(REPLACE ":" ";" priv_requires "${CMAKE_MATCH_2}")
endif()
set(${requires_var} ${requires} PARENT_SCOPE)
set(${priv_requires_var} ${priv_requires} PARENT_SCOPE)
endfunction() endfunction()
# __component_add_sources, __component_check_target # __component_add_sources, __component_check_target
@ -280,6 +288,39 @@ macro(__component_check_target)
endif() endif()
endmacro() endmacro()
# __component_set_dependencies, __component_set_all_dependencies
#
# Links public and private requirements for the currently processed component
macro(__component_set_dependencies reqs type)
foreach(req ${reqs})
if(req IN_LIST build_component_targets)
__component_get_property(req_lib ${req} COMPONENT_LIB)
target_link_libraries(${component_lib} ${type} ${req_lib})
endif()
endforeach()
endmacro()
macro(__component_set_all_dependencies)
__component_get_property(type ${component_target} COMPONENT_TYPE)
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
if(NOT type STREQUAL CONFIG_ONLY)
__component_get_property(reqs ${component_target} __REQUIRES)
__component_set_dependencies("${reqs}" PUBLIC)
__component_get_property(priv_reqs ${component_target} __PRIV_REQUIRES)
__component_set_dependencies("${priv_reqs}" PRIVATE)
else()
__component_get_property(reqs ${component_target} __REQUIRES)
foreach(req ${reqs})
if(req IN_LIST build_component_targets)
__component_get_property(req_lib ${req} COMPONENT_LIB)
target_link_libraries(${component_lib} INTERFACE ${req_lib})
endif()
endforeach()
endif()
endmacro()
# idf_component_get_property # idf_component_get_property
# #
# @brief Retrieve the value of the specified component property # @brief Retrieve the value of the specified component property
@ -323,6 +364,7 @@ function(idf_component_set_property component property val)
endif() endif()
endfunction() endfunction()
# idf_component_register # idf_component_register
# #
# @brief Register a component to the build, creating component library targets etc. # @brief Register a component to the build, creating component library targets etc.
@ -423,6 +465,9 @@ function(idf_component_register)
__ldgen_add_fragment_files("${__LDFRAGMENTS}") __ldgen_add_fragment_files("${__LDFRAGMENTS}")
endif() endif()
# Set dependencies
__component_set_all_dependencies()
# Add the component to built components # Add the component to built components
idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND) idf_build_set_property(__BUILD_COMPONENTS ${component_lib} APPEND)
idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND) idf_build_set_property(BUILD_COMPONENTS ${component_alias} APPEND)

View file

@ -88,14 +88,17 @@ endfunction()
function(__kconfig_generate_config sdkconfig sdkconfig_defaults) function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
# List all Kconfig and Kconfig.projbuild in known components # List all Kconfig and Kconfig.projbuild in known components
idf_build_get_property(component_targets __COMPONENT_TARGETS) idf_build_get_property(component_targets __COMPONENT_TARGETS)
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
foreach(component_target ${component_targets}) foreach(component_target ${component_targets})
__component_get_property(kconfig ${component_target} KCONFIG) if(component_target IN_LIST build_component_targets)
__component_get_property(kconfig_projbuild ${component_target} KCONFIG_PROJBUILD) __component_get_property(kconfig ${component_target} KCONFIG)
if(kconfig) __component_get_property(kconfig_projbuild ${component_target} KCONFIG_PROJBUILD)
list(APPEND kconfigs ${kconfig}) if(kconfig)
endif() list(APPEND kconfigs ${kconfig})
if(kconfig_projbuild) endif()
list(APPEND kconfig_projbuilds ${kconfig_projbuild}) if(kconfig_projbuild)
list(APPEND kconfig_projbuilds ${kconfig_projbuild})
endif()
endif() endif()
endforeach() endforeach()

View file

@ -27,7 +27,7 @@ endfunction()
# #
# Passes a linker script template to the linker script generation tool for # Passes a linker script template to the linker script generation tool for
# processing # processing
function(__ldgen_process_template output_var template) function(__ldgen_process_template template output)
idf_build_get_property(idf_target IDF_TARGET) idf_build_get_property(idf_target IDF_TARGET)
idf_build_get_property(idf_path IDF_PATH) idf_build_get_property(idf_path IDF_PATH)
@ -36,11 +36,6 @@ function(__ldgen_process_template output_var template)
file(GENERATE OUTPUT ${build_dir}/ldgen_libraries.in CONTENT $<JOIN:${ldgen_libraries},\n>) file(GENERATE OUTPUT ${build_dir}/ldgen_libraries.in CONTENT $<JOIN:${ldgen_libraries},\n>)
file(GENERATE OUTPUT ${build_dir}/ldgen_libraries INPUT ${build_dir}/ldgen_libraries.in) file(GENERATE OUTPUT ${build_dir}/ldgen_libraries INPUT ${build_dir}/ldgen_libraries.in)
get_filename_component(filename "${template}" NAME)
set(output ${CMAKE_CURRENT_BINARY_DIR}/${filename}.ld)
set(${output_var} ${output} PARENT_SCOPE)
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${build_dir}/ldgen_libraries.in" "${build_dir}/ldgen_libraries.in"
@ -80,5 +75,5 @@ function(__ldgen_process_template output_var template)
get_filename_component(_name ${output} NAME) get_filename_component(_name ${output} NAME)
add_custom_target(__ldgen_output_${_name} DEPENDS ${output}) add_custom_target(__ldgen_output_${_name} DEPENDS ${output})
add_dependencies(__idf_build_target __ldgen_output_${_name}) add_dependencies(__idf_build_target __ldgen_output_${_name})
idf_build_set_property(LINK_DEPENDS ${output} APPEND) idf_build_set_property(__LINK_DEPENDS ${output} APPEND)
endfunction() endfunction()

View file

@ -1,10 +1,5 @@
include(${IDF_PATH}/tools/cmake/utilities.cmake)
include("${BUILD_PROPERTIES_FILE}") include("${BUILD_PROPERTIES_FILE}")
include("${SDKCONFIG_CMAKE}") include("${COMPONENT_PROPERTIES_FILE}")
macro(require_idf_targets)
endmacro()
function(idf_build_get_property var property) function(idf_build_get_property var property)
cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN}) cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
@ -12,17 +7,20 @@ function(idf_build_get_property var property)
message(FATAL_ERROR "Getting build property generator expression not message(FATAL_ERROR "Getting build property generator expression not
supported before idf_component_register().") supported before idf_component_register().")
endif() endif()
set(${var} ${property} PARENT_SCOPE) set(${var} ${${property}} PARENT_SCOPE)
endfunction() endfunction()
function(print_requires requires priv_requires) idf_build_get_property(idf_path IDF_PATH)
spaces2list(requires) include(${idf_path}/tools/cmake/utilities.cmake)
spaces2list(priv_requires)
string(REPLACE ";" ":" requires "${requires}") function(__component_get_property var component_target property)
string(REPLACE ";" ":" priv_requires "${priv_requires}") set(_property __component_${component_target}_${property})
message("${requires}:::${priv_requires}") set(${var} ${${_property}} PARENT_SCOPE)
endfunction() endfunction()
macro(require_idf_targets)
endmacro()
macro(idf_component_register) macro(idf_component_register)
set(options) set(options)
set(single_value) set(single_value)
@ -30,14 +28,16 @@ macro(idf_component_register)
INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES INCLUDE_DIRS PRIV_INCLUDE_DIRS LDFRAGMENTS REQUIRES
PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES) PRIV_REQUIRES REQUIRED_IDF_TARGETS EMBED_FILES EMBED_TXTFILES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" "${ARGN}") cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" "${ARGN}")
print_requires("${__REQUIRES}" "${__PRIV_REQUIRES}") set(__component_requires "${__REQUIRES}")
set(__is_component 1) set(__component_priv_requires "${__PRIV_REQUIRES}")
set(__component_registered 1)
return() return()
endmacro() endmacro()
macro(register_component) macro(register_component)
print_requires("${COMPONENT_REQUIRES}" "${COMPONENT_PRIV_REQUIRES}") set(__component_requires "${COMPONENT_REQUIRES}")
set(__is_component 1) set(__component_priv_requires "${COMPONENT_PRIV_REQUIRES}")
set(__component_registered 1)
return() return()
endmacro() endmacro()
@ -45,5 +45,55 @@ macro(register_config_only_component)
register_component() register_component()
endmacro() endmacro()
set(CMAKE_BUILD_EARLY_EXPANSION) idf_build_get_property(__common_reqs __COMPONENT_REQUIRES_COMMON)
include(${COMPONENT_DIR}/CMakeLists.txt OPTIONAL) idf_build_get_property(__component_targets __COMPONENT_TARGETS)
function(__component_get_requirements)
# This is in a function (separate variable context) so that variables declared
# and set by the included CMakeLists.txt does not bleed into the next inclusion.
# We are only interested in the public and private requirements of components
__component_get_property(__component_dir ${__component_target} COMPONENT_DIR)
include(${__component_dir}/CMakeLists.txt OPTIONAL)
spaces2list(__component_requires)
spaces2list(__component_priv_requires)
set(__component_requires "${__component_requires}" PARENT_SCOPE)
set(__component_priv_requires "${__component_priv_requires}" PARENT_SCOPE)
set(__component_registered ${__component_registered} PARENT_SCOPE)
endfunction()
set(CMAKE_BUILD_EARLY_EXPANSION 1)
foreach(__component_target ${__component_targets})
set(__component_requires "")
set(__component_priv_requires "")
set(__component_registered 0)
__component_get_requirements()
list(APPEND __component_requires "${__common_reqs}")
# Remove duplicates and the component itself from its requirements
__component_get_property(__component_alias ${__component_target} COMPONENT_ALIAS)
__component_get_property(__component_name ${__component_target} COMPONENT_NAME)
# Prevent component from linking to itself.
if(__component_requires)
list(REMOVE_DUPLICATES __component_requires)
list(REMOVE_ITEM __component_requires ${__component_alias} ${__component_name})
endif()
if(__component_requires)
list(REMOVE_DUPLICATES __component_priv_requires)
list(REMOVE_ITEM __component_priv_requires ${__component_alias} ${__component_name})
endif()
set(__contents
"__component_set_property(${__component_target} REQUIRES \"${__component_requires}\")
__component_set_property(${__component_target} PRIV_REQUIRES \"${__component_priv_requires}\")
__component_set_property(${__component_target} __COMPONENT_REGISTERED ${__component_registered})"
)
set(__component_requires_contents "${__component_requires_contents}\n${__contents}")
endforeach()
file(WRITE ${COMPONENT_REQUIRES_FILE} "${__component_requires_contents}")

View file

@ -130,26 +130,22 @@ endfunction()
# Automatically adds a -L search path for the containing directory (if found), # Automatically adds a -L search path for the containing directory (if found),
# and then adds -T with the filename only. This allows INCLUDE directives to be # and then adds -T with the filename only. This allows INCLUDE directives to be
# used to include other linker scripts in the same directory. # used to include other linker scripts in the same directory.
function(target_linker_script target scriptfiles) function(target_linker_script target deptype scriptfiles)
cmake_parse_arguments(_ "PROCESS" "" "" ${ARGN}) cmake_parse_arguments(_ "" "PROCESS" "" ${ARGN})
foreach(scriptfile ${scriptfiles}) foreach(scriptfile ${scriptfiles})
get_filename_component(abs_script "${scriptfile}" ABSOLUTE) get_filename_component(abs_script "${scriptfile}" ABSOLUTE)
message(STATUS "Adding linker script ${abs_script}") message(STATUS "Adding linker script ${abs_script}")
if(__PROCESS) if(__PROCESS)
__ldgen_process_template(output ${abs_script}) get_filename_component(output "${__PROCESS}" ABSOLUTE)
__ldgen_process_template(${abs_script} ${output})
set(abs_script ${output}) set(abs_script ${output})
endif() endif()
get_filename_component(search_dir "${abs_script}" DIRECTORY) get_filename_component(search_dir "${abs_script}" DIRECTORY)
get_filename_component(scriptname "${abs_script}" NAME) get_filename_component(scriptname "${abs_script}" NAME)
get_target_property(type ${target} TYPE) if(deptype STREQUAL INTERFACE OR deptype STREQUAL PUBLIC)
if(type STREQUAL "INTERFACE_LIBRARY")
set(is_interface "INTERFACE")
endif()
if(is_interface)
get_target_property(link_libraries "${target}" INTERFACE_LINK_LIBRARIES) get_target_property(link_libraries "${target}" INTERFACE_LINK_LIBRARIES)
else() else()
get_target_property(link_libraries "${target}" LINK_LIBRARIES) get_target_property(link_libraries "${target}" LINK_LIBRARIES)
@ -157,10 +153,10 @@ function(target_linker_script target scriptfiles)
list(FIND "${link_libraries}" "-L ${search_dir}" found_search_dir) list(FIND "${link_libraries}" "-L ${search_dir}" found_search_dir)
if(found_search_dir EQUAL "-1") # not already added as a search path if(found_search_dir EQUAL "-1") # not already added as a search path
target_link_libraries("${target}" "${is_interface}" "-L ${search_dir}") target_link_libraries("${target}" "${deptype}" "-L ${search_dir}")
endif() endif()
target_link_libraries("${target}" "${is_interface}" "-T ${scriptname}") target_link_libraries("${target}" "${deptype}" "-T ${scriptname}")
# Note: In ESP-IDF, most targets are libraries and libary LINK_DEPENDS don't propagate to # Note: In ESP-IDF, most targets are libraries and libary LINK_DEPENDS don't propagate to
# executable(s) the library is linked to. Attach manually to executable once it is known. # executable(s) the library is linked to. Attach manually to executable once it is known.
@ -168,11 +164,7 @@ function(target_linker_script target scriptfiles)
# Property INTERFACE_LINK_DEPENDS is available in CMake 3.13 which should propagate link # Property INTERFACE_LINK_DEPENDS is available in CMake 3.13 which should propagate link
# dependencies. # dependencies.
if(NOT __PROCESS) if(NOT __PROCESS)
if(is_interface) idf_build_set_property(__LINK_DEPENDS ${abs_script} APPEND)
set_property(TARGET ${target} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${abs_script})
else()
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS ${abs_script})
endif()
endif() endif()
endforeach() endforeach()
endfunction() endfunction()

View file

@ -19,6 +19,8 @@ import argparse
import sys import sys
import tempfile import tempfile
import subprocess import subprocess
import os
import errno
from fragments import FragmentFile from fragments import FragmentFile
from sdkconfig import SDKConfig from sdkconfig import SDKConfig
@ -111,6 +113,14 @@ def main():
with tempfile.TemporaryFile("w+") as output: with tempfile.TemporaryFile("w+") as output:
script_model.write(output) script_model.write(output)
output.seek(0) output.seek(0)
if not os.path.exists(os.path.dirname(output_path)):
try:
os.makedirs(os.path.dirname(output_path))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
with open(output_path, "w") as f: # only create output file after generation has suceeded with open(output_path, "w") as f: # only create output file after generation has suceeded
f.write(output.read()) f.write(output.read())
except LdGenFailure as e: except LdGenFailure as e: