Skip to content

Commit

Permalink
cmake: simplify c++ standard settings
Browse files Browse the repository at this point in the history
c++14 is our new lower bound and default c++ standard.
Use SUBSTRING to calculate CMAKE_CXX_STANDARD rather
than having to special-case each value.
  • Loading branch information
davvid committed Dec 21, 2020
1 parent eb4e474 commit c4c1e48
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ endif()
if (DEFINED ENV{CXXFLAGS_STD})
set(CXXFLAGS_STD $ENV{CXXFLAGS_STD})
else()
set(CXXFLAGS_STD "c++11")
set(CXXFLAGS_STD "c++14")
endif()
if (${CXXFLAGS_STD} STREQUAL "c++17")
set(CMAKE_CXX_STANDARD 17)
elseif (${CXXFLAGS_STD} STREQUAL "c++14")
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 11)
# Transform "c++17" into "17". "-1" means "rest of the string".
if (NOT DEFINED WDAS_CXX_STANDARD)
string(SUBSTRING "${CXXFLAGS_STD}" 3 -1 WDAS_CXX_STANDARD)
endif()

set(CMAKE_CXX_STANDARD "${WDAS_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down

0 comments on commit c4c1e48

Please sign in to comment.