Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/runner/CMakeLists.txt
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if(WIN32) | ||||
| foreach(_lib ${_test_libs}) | foreach(_lib ${_test_libs}) | ||||
| # Both target_link_libraries and target_link_options are required here | # Both target_link_libraries and target_link_options are required here | ||||
| # target_link_libraries will add any dependend libraries, while just setting | # target_link_libraries will add any dependend libraries, while just setting | ||||
| # the wholearchive flag in target link options will not. | # the wholearchive flag in target link options will not. | ||||
| target_link_libraries(blender_test ${_lib}) | target_link_libraries(blender_test ${_lib}) | ||||
| target_link_options(blender_test PRIVATE /wholearchive:$<TARGET_FILE:${_lib}>) | target_link_options(blender_test PRIVATE /wholearchive:$<TARGET_FILE:${_lib}>) | ||||
| endforeach() | endforeach() | ||||
| elseif(APPLE) | elseif(APPLE) | ||||
| # force_load for `_test_libs` ensures that all symbols definitely make it into the test binary. | |||||
| # But linking against them again using `target_link_libraries` creates duplicate symbol | |||||
| # errors when linker cannot deduplicate a force loaded and linked library. | |||||
| # So force load test libraries separately, and link against their non-"test libraries" | |||||
| # dependencies separately. | |||||
| # Gather dependencies of all test libraries. | |||||
| set(_test_libs_dependencies) | |||||
| foreach(_lib ${_test_libs}) | foreach(_lib ${_test_libs}) | ||||
| # We need -force_load for every test library and target_link_libraries will | get_target_property(_interface_libs ${_lib} INTERFACE_LINK_LIBRARIES) | ||||
| # deduplicate it. So explicitly set as linker option for every test lib. | if (_interface_libs) | ||||
| target_link_libraries(blender_test ${_lib}) | list(APPEND _test_libs_dependencies ${_interface_libs}) | ||||
| endif() | |||||
| unset(_interface_libs) | |||||
| endforeach() | |||||
| # Force load test libraries. Ensure that they are not linked twice in case they | |||||
| # are used as dependencies of other test libraries. | |||||
| foreach(_lib ${_test_libs}) | |||||
| list(REMOVE_ITEM _test_libs_dependencies ${_lib}) | |||||
| target_link_options(blender_test PRIVATE "LINKER:-force_load,$<TARGET_FILE:${_lib}>") | target_link_options(blender_test PRIVATE "LINKER:-force_load,$<TARGET_FILE:${_lib}>") | ||||
| endforeach() | endforeach() | ||||
| target_link_libraries(blender_test "${_test_libs_dependencies}") | |||||
| unset(_test_libs_dependencies) | |||||
| endif() | endif() | ||||
| unset(_test_libs) | unset(_test_libs) | ||||