if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.7.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.9) return() endif() if(CMAKE_VERSION GREATER_EQUAL 3.11) include(FetchContent) FetchContent_Declare(doctest GIT_REPOSITORY https://github.com/doctest/doctest.git GIT_TAG dev GIT_PROGRESS TRUE CMAKE_ARGS DOCTEST_NO_INSTALL=TRUE) if(CMAKE_VERSION GREATER_EQUAL 3.14) FetchContent_MakeAvailable(doctest) include("${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake") else() FetchContent_GetProperties(doctest) if(NOT doctest_POPULATED) FetchContent_Populate(doctest) add_subdirectory("${doctest_SOURCE_DIR}" "${doctest_BINARY_DIR}") include("${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake") endif() endif() else() find_package(doctest QUIET) if(NOT doctest_FOUND) message(WARNING "CMake is too old to use FetchContent and doctest is not found !\nSkipping tests !") return() endif() include(doctest) endif() # Function to create test executables function(cppterminal_test ) cmake_parse_arguments(ARG "" "SOURCE" "" ${ARGN}) add_executable("${ARG_SOURCE}.test" "${ARG_SOURCE}.test.cpp") target_link_libraries("${ARG_SOURCE}.test" PRIVATE cpp-terminal::cpp-terminal doctest::doctest) doctest_discover_tests("${ARG_SOURCE}.test") endfunction() cppterminal_test(SOURCE file) cppterminal_test(SOURCE key) cppterminal_test(SOURCE screen) cppterminal_test(SOURCE events) cppterminal_test(SOURCE exception) cppterminal_test(SOURCE unicode) cppterminal_test(SOURCE options) cppterminal_test(SOURCE version) if (NOT MINGW AND NOT MSYS) add_executable(Args args.test.cpp) target_link_libraries(Args PRIVATE doctest::doctest cpp-terminal::cpp-terminal) doctest_discover_tests(Args EXTRA_ARGS Bonjour Hello 大家好) endif()