Skip to content

Commit

Permalink
update cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye committed Oct 19, 2019
1 parent 017aa08 commit ff28127
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
21 changes: 5 additions & 16 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
include(CheckCXXCompilerFlag)

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(OPTIONS -Wall -Wextra -pedantic-errors -Werror -std=c++17)
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
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(OPTIONS /W4 /WX /std:c++17)
set(OPTIONS /W4 /WX)
if(HAS_PERMISSIVE_FLAG)
set(OPTIONS ${OPTIONS} /permissive-)
endif()
endif()

add_executable(example
example.cpp
${CMAKE_SOURCE_DIR}/include/${CMAKE_PROJECT_NAME}.hpp)
add_executable(example example.cpp)
set_target_properties(example PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(example PRIVATE cxx_std_17)
target_compile_options(example PRIVATE ${OPTIONS})
target_link_libraries(example PRIVATE ${CMAKE_PROJECT_NAME})
9 changes: 5 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS ${OPTIONS} /permissive-)
endif()

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")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -pedantic-errors -Werror)

check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG)
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
endif()

Expand All @@ -25,6 +23,7 @@ function(make_test target std)
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})
Expand All @@ -35,8 +34,10 @@ function(make_test target std)
add_test(NAME ${target} COMMAND ${target})
endfunction()

if(HAS_CPP17_FLAG)
make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17)
make_test(${CMAKE_PROJECT_NAME}-cpp17.t c++17)

if(HAS_CPP20_FLAG)
make_test(${CMAKE_PROJECT_NAME}-cpp20.t c++20)
endif()

if(HAS_CPPLATEST_FLAG)
Expand Down

0 comments on commit ff28127

Please sign in to comment.