update cmake
This commit is contained in:
parent
ceb23bef6e
commit
9026a202eb
2 changed files with 16 additions and 14 deletions
|
@ -1,18 +1,23 @@
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
set(OPTIONS "")
|
|
||||||
|
|
||||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||||
|
check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG)
|
||||||
|
if(!HAS_CPP17_FLAG)
|
||||||
|
MESSAGE(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support.")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror)
|
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror -std=c++17)
|
||||||
set(OPTIONS ${OPTIONS} -std=c++17)
|
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
set(OPTIONS /W4 /WX)
|
check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG)
|
||||||
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
if(!HAS_CPP17_FLAG)
|
||||||
|
MESSAGE(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(OPTIONS /W4 /WX /std:c++17)
|
||||||
if(HAS_PERMISSIVE_FLAG)
|
if(HAS_PERMISSIVE_FLAG)
|
||||||
set(OPTIONS ${OPTIONS} /permissive-)
|
set(OPTIONS ${OPTIONS} /permissive-)
|
||||||
endif()
|
endif()
|
||||||
set(OPTIONS ${OPTIONS} /std:c++17)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(example
|
add_executable(example
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
set(SOURCES test.cpp)
|
set(SOURCES test.cpp)
|
||||||
|
|
||||||
set(OPTIONS "")
|
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
set(OPTIONS /W4 /WX)
|
set(OPTIONS /W4 /WX)
|
||||||
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
||||||
|
@ -22,7 +20,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||||
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
|
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
function(make_target target std)
|
function(make_test target std)
|
||||||
add_executable(${target} ${SOURCES})
|
add_executable(${target} ${SOURCES})
|
||||||
target_compile_options(${target} PRIVATE ${OPTIONS})
|
target_compile_options(${target} PRIVATE ${OPTIONS})
|
||||||
target_include_directories(${target} PRIVATE 3rdparty/Catch2)
|
target_include_directories(${target} PRIVATE 3rdparty/Catch2)
|
||||||
|
@ -34,14 +32,13 @@ function(make_target target std)
|
||||||
target_compile_options(${target} PRIVATE -std=${std})
|
target_compile_options(${target} PRIVATE -std=${std})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
add_test(NAME ${target} COMMAND ${target})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(HAS_CPP17_FLAG)
|
if(HAS_CPP17_FLAG)
|
||||||
make_target(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
|
make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
|
||||||
add_test(NAME ${CMAKE_PROJECT_NAME}-cpp17.t COMMAND ${CMAKE_PROJECT_NAME}-cpp17.t)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAS_CPPLATEST_FLAG)
|
if(HAS_CPPLATEST_FLAG)
|
||||||
make_target(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest)
|
make_test(${CMAKE_PROJECT_NAME}-cpplatest.t c++latest)
|
||||||
add_test(NAME ${CMAKE_PROJECT_NAME}-cpplatest.t COMMAND ${CMAKE_PROJECT_NAME}-cpplatest.t)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in a new issue