CMake: Put all unit tests in one binary

We currently have 32 different binaries containing unit tests. At least
when I build for Android, each one takes up over 200 MiB, and linking
them all increases my incremental build times by over a minute. I'd
like to change this for the sake of my productivity and disk space.

For reference, MSBuild is already putting all tests in a single binary.
This commit is contained in:
JosJuice 2024-06-06 18:56:37 +02:00
parent ca22d0af57
commit f404edb4dc

View File

@ -4,24 +4,16 @@ add_custom_command(TARGET unittests POST_BUILD COMMAND ${CMAKE_CTEST_COMMAND} "-
string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY "/Tests") string(APPEND CMAKE_RUNTIME_OUTPUT_DIRECTORY "/Tests")
add_library(unittests_main OBJECT UnitTestsMain.cpp) add_executable(tests EXCLUDE_FROM_ALL UnitTestsMain.cpp StubHost.cpp)
set_target_properties(tests PROPERTIES FOLDER Tests)
target_link_libraries(unittests_main PUBLIC fmt::fmt gtest::gtest) target_link_libraries(tests PRIVATE fmt::fmt gtest::gtest core uicommon)
# Since this is a Core dependency, it can't be linked as a normal library. add_test(NAME tests COMMAND tests)
# Otherwise CMake inserts the library after core, but before other core add_dependencies(unittests tests)
# dependencies like videocommon which also use Host_ functions, which makes the
# GNU linker complain.
add_library(unittests_stubhost OBJECT StubHost.cpp)
macro(add_dolphin_test target) macro(add_dolphin_test target)
add_executable(${target} EXCLUDE_FROM_ALL add_library(${target} OBJECT ${ARGN})
${ARGN} target_link_libraries(${target} PUBLIC fmt::fmt gtest::gtest PRIVATE core uicommon)
$<TARGET_OBJECTS:unittests_stubhost> target_link_libraries(tests PRIVATE ${target})
)
set_target_properties(${target} PROPERTIES FOLDER Tests)
target_link_libraries(${target} PRIVATE core uicommon unittests_main)
add_dependencies(unittests ${target})
add_test(NAME ${target} COMMAND ${target})
endmacro() endmacro()
add_subdirectory(Common) add_subdirectory(Common)