diff --git a/docs/en/migration-guides/build-system.rst b/docs/en/migration-guides/build-system.rst index 42a8711bd3..11e9f7aee6 100644 --- a/docs/en/migration-guides/build-system.rst +++ b/docs/en/migration-guides/build-system.rst @@ -55,3 +55,18 @@ instead of:: set(EXTRA_COMPONENT_DIRS "${EXTRA_COMPONENT_DIRS} path3") Defining these variables as CMake lists is compatible with previous IDF versions. + +Update usage of target_link_libraries with project_elf +------------------------------------------------------ + +ESP-IDF v5.0 fixes issues with CMake variable propagation for components, which caused among others compiler flags and defines applied to one component to be applied to every component in the project. + +As a side effect of this ESP-IDF user projects from ESP-IDF v5.0 onwards using ``target_link_libraries`` with ``project_elf`` explicitly and custom CMake projects must specify ``PRIVATE``, ``PUBLIC`` or ``INTERFACE`` arguments. This is a breaking change and is not backwards compatible with previous ESP-IDF versions. + +For example:: + + target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=esp_panic_handler") + +instead of:: + + target_link_libraries(${project_elf} "-Wl,--wrap=esp_panic_handler") diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 250ade412e..def45ee20c 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -473,17 +473,17 @@ macro(project project_name) add_dependencies(${project_elf} _project_elf_src) if(__PROJECT_GROUP_LINK_COMPONENTS) - target_link_libraries(${project_elf} "-Wl,--start-group") + target_link_libraries(${project_elf} PRIVATE "-Wl,--start-group") endif() if(test_components) - target_link_libraries(${project_elf} "-Wl,--whole-archive") + target_link_libraries(${project_elf} PRIVATE "-Wl,--whole-archive") foreach(test_component ${test_components}) if(TARGET ${test_component}) - target_link_libraries(${project_elf} ${test_component}) + target_link_libraries(${project_elf} PRIVATE ${test_component}) endif() endforeach() - target_link_libraries(${project_elf} "-Wl,--no-whole-archive") + target_link_libraries(${project_elf} PRIVATE "-Wl,--no-whole-archive") endif() idf_build_get_property(build_components BUILD_COMPONENT_ALIASES) @@ -496,9 +496,12 @@ macro(project project_name) __component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE) if(whole_archive) message(STATUS "Component ${build_component} will be linked with -Wl,--whole-archive") - target_link_libraries(${project_elf} "-Wl,--whole-archive" ${build_component} "-Wl,--no-whole-archive") + target_link_libraries(${project_elf} PRIVATE + "-Wl,--whole-archive" + ${build_component} + "-Wl,--no-whole-archive") else() - target_link_libraries(${project_elf} ${build_component}) + target_link_libraries(${project_elf} PRIVATE ${build_component}) endif() endforeach() @@ -507,7 +510,7 @@ macro(project project_name) set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") set(idf_target "${IDF_TARGET}") string(TOUPPER ${idf_target} idf_target) - target_link_libraries(${project_elf} "-Wl,--cref" "-Wl,--defsym=IDF_TARGET_${idf_target}=0" + target_link_libraries(${project_elf} PRIVATE "-Wl,--cref" "-Wl,--defsym=IDF_TARGET_${idf_target}=0" "-Wl,--Map=\"${mapfile}\"") unset(idf_target) endif() diff --git a/tools/test_apps/system/memprot/CMakeLists.txt b/tools/test_apps/system/memprot/CMakeLists.txt index c1fbe08208..fc362b1d4d 100644 --- a/tools/test_apps/system/memprot/CMakeLists.txt +++ b/tools/test_apps/system/memprot/CMakeLists.txt @@ -4,6 +4,6 @@ if((IDF_TARGET STREQUAL "esp32s2") OR (IDF_TARGET STREQUAL "esp32c3")) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(test_memprot) - target_link_libraries(${project_elf} "-Wl,--wrap=esp_panic_handler") + target_link_libraries(${project_elf} PRIVATE "-Wl,--wrap=esp_panic_handler") endif()