Skip to content

Commit

Permalink
feat: C++17 #4235
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Nov 3, 2023
1 parent 5e6bb8e commit a7a6f86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ endif()
# Setup C/C++ compiler options
#################################################################################

# C++11/14 compiler flags
# C++11/17 compiler flags
include(CXX1x)
check_for_cxx14_compiler(CXX14_COMPILER)
check_for_cxx17_compiler(CXX17_COMPILER)

# If a C++14 compiler is available, then set the appropriate flags
if(CXX14_COMPILER)
set(CMAKE_CXX_STANDARD 14)
# If a C++17 compiler is available, then set the appropriate flags
if(CXX17_COMPILER)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
message(FATAL_ERROR "Compiler does not support C++14.")
message(FATAL_ERROR "Compiler does not support C++17.")
endif()

if(NOT CMAKE_BUILD_TYPE)
Expand Down
18 changes: 9 additions & 9 deletions cmake/CXX1x.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Determines whether the compiler supports C++11
macro(check_for_cxx11_compiler _VAR)
message(STATUS "Checking for C++11 compiler")
message(STATUS "Checking for C++11 compiler ...")
set(${_VAR})
try_compile(_COMPILER_TEST_RESULT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/test_compiler.cpp CMAKE_FLAGS -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
if(NOT _COMPILER_TEST_RESULT AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand All @@ -43,17 +43,17 @@ macro(check_for_cxx11_compiler _VAR)
endif()
endmacro()

# Determines whether the compiler supports C++14
macro(check_for_cxx14_compiler _VAR)
message(STATUS "Checking for C++14 compiler")
# Determines whether the compiler supports C++17
macro(check_for_cxx17_compiler _VAR)
message(STATUS "Checking for C++17 compiler")
set(${_VAR})
try_compile(_COMPILER_TEST_RESULT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/test_compiler.cpp CMAKE_FLAGS -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
try_compile(_COMPILER_TEST_RESULT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/test_compiler.cpp CMAKE_FLAGS -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
if(NOT _COMPILER_TEST_RESULT AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
try_compile(_COMPILER_TEST_RESULT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/test_compiler.cpp CMAKE_FLAGS -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
try_compile(_COMPILER_TEST_RESULT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/test_compiler.cpp CMAKE_FLAGS -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON)
if(_COMPILER_TEST_RESULT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else()
message(STATUS "To enable C++14 install libc++ standard library from https://libcxx.llvm.org/")
message(STATUS "To enable C++17 install libc++ standard library from https://libcxx.llvm.org/")
endif()
endif()
if(_COMPILER_TEST_RESULT AND ((MSVC AND (MSVC14)) OR
Expand All @@ -62,8 +62,8 @@ macro(check_for_cxx14_compiler _VAR)
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.4) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")))
set(${_VAR} 1)
message(STATUS "Checking for C++14 compiler - available")
message(STATUS "Checking for C++17 compiler - available")
else()
message(STATUS "Checking for C++14 compiler - unavailable")
message(STATUS "Checking for C++17 compiler - unavailable")
endif()
endmacro()

0 comments on commit a7a6f86

Please sign in to comment.