From 532ac1163ceea857df0f3f144de0dde837712bbe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 15 Sep 2020 11:16:35 +0200 Subject: Tests: bundle tests for some modules in their own executables The ffmpeg, guardedalloc and blenlib are quite isolated and putting them in their own executable separate from blender_test is faster for development than linking the entire blender_tests executable. For Cycles, this also bundles all the unit tests into one executable. Ref T79958 Differential Revision: https://developer.blender.org/D8714 --- build_files/cmake/macros.cmake | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'build_files/cmake') diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 268daa4aae3..1e3863ac567 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -375,9 +375,8 @@ function(blender_add_lib set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name}) endfunction() -# blender_add_test_lib() is used to define a test library. It is intended to be -# called in tandem with blender_add_lib(). The test library will be linked into -# the bf_gtest_runner_test executable (see tests/gtests/CMakeLists.txt). +# Add tests for a Blender library, to be called in tandem with blender_add_lib(). +# The tests will be part of the blender_test executable (see tests/gtests/runner). function(blender_add_test_lib name sources @@ -411,6 +410,48 @@ function(blender_add_test_lib set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name}) endfunction() + +# Add tests for a Blender library, to be called in tandem with blender_add_lib(). +# Test will be compiled into a ${name}_test executable. +# +# To be used for smaller isolated libraries, that do not have many dependencies. +# For libraries that do drag in many other Blender libraries and would create a +# very large executable, blender_add_test_lib() should be used instead. +function(blender_add_test_executable + name + sources + includes + includes_sys + library_deps + ) + + add_cc_flags_custom_test(${name} PARENT_SCOPE) + + ## Otherwise external projects will produce warnings that we cannot fix. + remove_strict_flags() + + include_directories(${includes}) + include_directories(${includes_sys}) + setup_libdirs() + + BLENDER_SRC_GTEST_EX( + NAME ${name} + SRC "${sources}" + EXTRA_LIBS "${library_deps}" + SKIP_ADD_TEST + ) + + include(GTest) + set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT + ${CMAKE_SOURCE_DIR}/build_files/cmake/Modules/GTestAddTests.cmake + ) + + gtest_discover_tests(${name}_test + DISCOVERY_MODE PRE_TEST + WORKING_DIRECTORY "${TEST_INSTALL_DIR}" + ) +endfunction() + # Ninja only: assign 'heavy pool' to some targets that are especially RAM-consuming to build. function(setup_heavy_lib_pool) if(WITH_NINJA_POOL_JOBS AND NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS) -- cgit v1.2.3