File tree 1 file changed +35
-8
lines changed
1 file changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -55,18 +55,36 @@ endmacro()
55
55
macro (enable_clang_tidy)
56
56
find_program (CLANGTIDY clang-tidy)
57
57
if (CLANGTIDY)
58
- if (NOT
59
- CMAKE_CXX_COMPILER_ID
60
- MATCHES
61
- ".*Clang"
58
+
59
+ # clang-tidy only works with clang when PCH is enabled
60
+ if ((NOT
61
+ CMAKE_CXX_COMPILER_ID
62
+ MATCHES
63
+ ".*Clang"
64
+ OR (NOT
65
+ CMAKE_C_COMPILER_ID
66
+ MATCHES
67
+ ".*Clang"
68
+ )
69
+ )
62
70
AND ${ProjectOptions_ENABLE_PCH} )
63
71
message (
64
72
SEND_ERROR
65
73
"clang-tidy cannot be enabled with non-clang compiler and PCH, clang-tidy fails to handle gcc's PCH file" )
66
74
endif ()
75
+
67
76
# construct the clang-tidy command line
68
77
set (CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option)
69
- # set standard
78
+
79
+ # set warnings as errors
80
+ if (WARNINGS_AS_ERRORS)
81
+ list (APPEND CMAKE_CXX_CLANG_TIDY -warnings-as-errors=*)
82
+ endif ()
83
+
84
+ # C clang-tidy
85
+ set (CMAKE_C_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} )
86
+
87
+ # set C++ standard
70
88
if (NOT
71
89
"${CMAKE_CXX_STANDARD} "
72
90
STREQUAL
@@ -77,10 +95,19 @@ macro(enable_clang_tidy)
77
95
set (CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -extra-arg=-std=c++${CMAKE_CXX_STANDARD} )
78
96
endif ()
79
97
endif ()
80
- # set warnings as errors
81
- if (WARNINGS_AS_ERRORS)
82
- list (APPEND CMAKE_CXX_CLANG_TIDY -warnings-as-errors=*)
98
+
99
+ # set C standard
100
+ if (NOT
101
+ "${CMAKE_C_STANDARD} "
102
+ STREQUAL
103
+ "" )
104
+ if ("${CMAKE_C_CLANG_TIDY_DRIVER_MODE} " STREQUAL "cl" )
105
+ set (CMAKE_C_CLANG_TIDY ${CMAKE_C_CLANG_TIDY} -extra-arg=/std:c${CMAKE_C_STANDARD} )
106
+ else ()
107
+ set (CMAKE_C_CLANG_TIDY ${CMAKE_C_CLANG_TIDY} -extra-arg=-std=c${CMAKE_C_STANDARD} )
108
+ endif ()
83
109
endif ()
110
+
84
111
else ()
85
112
message (${WARNING_MESSAGE} "clang-tidy requested but executable not found" )
86
113
endif ()
You can’t perform that action at this time.
0 commit comments