diff --git a/CMakeLists.txt b/CMakeLists.txt index cbb45d1c3..36631c4e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,9 @@ if(SFML_OS_MACOSX) set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)") endif() +# set the output directory for SFML DLLs and executables +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) + # enable project folders set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 09580a4dc..d40bc4ca1 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -330,17 +330,7 @@ function(sfml_add_test target SOURCES 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 - $ - $) - endforeach() - endif() + doctest_discover_tests(${target}) endfunction() # Create an interface library for an external dependency. This virtual target can provide diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a8610385c..9b07ba727 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,8 @@ FetchContent_Declare(doctest GIT_TAG v2.4.9 ) FetchContent_MakeAvailable(doctest) +list(APPEND CMAKE_MODULE_PATH ${doctest_SOURCE_DIR}/scripts/cmake) +include(doctest) add_library(sfml-test-main STATIC DoctestMain.cpp @@ -76,31 +78,19 @@ set(AUDIO_SRC ) sfml_add_test(test-sfml-audio "${AUDIO_SRC}" SFML::Audio) +if(SFML_OS_WINDOWS AND NOT SFML_USE_SYSTEM_DEPS) + add_custom_command( + TARGET test-sfml-audio + COMMENT "Copy OpenAL DLL" + PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/extlibs/bin/$,x64,x86>/openal32.dll $ + ) +endif() + # Automatically run the tests at the end of the build add_custom_target(runtests ALL DEPENDS test-sfml-system test-sfml-window test-sfml-graphics test-sfml-network test-sfml-audio ) -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} "$" - ) -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")