2019-08-24 15:31:42 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
2019-07-31 16:09:26 +00:00
|
|
|
|
2019-08-24 15:31:42 +00:00
|
|
|
set(SOURCES test.cpp)
|
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
set(OPTIONS /W4 /WX)
|
|
|
|
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
|
|
|
if(HAS_PERMISSIVE_FLAG)
|
|
|
|
set(OPTIONS ${OPTIONS} /permissive-)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG)
|
|
|
|
check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror)
|
|
|
|
|
|
|
|
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
|
|
|
|
endif()
|
2019-07-31 16:09:26 +00:00
|
|
|
|
2019-07-31 19:48:50 +00:00
|
|
|
function(make_test target std)
|
2019-08-24 15:31:42 +00:00
|
|
|
add_executable(${target} ${SOURCES})
|
|
|
|
target_compile_options(${target} PRIVATE ${OPTIONS})
|
|
|
|
target_include_directories(${target} PRIVATE 3rdparty/Catch2)
|
|
|
|
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
|
|
|
|
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
|
|
|
|
if(std)
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
target_compile_options(${target} PRIVATE /std:${std})
|
|
|
|
else()
|
|
|
|
target_compile_options(${target} PRIVATE -std=${std})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
add_test(NAME ${target} COMMAND ${target})
|
2019-07-31 19:48:50 +00:00
|
|
|
endfunction()
|
|
|
|
|
2019-08-24 15:31:42 +00:00
|
|
|
make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
|
|
|
|
|
|
|
|
if(HAS_CPP20_FLAG)
|
|
|
|
make_test(${CMAKE_PROJECT_NAME}-cpp20.t c++20)
|
|
|
|
endif()
|
2019-07-31 19:48:50 +00:00
|
|
|
|
2019-08-24 15:31:42 +00:00
|
|
|
if(HAS_CPPLATEST_FLAG)
|
|
|
|
make_test(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest)
|
2018-08-29 11:57:44 +00:00
|
|
|
endif()
|