2019-03-21 06:25:17 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2019-03-12 13:55:56 +00:00
|
|
|
set(SOURCES test.cpp)
|
|
|
|
|
2018-08-29 11:57:44 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
2019-04-25 17:08:44 +00:00
|
|
|
set(OPTIONS /W4 /WX)
|
2019-03-21 11:05:37 +00:00
|
|
|
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
|
|
|
if(HAS_PERMISSIVE_FLAG)
|
2018-08-29 11:57:44 +00:00
|
|
|
set(OPTIONS ${OPTIONS} /permissive-)
|
|
|
|
endif()
|
2019-03-21 06:25:17 +00:00
|
|
|
|
|
|
|
check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG)
|
|
|
|
check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG)
|
|
|
|
check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG)
|
2018-08-29 11:57:44 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
2019-04-25 17:08:44 +00:00
|
|
|
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror)
|
2018-08-29 11:57:44 +00:00
|
|
|
|
2019-03-21 06:25:17 +00:00
|
|
|
check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG)
|
|
|
|
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
|
2018-08-29 11:57:44 +00:00
|
|
|
endif()
|
|
|
|
|
2019-05-25 16:17:06 +00:00
|
|
|
function(make_test target std)
|
2018-08-29 11:57:44 +00:00
|
|
|
add_executable(${target} ${SOURCES})
|
|
|
|
target_compile_options(${target} PRIVATE ${OPTIONS})
|
2019-04-23 13:18:39 +00:00
|
|
|
target_include_directories(${target} PRIVATE 3rdparty/Catch2)
|
|
|
|
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
|
2018-08-29 11:57:44 +00:00
|
|
|
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()
|
2019-05-25 16:17:06 +00:00
|
|
|
add_test(NAME ${target} COMMAND ${target})
|
2018-08-29 11:57:44 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
if(HAS_CPP17_FLAG)
|
2019-05-25 16:17:06 +00:00
|
|
|
make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
|
2018-08-29 11:57:44 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(HAS_CPPLATEST_FLAG)
|
2019-05-25 16:17:06 +00:00
|
|
|
make_test(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest)
|
2018-08-29 11:57:44 +00:00
|
|
|
endif()
|