CMake: Set C++20 mode in canonical cmake

Problem:
- Setting `CMAKE_CXX_FLAGS` directly to effect the version of the C++
  standard being used is no longer the recommended best practice.

Solution:
- Set C++20 mode in the compiler by setting `CMAKE_CXX_STANDARD`.
- Force the build system generator not to fallback to the latest
  standard supported by the compiler by enabling
  `CMAKE_CXX_STANDARD_REQUIRED`. This shouldn't ever be a problem
  though since the toolchain is tightly controlled.
- Disable GNU compiler extensions by disabling `CMAKE_CXX_EXTENSIONS`
  to preserve the previous flags.
This commit is contained in:
Lenny Maiorani 2020-12-21 17:47:47 -07:00 committed by Andreas Kling
parent 0316f0627e
commit ded0b5a93c
Notes: sideshowbarker 2024-07-19 00:41:17 +09:00

View file

@ -42,7 +42,11 @@ add_custom_target(check-style
USES_TERMINAL
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -std=c++2a -fdiagnostics-color=always -ftls-model=initial-exec")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -ftls-model=initial-exec")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconcepts")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")