2021-12-24 01:28:14 +08:00
|
|
|
set(SRCROOT "${PROJECT_SOURCE_DIR}/test")
|
2015-04-29 03:54:03 +08:00
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
add_library(sfml-test-main STATIC "${SRCROOT}/DoctestMain.cpp")
|
|
|
|
target_include_directories(sfml-test-main PUBLIC "${PROJECT_SOURCE_DIR}/extlibs/headers" "${SRCROOT}/TestUtilities")
|
2021-12-18 12:39:38 +08:00
|
|
|
target_compile_features(sfml-test-main PRIVATE cxx_std_17)
|
2018-08-19 07:30:53 +08:00
|
|
|
|
|
|
|
# System is always built
|
|
|
|
SET(SYSTEM_SRC
|
2022-01-23 09:11:08 +08:00
|
|
|
"${SRCROOT}/System/Angle.cpp"
|
2021-12-24 07:10:21 +08:00
|
|
|
"${SRCROOT}/System/Clock.cpp"
|
2021-12-25 00:16:06 +08:00
|
|
|
"${SRCROOT}/System/FileInputStream.cpp"
|
2021-12-18 23:32:40 +08:00
|
|
|
"${SRCROOT}/System/Time.cpp"
|
2018-08-20 15:51:42 +08:00
|
|
|
"${SRCROOT}/System/Vector2.cpp"
|
|
|
|
"${SRCROOT}/System/Vector3.cpp"
|
|
|
|
"${SRCROOT}/TestUtilities/SystemUtil.hpp"
|
|
|
|
"${SRCROOT}/TestUtilities/SystemUtil.cpp"
|
2015-04-29 03:54:03 +08:00
|
|
|
)
|
2021-12-29 13:28:50 +08:00
|
|
|
sfml_add_test(test-sfml-system "${SYSTEM_SRC}" SFML::System)
|
2021-12-18 12:39:38 +08:00
|
|
|
target_link_libraries(test-sfml-system PRIVATE sfml-test-main)
|
2015-04-29 03:54:03 +08:00
|
|
|
|
2018-08-19 07:30:53 +08:00
|
|
|
if(SFML_BUILD_WINDOW)
|
|
|
|
SET(WINDOW_SRC
|
2022-01-12 11:17:15 +08:00
|
|
|
"${SRCROOT}/Window/ContextSettings.cpp"
|
2021-12-24 06:21:51 +08:00
|
|
|
"${SRCROOT}/Window/VideoMode.cpp"
|
2018-08-20 15:51:42 +08:00
|
|
|
"${SRCROOT}/TestUtilities/WindowUtil.hpp"
|
|
|
|
"${SRCROOT}/TestUtilities/WindowUtil.cpp"
|
2018-08-19 07:30:53 +08:00
|
|
|
)
|
2021-12-29 13:28:50 +08:00
|
|
|
sfml_add_test(test-sfml-window "${WINDOW_SRC}" SFML::Window)
|
2021-12-18 12:39:38 +08:00
|
|
|
target_link_libraries(test-sfml-window PRIVATE sfml-test-main)
|
2018-08-19 07:30:53 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SFML_BUILD_GRAPHICS)
|
|
|
|
SET(GRAPHICS_SRC
|
2022-01-12 05:40:51 +08:00
|
|
|
"${SRCROOT}/Graphics/BlendMode.cpp"
|
2021-12-25 01:04:04 +08:00
|
|
|
"${SRCROOT}/Graphics/Color.cpp"
|
2018-08-20 15:51:42 +08:00
|
|
|
"${SRCROOT}/Graphics/Rect.cpp"
|
2021-12-24 08:18:33 +08:00
|
|
|
"${SRCROOT}/Graphics/Transform.cpp"
|
2022-01-03 11:59:15 +08:00
|
|
|
"${SRCROOT}/Graphics/Vertex.cpp"
|
2018-08-20 15:51:42 +08:00
|
|
|
"${SRCROOT}/TestUtilities/GraphicsUtil.hpp"
|
|
|
|
"${SRCROOT}/TestUtilities/GraphicsUtil.cpp"
|
2018-08-19 07:30:53 +08:00
|
|
|
)
|
2021-12-29 13:28:50 +08:00
|
|
|
sfml_add_test(test-sfml-graphics "${GRAPHICS_SRC}" SFML::Graphics)
|
2021-12-18 12:39:38 +08:00
|
|
|
target_link_libraries(test-sfml-graphics PRIVATE sfml-test-main)
|
2018-08-19 07:30:53 +08:00
|
|
|
endif()
|
|
|
|
|
2021-12-06 06:27:48 +08:00
|
|
|
if(SFML_BUILD_NETWORK)
|
|
|
|
SET(NETWORK_SRC
|
|
|
|
"${SRCROOT}/Network/Packet.cpp"
|
|
|
|
)
|
2021-12-29 13:28:50 +08:00
|
|
|
sfml_add_test(test-sfml-network "${NETWORK_SRC}" SFML::Network)
|
2021-12-18 12:39:38 +08:00
|
|
|
target_link_libraries(test-sfml-network PRIVATE sfml-test-main)
|
2021-12-06 06:27:48 +08:00
|
|
|
endif()
|
|
|
|
|
2022-02-06 12:38:28 +08:00
|
|
|
if(SFML_BUILD_AUDIO)
|
|
|
|
SET(AUDIO_SRC
|
|
|
|
"${SRCROOT}/Audio/Dummy.cpp" # TODO: Remove when there are real tests
|
|
|
|
)
|
|
|
|
sfml_add_test(test-sfml-audio "${AUDIO_SRC}" SFML::Audio)
|
|
|
|
target_link_libraries(test-sfml-audio PRIVATE sfml-test-main)
|
|
|
|
endif()
|
|
|
|
|
2018-08-20 02:04:11 +08:00
|
|
|
# Automatically run the tests at the end of the build
|
2018-08-21 05:49:56 +08:00
|
|
|
add_custom_target(runtests ALL
|
2022-02-06 12:38:28 +08:00
|
|
|
DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio
|
2018-08-19 07:30:53 +08:00
|
|
|
)
|
2018-11-30 02:38:27 +08:00
|
|
|
|
2022-02-06 12:38:28 +08:00
|
|
|
if(SFML_OS_WINDOWS AND NOT SFML_USE_SYSTEM_DEPS)
|
|
|
|
# Copy the binaries of SFML dependencies
|
|
|
|
list(APPEND BINARIES
|
|
|
|
"openal32.dll"
|
|
|
|
)
|
|
|
|
|
|
|
|
foreach (BINARY ${BINARIES})
|
|
|
|
if(ARCH_32BITS)
|
|
|
|
list(APPEND BINARY_PATHS "${PROJECT_SOURCE_DIR}/extlibs/bin/x86/${BINARY}")
|
|
|
|
elseif(ARCH_64BITS)
|
|
|
|
list(APPEND BINARY_PATHS "${PROJECT_SOURCE_DIR}/extlibs/bin/x64/${BINARY}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Copy binaries"
|
|
|
|
POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy ${BINARY_PATHS} "$<TARGET_FILE_DIR:test-sfml-system>"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SFML_ENABLE_COVERAGE AND SFML_COMPILER_MSVC)
|
|
|
|
# Try to find and use OpenCppCoverage for coverage reporting when building with MSVC
|
|
|
|
find_program(OpenCppCoverage_BINARY "OpenCppCoverage.exe")
|
|
|
|
|
|
|
|
if(OpenCppCoverage_BINARY)
|
|
|
|
execute_process(COMMAND "${OpenCppCoverage_BINARY}" --help ERROR_VARIABLE OpenCppCoverage_HELP_OUTPUT OUTPUT_QUIET)
|
|
|
|
|
|
|
|
if(OpenCppCoverage_HELP_OUTPUT MATCHES "OpenCppCoverage Version: ([.0-9]+)")
|
|
|
|
set(OpenCppCoverage_VERSION "${CMAKE_MATCH_1}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
|
|
|
|
find_package_handle_standard_args(OpenCppCoverage
|
|
|
|
REQUIRED_VARS OpenCppCoverage_BINARY
|
|
|
|
VERSION_VAR OpenCppCoverage_VERSION
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SFML_ENABLE_COVERAGE AND OpenCppCoverage_FOUND)
|
|
|
|
# Use OpenCppCoverage
|
|
|
|
message(STATUS "Using OpenCppCoverage to generate coverage report")
|
|
|
|
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_EXCLUDE "${CMAKE_CTEST_COMMAND}")
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_SRC "${PROJECT_SOURCE_DIR}/src")
|
|
|
|
string(REPLACE "/" "\\" COVERAGE_INCLUDE "${PROJECT_SOURCE_DIR}/include")
|
|
|
|
|
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Run tests"
|
|
|
|
POST_BUILD COMMAND "${OpenCppCoverage_BINARY}" ARGS --quiet --export_type cobertura:"${CMAKE_BINARY_DIR}/coverage.out" --cover_children --excluded_modules "${COVERAGE_EXCLUDE}" --sources "${COVERAGE_SRC}" --sources "${COVERAGE_INCLUDE}" -- "${CMAKE_CTEST_COMMAND}" --output-on-failure -C $<CONFIG>
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
# Run tests without a coverage runner
|
|
|
|
add_custom_command(TARGET runtests
|
|
|
|
COMMENT "Run tests"
|
|
|
|
POST_BUILD COMMAND "${CMAKE_CTEST_COMMAND}" --output-on-failure -C $<CONFIG>
|
|
|
|
)
|
|
|
|
endif()
|