Skip to content

Commit

Permalink
Check support for C++17 in a platform-agnostic manner
Browse files Browse the repository at this point in the history
  • Loading branch information
samangh authored and quicknir committed Feb 25, 2021
1 parent 6450f9c commit 703b7f4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ enable_testing()

include(CheckCXXSourceCompiles)

# report an updated value for recent C++ language standards support. By
# default, Visual Studio always returns the value "199711L" for the
# __cplusplus preprocessor macro.
if(MSVC)
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
endif()

set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS -std=c++17)
if(MSVC)
set(CMAKE_REQUIRED_FLAGS /std:c++17)
else()
set(CMAKE_REQUIRED_FLAGS -std=c++17)
endif()

check_cxx_source_compiles("
#include <string_view>
#include <type_traits>
int main() { return std::is_same_v<std::string_view, int>; }" CAN_COMPILE_17)

set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")

if (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake)
Expand All @@ -22,7 +35,7 @@ find_package(Catch2 REQUIRED)
if (CAN_COMPILE_17)
add_executable(wise_enum_test test_main.cpp cxx17.cpp)
target_compile_features(wise_enum_test PRIVATE cxx_std_17)
target_include_directories(wise_enum_test PRIVATE ..)
target_include_directories(wise_enum_test PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..)
else ()
add_executable(wise_enum_test test_main.cpp)
endif ()
Expand All @@ -31,7 +44,7 @@ target_link_libraries(wise_enum_test PRIVATE Catch2::Catch2)
add_executable(wise_enum_test14 test_main.cpp cxx14.cpp)
target_compile_features(wise_enum_test14 PRIVATE cxx_std_14)
target_link_libraries(wise_enum_test14 PRIVATE Catch2::Catch2)
target_include_directories(wise_enum_test14 PRIVATE ..)
target_include_directories(wise_enum_test14 PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..)

add_test(NAME wise_enum.unit_tests COMMAND wise_enum_test)
add_test(NAME wise_enum.unit_tests14 COMMAND wise_enum_test14)

0 comments on commit 703b7f4

Please sign in to comment.