diff options
author | Ankit Meel <ankitjmeel@gmail.com> | 2021-02-03 20:50:27 +0300 |
---|---|---|
committer | Ankit Meel <ankitjmeel@gmail.com> | 2021-02-03 20:50:27 +0300 |
commit | dcb2821292f962951e88f146cb304160f21f73da (patch) | |
tree | 0cee6cad43676b007d45ac71b7047b57377780ef /tests/gtests | |
parent | 46e66cecb36f51edf2c146d1f813144f6356dce2 (diff) |
macOS/GTest: Fix duplicate symbol errors with some generators
Don't force load _and_ link against a library in case
linker fails to deduplicate them.
https://devtalk.blender.org/t/macos-duplicate-symbol-errors/17343
Reviewed By: #platform_macos, brecht
Differential Revision: https://developer.blender.org/D10294
Diffstat (limited to 'tests/gtests')
-rw-r--r-- | tests/gtests/runner/CMakeLists.txt | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/gtests/runner/CMakeLists.txt b/tests/gtests/runner/CMakeLists.txt index 85b80979074..b1b9cf98d68 100644 --- a/tests/gtests/runner/CMakeLists.txt +++ b/tests/gtests/runner/CMakeLists.txt @@ -62,12 +62,31 @@ if(WIN32) target_link_options(blender_test PRIVATE /wholearchive:$<TARGET_FILE:${_lib}>) endforeach() 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}) - # We need -force_load for every test library and target_link_libraries will - # deduplicate it. So explicitly set as linker option for every test lib. - target_link_libraries(blender_test ${_lib}) + get_target_property(_interface_libs ${_lib} INTERFACE_LINK_LIBRARIES) + if (_interface_libs) + 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}>") endforeach() + + target_link_libraries(blender_test "${_test_libs_dependencies}") + unset(_test_libs_dependencies) endif() unset(_test_libs) |