2023-06-14 22:49:59 +10:00
|
|
|
# SPDX-FileCopyrightText: 2020 Blender Foundation
|
|
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2020-07-16 12:58:49 +02:00
|
|
|
|
|
|
|
|
# Build the test runner. This runner takes care of running all GTests, i.e.
|
|
|
|
|
# the code that was built using the blender_add_test_lib() CMake macro (see
|
|
|
|
|
# macros.cmake).
|
|
|
|
|
set(SRC
|
|
|
|
|
blender_test.cc
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(WITH_BUILDINFO)
|
|
|
|
|
list(APPEND SRC
|
|
|
|
|
"$<TARGET_OBJECTS:buildinfoobj>"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test libraries need to be linked "whole archive", because they're not
|
|
|
|
|
# directly referenced from other code.
|
|
|
|
|
get_property(_test_libs GLOBAL PROPERTY BLENDER_TEST_LIBS)
|
2020-07-31 14:14:56 +02:00
|
|
|
if(WIN32 OR APPLE)
|
|
|
|
|
# Windows and macOS set target_link_options after target creation.
|
2020-07-16 12:58:49 +02:00
|
|
|
elseif(UNIX)
|
|
|
|
|
list(APPEND TEST_LIBS "-Wl,--whole-archive" ${_test_libs} "-Wl,--no-whole-archive")
|
|
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "Unknown how to link whole-archive with your compiler ${CMAKE_CXX_COMPILER_ID}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# This builds `bin/tests/blender_test`, but does not add it as a single test.
|
2022-09-23 14:33:44 +10:00
|
|
|
blender_src_gtest_ex(
|
2020-07-16 12:58:49 +02:00
|
|
|
NAME blender
|
|
|
|
|
SRC "${SRC}"
|
|
|
|
|
EXTRA_LIBS "${TEST_LIBS}"
|
|
|
|
|
SKIP_ADD_TEST
|
|
|
|
|
)
|
2020-09-15 16:00:15 +02:00
|
|
|
setup_platform_linker_libs(blender_test)
|
2020-07-16 12:58:49 +02:00
|
|
|
|
2020-07-27 10:55:34 -06:00
|
|
|
if(WIN32)
|
|
|
|
|
foreach(_lib ${_test_libs})
|
|
|
|
|
# Both target_link_libraries and target_link_options are required here
|
2021-11-16 18:44:04 -05:00
|
|
|
# target_link_libraries will add any dependent libraries, while just setting
|
2020-07-27 10:55:34 -06:00
|
|
|
# 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()
|
2022-12-15 09:04:59 -07:00
|
|
|
set_target_properties(blender_test PROPERTIES VS_DEBUGGER_ENVIRONMENT "${PLATFORM_ENV_INSTALL};$<TARGET_FILE_DIR:blender>")
|
2020-07-31 14:14:56 +02:00
|
|
|
elseif(APPLE)
|
|
|
|
|
foreach(_lib ${_test_libs})
|
2023-04-19 09:05:43 +05:30
|
|
|
# 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} "-Wl,-force_load,$<TARGET_PROPERTY:${_lib},IMPORTED_LOCATION>")
|
2021-02-03 23:20:27 +05:30
|
|
|
endforeach()
|
2020-07-27 10:55:34 -06:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
unset(_test_libs)
|