fix cmake

This commit is contained in:
neargye 2019-03-21 11:25:17 +05:00
parent 7c0731598d
commit 7008ed1e37

View file

@ -1,59 +1,32 @@
include_directories(3rdparty/Catch2) include(CheckCXXCompilerFlag)
include_directories(3rdparty/Catch2)
include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include)
set(SOURCES test.cpp) set(SOURCES test.cpp)
set(OPTIONS "") 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") if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS /W4) 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) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11)
set(HAS_CPP17_FLAG TRUE)
set(OPTIONS ${OPTIONS} /permissive-) set(OPTIONS ${OPTIONS} /permissive-)
endif() endif()
set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code
set(HAS_CPP11_FLAG TRUE)
check_cxx_compiler_flag(/std:c++14 HAS_CPP14_FLAG)
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)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -pedantic-errors) set(OPTIONS -Wall -Wextra -pedantic-errors)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") check_cxx_compiler_flag(-std=c++11 HAS_CPP11_FLAG)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.0) check_cxx_compiler_flag(-std=c++14 HAS_CPP14_FLAG)
set(HAS_CPP11_FLAG TRUE) check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG)
endif() check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
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() endif()
function(make_target target std) function(make_target target std)
@ -69,11 +42,7 @@ function(make_target target std)
endfunction() endfunction()
if(HAS_CPP17_FLAG) if(HAS_CPP17_FLAG)
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
make_target(${CMAKE_PROJECT_NAME}-cpp17.t c++1z)
else()
make_target(${CMAKE_PROJECT_NAME}-cpp17.t c++17) make_target(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
endif()
add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t) add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t)
endif() endif()