-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathStandards.cmake
66 lines (59 loc) · 2 KB
/
Standards.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
include_guard()
function(_set_language_standard output language)
foreach(version IN LISTS ARGN)
if(DEFINED "CMAKE_${language}${version}_STANDARD_COMPILE_OPTION"
OR DEFINED "CMAKE_${language}${version}_EXTENSION_COMPILE_OPTION"
)
set("${output}" "${version}" PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()
# Set the default copmiler standards if not specified
macro(set_standards)
# if the default CMAKE_CXX_STANDARD is not set, detect the latest CXX standard supported by the compiler and use it.
# This is needed for the tools like clang-tidy, cppcheck, etc.
# Like not having compiler warnings on by default, this fixes another `bad` default for the compilers
# If someone needs an older standard like c++11 although their compiler supports c++20, they can override this by passing -D CMAKE_CXX_STANDARD=11.
if("${CMAKE_CXX_STANDARD}" STREQUAL "")
_set_language_standard(
CXX_LATEST_STANDARD
CXX
# 23
20
17
14
11
)
message(
STATUS
"The default CMAKE_CXX_STANDARD used by external targets and tools is not set yet. Using the latest supported C++ standard that is ${CXX_LATEST_STANDARD}"
)
set(CMAKE_CXX_STANDARD ${CXX_LATEST_STANDARD})
endif()
if("${CMAKE_C_STANDARD}" STREQUAL "")
_set_language_standard(
C_LATEST_STANDARD
C
# 23
20
17
11
99
90
)
message(
STATUS
"The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is ${C_LATEST_STANDARD}"
)
set(CMAKE_C_STANDARD ${C_LATEST_STANDARD})
endif()
# strongly encouraged to enable this globally to avoid conflicts between
# -Wpedantic being enabled and -std=c++xx and -std=gnu++xx when compiling with PCH enabled
if("${CMAKE_CXX_EXTENSIONS}" STREQUAL "")
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
if("${CMAKE_C_EXTENSIONS}" STREQUAL "")
set(CMAKE_C_EXTENSIONS OFF)
endif()
endmacro()