nameof_module/test/CMakeLists.txt
2019-03-20 21:41:51 +05:00

83 lines
2.5 KiB
CMake

include_directories(3rdparty/Catch2)
include_directories(${CMAKE_SOURCE_DIR}/include)
set(SOURCES test.cpp)
set(OPTIONS "")
set(HAS_CPP11_FLAG FALSE)
set(HAS_CPP14_FLAG FALSE)
set(HAS_CPP17_FLAG FALSE)
set(HAS_CPP20_FLAG FALSE)
set(HAS_CPPLATEST_FLAG FALSE)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS /W4)
set(HAS_CPP11_FLAG TRUE)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00)
set(HAS_CPP14_FLAG TRUE)
set(HAS_CPPLATEST_FLAG TRUE)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11)
set(HAS_CPP17_FLAG TRUE)
set(OPTIONS ${OPTIONS} /permissive-)
endif()
set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -pedantic-errors)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.0)
set(HAS_CPP11_FLAG TRUE)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.2)
set(HAS_CPP14_FLAG TRUE)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1.0)
set(HAS_CPP17_FLAG TRUE)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3.0)
set(HAS_CPP11_FLAG TRUE)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4.0)
set(HAS_CPP14_FLAG TRUE)
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0)
set(HAS_CPP17_FLAG TRUE)
endif()
endif()
endif()
function(make_target target std)
add_executable(${target} ${SOURCES})
target_compile_options(${target} PRIVATE ${OPTIONS})
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()
endfunction()
if(HAS_CPP17_FLAG)
set(std17 c++17)
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(std17 c++1z)
endif()
make_target(${CMAKE_PROJECT_NAME}-cpp17.t ${std17})
add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t)
endif()
if(HAS_CPPLATEST_FLAG)
make_target(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest)
add_test(NAME ${CMAKE_PROJECT_NAME}-cpplatest.t COMMAND ${CMAKE_PROJECT_NAME}-cpplatest.t)
endif()