Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/runner/CMakeLists.txt
| Show All 30 Lines | if(WITH_BUILDINFO) | ||||
| ) | ) | ||||
| endif() | endif() | ||||
| # Test libraries need to be linked "whole archive", because they're not | # Test libraries need to be linked "whole archive", because they're not | ||||
| # directly referenced from other code. | # directly referenced from other code. | ||||
| get_property(_test_libs GLOBAL PROPERTY BLENDER_TEST_LIBS) | get_property(_test_libs GLOBAL PROPERTY BLENDER_TEST_LIBS) | ||||
| if(WIN32) | if(WIN32) | ||||
| list(APPEND TEST_LIBS ${_test_libs}) | # Win32 is set using target_link_options after target creation. | ||||
| elseif(APPLE) | elseif(APPLE) | ||||
| list(APPEND TEST_LIBS "-Wl,-force_load" ${_test_libs}) | list(APPEND TEST_LIBS "-Wl,-force_load" ${_test_libs}) | ||||
| elseif(UNIX) | elseif(UNIX) | ||||
| list(APPEND TEST_LIBS "-Wl,--whole-archive" ${_test_libs} "-Wl,--no-whole-archive") | list(APPEND TEST_LIBS "-Wl,--whole-archive" ${_test_libs} "-Wl,--no-whole-archive") | ||||
| else() | else() | ||||
| message(FATAL_ERROR "Unknown how to link whole-archive with your compiler ${CMAKE_CXX_COMPILER_ID}") | message(FATAL_ERROR "Unknown how to link whole-archive with your compiler ${CMAKE_CXX_COMPILER_ID}") | ||||
| endif() | endif() | ||||
| unset(_test_libs) | |||||
| # This builds `bin/tests/blender_test`, but does not add it as a single test. | # This builds `bin/tests/blender_test`, but does not add it as a single test. | ||||
| setup_libdirs() | setup_libdirs() | ||||
| BLENDER_SRC_GTEST_EX( | BLENDER_SRC_GTEST_EX( | ||||
| NAME blender | NAME blender | ||||
| SRC "${SRC}" | SRC "${SRC}" | ||||
| EXTRA_LIBS "${TEST_LIBS}" | EXTRA_LIBS "${TEST_LIBS}" | ||||
| SKIP_ADD_TEST | SKIP_ADD_TEST | ||||
| ) | ) | ||||
| setup_liblinks(blender_test) | setup_liblinks(blender_test) | ||||
| if(WIN32) | |||||
| foreach(_lib ${_test_libs}) | |||||
| # Both target_link_libraries and target_link_options are required here | |||||
| # target_link_libraries will add any dependend libraries, while just setting | |||||
| # the wholearchive flag in target link options will not. | |||||
| target_link_libraries(blender_test ${_lib}) | |||||
| target_link_options(blender_test PRIVATE /wholearchive:$<TARGET_FILE:${_lib}>) | |||||
| endforeach() | |||||
| endif() | |||||
| unset(_test_libs) | |||||
| # This runs the blender_test executable with `--gtest_list_tests`, then | # This runs the blender_test executable with `--gtest_list_tests`, then | ||||
| # exposes those tests individually to the ctest runner. | # exposes those tests individually to the ctest runner. | ||||
| # See https://cmake.org/cmake/help/v3.18/module/GoogleTest.html | # See https://cmake.org/cmake/help/v3.18/module/GoogleTest.html | ||||
| include(GoogleTest) | include(GoogleTest) | ||||
| set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT | set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT | ||||
| ${CMAKE_CURRENT_LIST_DIR}/BlenderAddTests.cmake | ${CMAKE_CURRENT_LIST_DIR}/BlenderAddTests.cmake | ||||
| ) | ) | ||||
| gtest_discover_tests(blender_test | gtest_discover_tests(blender_test | ||||
| # So that the binary can find its shared libs on window. | |||||
| WORKING_DIRECTORY "$<TARGET_FILE_DIR:blender>" | |||||
| # So that unit tests know where to find files: | # So that unit tests know where to find files: | ||||
| EXTRA_ARGS | EXTRA_ARGS | ||||
| --test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests" | --test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests" | ||||
| --test-release-dir "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION}" | --test-release-dir "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION}" | ||||
| ) | ) | ||||