Simplify how tests are built

This commit is contained in:
Chris Thrasher 2022-01-21 21:09:49 -07:00 committed by Vittorio Romeo
parent 83259a4a31
commit 5236513f16
2 changed files with 24 additions and 31 deletions

View File

@ -327,7 +327,7 @@ function(sfml_add_test target SOURCES DEPENDS)
set_target_properties(${target} PROPERTIES FOLDER "Tests") set_target_properties(${target} PROPERTIES FOLDER "Tests")
# link the target to its SFML dependencies # link the target to its SFML dependencies
target_link_libraries(${target} PRIVATE ${DEPENDS}) target_link_libraries(${target} PRIVATE ${DEPENDS} sfml-test-main)
# If coverage is enabled for MSVC and we are linking statically, use /WHOLEARCHIVE # If coverage is enabled for MSVC and we are linking statically, use /WHOLEARCHIVE
# to make sure the linker doesn't discard unused code sections before coverage can be measured # to make sure the linker doesn't discard unused code sections before coverage can be measured

View File

@ -1,62 +1,55 @@
set(SRCROOT "${PROJECT_SOURCE_DIR}/test") add_library(sfml-test-main STATIC DoctestMain.cpp)
target_include_directories(sfml-test-main PUBLIC "${PROJECT_SOURCE_DIR}/extlibs/headers" TestUtilities)
add_library(sfml-test-main STATIC "${SRCROOT}/DoctestMain.cpp")
target_include_directories(sfml-test-main PUBLIC "${PROJECT_SOURCE_DIR}/extlibs/headers" "${SRCROOT}/TestUtilities")
target_compile_features(sfml-test-main PRIVATE cxx_std_17) target_compile_features(sfml-test-main PRIVATE cxx_std_17)
# System is always built # System is always built
SET(SYSTEM_SRC SET(SYSTEM_SRC
"${SRCROOT}/System/Angle.cpp" System/Angle.cpp
"${SRCROOT}/System/Clock.cpp" System/Clock.cpp
"${SRCROOT}/System/FileInputStream.cpp" System/FileInputStream.cpp
"${SRCROOT}/System/Time.cpp" System/Time.cpp
"${SRCROOT}/System/Vector2.cpp" System/Vector2.cpp
"${SRCROOT}/System/Vector3.cpp" System/Vector3.cpp
"${SRCROOT}/TestUtilities/SystemUtil.hpp" TestUtilities/SystemUtil.hpp
"${SRCROOT}/TestUtilities/SystemUtil.cpp" TestUtilities/SystemUtil.cpp
) )
sfml_add_test(test-sfml-system "${SYSTEM_SRC}" SFML::System) sfml_add_test(test-sfml-system "${SYSTEM_SRC}" SFML::System)
target_link_libraries(test-sfml-system PRIVATE sfml-test-main)
if(SFML_BUILD_WINDOW) if(SFML_BUILD_WINDOW)
SET(WINDOW_SRC SET(WINDOW_SRC
"${SRCROOT}/Window/ContextSettings.cpp" Window/ContextSettings.cpp
"${SRCROOT}/Window/VideoMode.cpp" Window/VideoMode.cpp
"${SRCROOT}/TestUtilities/WindowUtil.hpp" TestUtilities/WindowUtil.hpp
"${SRCROOT}/TestUtilities/WindowUtil.cpp" TestUtilities/WindowUtil.cpp
) )
sfml_add_test(test-sfml-window "${WINDOW_SRC}" SFML::Window) sfml_add_test(test-sfml-window "${WINDOW_SRC}" SFML::Window)
target_link_libraries(test-sfml-window PRIVATE sfml-test-main)
endif() endif()
if(SFML_BUILD_GRAPHICS) if(SFML_BUILD_GRAPHICS)
SET(GRAPHICS_SRC SET(GRAPHICS_SRC
"${SRCROOT}/Graphics/BlendMode.cpp" Graphics/BlendMode.cpp
"${SRCROOT}/Graphics/Color.cpp" Graphics/Color.cpp
"${SRCROOT}/Graphics/Rect.cpp" Graphics/Rect.cpp
"${SRCROOT}/Graphics/Transform.cpp" Graphics/Transform.cpp
"${SRCROOT}/Graphics/Vertex.cpp" Graphics/Vertex.cpp
"${SRCROOT}/TestUtilities/GraphicsUtil.hpp" TestUtilities/GraphicsUtil.hpp
"${SRCROOT}/TestUtilities/GraphicsUtil.cpp" TestUtilities/GraphicsUtil.cpp
) )
sfml_add_test(test-sfml-graphics "${GRAPHICS_SRC}" SFML::Graphics) sfml_add_test(test-sfml-graphics "${GRAPHICS_SRC}" SFML::Graphics)
target_link_libraries(test-sfml-graphics PRIVATE sfml-test-main)
endif() endif()
if(SFML_BUILD_NETWORK) if(SFML_BUILD_NETWORK)
SET(NETWORK_SRC SET(NETWORK_SRC
"${SRCROOT}/Network/Packet.cpp" Network/Packet.cpp
) )
sfml_add_test(test-sfml-network "${NETWORK_SRC}" SFML::Network) sfml_add_test(test-sfml-network "${NETWORK_SRC}" SFML::Network)
target_link_libraries(test-sfml-network PRIVATE sfml-test-main)
endif() endif()
if(SFML_BUILD_AUDIO) if(SFML_BUILD_AUDIO)
SET(AUDIO_SRC SET(AUDIO_SRC
"${SRCROOT}/Audio/Dummy.cpp" # TODO: Remove when there are real tests Audio/Dummy.cpp # TODO: Remove when there are real tests
) )
sfml_add_test(test-sfml-audio "${AUDIO_SRC}" SFML::Audio) sfml_add_test(test-sfml-audio "${AUDIO_SRC}" SFML::Audio)
target_link_libraries(test-sfml-audio PRIVATE sfml-test-main)
endif() endif()
# Automatically run the tests at the end of the build # Automatically run the tests at the end of the build