Merge pull request #12837 from JosJuice/cmake-one-tests-binary

CMake: Put all unit tests in one binary
This commit is contained in:
Admiral H. Curtiss 2024-06-10 22:47:45 +02:00 committed by GitHub
commit 04c246d11f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 16 deletions

View File

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