Skip to content

Commit ac3576b

Browse files
authored
Merge pull request #78 from cpp-best-practices/c-clangtidy
2 parents 60940e4 + 0517112 commit ac3576b

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/StaticAnalyzers.cmake

+35-8
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,36 @@ endmacro()
5555
macro(enable_clang_tidy)
5656
find_program(CLANGTIDY clang-tidy)
5757
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+
)
6270
AND ${ProjectOptions_ENABLE_PCH})
6371
message(
6472
SEND_ERROR
6573
"clang-tidy cannot be enabled with non-clang compiler and PCH, clang-tidy fails to handle gcc's PCH file")
6674
endif()
75+
6776
# construct the clang-tidy command line
6877
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
7088
if(NOT
7189
"${CMAKE_CXX_STANDARD}"
7290
STREQUAL
@@ -77,10 +95,19 @@ macro(enable_clang_tidy)
7795
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} -extra-arg=-std=c++${CMAKE_CXX_STANDARD})
7896
endif()
7997
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()
83109
endif()
110+
84111
else()
85112
message(${WARNING_MESSAGE} "clang-tidy requested but executable not found")
86113
endif()

0 commit comments

Comments
 (0)