Use sfml_add_test macro for unit tests and copy dlls to output directory if required
This commit is contained in:
parent
2c3a321afd
commit
53972ed5f2
@ -285,8 +285,12 @@ if(SFML_BUILD_DOC)
|
|||||||
add_subdirectory(doc)
|
add_subdirectory(doc)
|
||||||
endif()
|
endif()
|
||||||
if(SFML_BUILD_TEST_SUITE)
|
if(SFML_BUILD_TEST_SUITE)
|
||||||
enable_testing()
|
if (SFML_OS_IOS)
|
||||||
add_subdirectory(test)
|
message( WARNING "Unit testing not supported on iOS")
|
||||||
|
else()
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# on Linux and BSD-like OS, install pkg-config files by default
|
# on Linux and BSD-like OS, install pkg-config files by default
|
||||||
|
@ -297,6 +297,42 @@ macro(sfml_add_example target)
|
|||||||
|
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
# add a new target which is a SFML test
|
||||||
|
# example: sfml_add_test(sfml-test
|
||||||
|
# ftp.cpp ...
|
||||||
|
# sfml-network)
|
||||||
|
function(sfml_add_test target SOURCES DEPENDS)
|
||||||
|
|
||||||
|
# set a source group for the source files
|
||||||
|
source_group("" FILES ${SOURCES})
|
||||||
|
|
||||||
|
# check whether resources must be added in target
|
||||||
|
set(target_input ${SOURCES})
|
||||||
|
|
||||||
|
# create the target
|
||||||
|
add_executable(${target} ${target_input})
|
||||||
|
|
||||||
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||||
|
set_target_properties(${target} PROPERTIES FOLDER "Tests")
|
||||||
|
|
||||||
|
# link the target to its SFML dependencies
|
||||||
|
if(DEPENDS)
|
||||||
|
target_link_libraries(${target} PRIVATE ${DEPENDS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add the test
|
||||||
|
add_test(${target} ${target})
|
||||||
|
|
||||||
|
# If building shared libs on windows we must copy the dependencies into the folder
|
||||||
|
if (WIN32 AND BUILD_SHARED_LIBS)
|
||||||
|
foreach (DEPENDENCY ${DEPENDS})
|
||||||
|
add_custom_command(TARGET ${target} PRE_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
$<TARGET_FILE:${DEPENDENCY}>
|
||||||
|
$<TARGET_FILE_DIR:${target}>)
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Create an interface library for an external dependency. This virtual target can provide
|
# Create an interface library for an external dependency. This virtual target can provide
|
||||||
# link specifications and include directories to be used by dependees.
|
# link specifications and include directories to be used by dependees.
|
||||||
|
@ -12,9 +12,7 @@ SET(SYSTEM_SRC
|
|||||||
"${SRCROOT}/TestUtilities/SystemUtil.hpp"
|
"${SRCROOT}/TestUtilities/SystemUtil.hpp"
|
||||||
"${SRCROOT}/TestUtilities/SystemUtil.cpp"
|
"${SRCROOT}/TestUtilities/SystemUtil.cpp"
|
||||||
)
|
)
|
||||||
add_executable(systemtest ${SYSTEM_SRC})
|
sfml_add_test(systemtest "${SYSTEM_SRC}" sfml-system)
|
||||||
target_link_libraries(systemtest sfml-system)
|
|
||||||
add_test(System-module-tests systemtest)
|
|
||||||
|
|
||||||
if(SFML_BUILD_WINDOW)
|
if(SFML_BUILD_WINDOW)
|
||||||
SET(WINDOW_SRC
|
SET(WINDOW_SRC
|
||||||
@ -22,9 +20,7 @@ if(SFML_BUILD_WINDOW)
|
|||||||
"${SRCROOT}/TestUtilities/WindowUtil.hpp"
|
"${SRCROOT}/TestUtilities/WindowUtil.hpp"
|
||||||
"${SRCROOT}/TestUtilities/WindowUtil.cpp"
|
"${SRCROOT}/TestUtilities/WindowUtil.cpp"
|
||||||
)
|
)
|
||||||
add_executable(windowtest ${WINDOW_SRC})
|
sfml_add_test(windowtest "${WINDOW_SRC}" sfml-window)
|
||||||
target_link_libraries(windowtest sfml-window)
|
|
||||||
add_test(Window-module-tests windowtest)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SFML_BUILD_GRAPHICS)
|
if(SFML_BUILD_GRAPHICS)
|
||||||
@ -34,17 +30,15 @@ if(SFML_BUILD_GRAPHICS)
|
|||||||
"${SRCROOT}/TestUtilities/GraphicsUtil.hpp"
|
"${SRCROOT}/TestUtilities/GraphicsUtil.hpp"
|
||||||
"${SRCROOT}/TestUtilities/GraphicsUtil.cpp"
|
"${SRCROOT}/TestUtilities/GraphicsUtil.cpp"
|
||||||
)
|
)
|
||||||
add_executable(graphicstest ${GRAPHICS_SRC})
|
sfml_add_test(graphicstest "${GRAPHICS_SRC}" sfml-graphics)
|
||||||
target_link_libraries(graphicstest sfml-graphics)
|
|
||||||
add_test(Graphics-module-tests graphicstest)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Automatically run the tests at the end of the build
|
# Automatically run the tests at the end of the build
|
||||||
add_custom_target(runtests ALL
|
add_custom_target(runtests ALL
|
||||||
DEPENDS systemtest windowtest graphicstest
|
DEPENDS systemtest windowtest graphicstest
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command(TARGET runtests
|
add_custom_command(TARGET runtests
|
||||||
COMMENT "Run tests"
|
COMMENT "Run tests"
|
||||||
POST_BUILD COMMAND ctest ARGS --output-on-failure
|
POST_BUILD COMMAND ctest ARGS --output-on-failure
|
||||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
)
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user