Merge branch 'bugfix/unit_test_example' into 'master'

fix(linux_target): fixed TEST_COMPONENTS not working on macOS for linux target

Closes IDFGH-14751

See merge request espressif/esp-idf!37429
This commit is contained in:
Marius Vikhammer 2025-03-04 13:59:51 +08:00
commit 64113b8e86

View File

@ -785,21 +785,6 @@ macro(project project_name)
target_link_libraries(${project_elf} PRIVATE "-Wl,--start-group") target_link_libraries(${project_elf} PRIVATE "-Wl,--start-group")
endif() endif()
if(test_components)
target_link_libraries(${project_elf} PRIVATE "-Wl,--whole-archive")
foreach(test_component ${test_components})
if(TARGET ${test_component})
target_link_libraries(${project_elf} PRIVATE ${test_component})
endif()
endforeach()
target_link_libraries(${project_elf} PRIVATE "-Wl,--no-whole-archive")
endif()
idf_build_get_property(build_components BUILD_COMPONENT_ALIASES)
if(test_components)
list(REMOVE_ITEM build_components ${test_components})
endif()
if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
# Compiling for the host, and the host is macOS, so the linker is Darwin LD. # Compiling for the host, and the host is macOS, so the linker is Darwin LD.
# Note, when adding support for Clang and LLD based toolchain this check will # Note, when adding support for Clang and LLD based toolchain this check will
@ -809,6 +794,29 @@ macro(project project_name)
set(linker_type "GNU") set(linker_type "GNU")
endif() endif()
if(test_components)
if(linker_type STREQUAL "GNU")
target_link_libraries(${project_elf} PRIVATE "-Wl,--whole-archive")
foreach(test_component ${test_components})
if(TARGET ${test_component})
target_link_libraries(${project_elf} PRIVATE ${test_component})
endif()
endforeach()
target_link_libraries(${project_elf} PRIVATE "-Wl,--no-whole-archive")
elseif(linker_type STREQUAL "Darwin")
foreach(test_component ${test_components})
if(TARGET ${test_component})
target_link_libraries(${project_elf} PRIVATE "-Wl,-force_load" ${test_component})
endif()
endforeach()
endif()
endif()
idf_build_get_property(build_components BUILD_COMPONENT_ALIASES)
if(test_components)
list(REMOVE_ITEM build_components ${test_components})
endif()
foreach(build_component ${build_components}) foreach(build_component ${build_components})
__component_get_target(build_component_target ${build_component}) __component_get_target(build_component_target ${build_component})
__component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE) __component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE)