Selaa lähdekoodia

Merge topic 'clang-tidy-driver-mode'

f6f4eb0907 clang-tidy: Add driver mode argument

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4208
Brad King 5 vuotta sitten
vanhempi
sitoutus
193352e420

+ 4 - 0
Modules/Compiler/Clang-C.cmake

@@ -6,6 +6,10 @@ if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
   return()
 endif()
 
+if("x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
+  set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl")
+endif()
+
 if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
   if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
     set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")

+ 3 - 0
Modules/Compiler/Clang-CXX.cmake

@@ -10,6 +10,9 @@ if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
   return()
 endif()
 
+if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
+  set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl")
+endif()
 
 if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
   if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)

+ 2 - 0
Modules/Compiler/Intel-C.cmake

@@ -9,6 +9,8 @@ set(CMAKE_DEPFILE_FLAGS_C "-MD -MT <OBJECT> -MF <DEPFILE>")
 
 if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
 
+  set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl")
+
   if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 16.0.0)
     set(CMAKE_C11_STANDARD_COMPILE_OPTION "-Qstd=c11")
     set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-Qstd=c11")

+ 2 - 0
Modules/Compiler/Intel-CXX.cmake

@@ -9,6 +9,8 @@ set(CMAKE_DEPFILE_FLAGS_CXX "-MD -MT <OBJECT> -MF <DEPFILE>")
 
 if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
 
+  set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl")
+
   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.0)
     set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-Qstd=c++17")
     set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-Qstd=c++17")

+ 2 - 0
Modules/Compiler/MSVC-C.cmake

@@ -11,6 +11,8 @@ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "")
 # There is no meaningful default for this
 set(CMAKE_C_STANDARD_DEFAULT "")
 
+set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl")
+
 # There are no C compiler modes so we hard-code the known compiler supported
 # features. Override the default macro for this special case.  Pretend that
 # all language standards are available so that at least compilation

+ 2 - 0
Modules/Compiler/MSVC-CXX.cmake

@@ -3,6 +3,8 @@
 
 include(Compiler/CMakeCommonCompilerMacros)
 
+set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl")
+
 if ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0.24215.1 AND
      CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR
    CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10.25017)

+ 7 - 1
Source/cmMakefileTargetGenerator.cxx

@@ -782,7 +782,13 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
         }
         if (tidy && *tidy) {
           run_iwyu += " --tidy=";
-          run_iwyu += this->LocalGenerator->EscapeForShell(tidy);
+          const char* driverMode = this->Makefile->GetDefinition(
+            "CMAKE_" + lang + "_CLANG_TIDY_DRIVER_MODE");
+          if (!(driverMode && *driverMode)) {
+            driverMode = lang == "C" ? "gcc" : "g++";
+          }
+          run_iwyu += this->LocalGenerator->EscapeForShell(
+            cmStrCat(tidy, ";--driver-mode=", driverMode));
         }
         if (cpplint && *cpplint) {
           run_iwyu += " --cpplint=";

+ 7 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -761,7 +761,13 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
       }
       if (tidy && *tidy) {
         run_iwyu += " --tidy=";
-        run_iwyu += this->GetLocalGenerator()->EscapeForShell(tidy);
+        const char* driverMode = this->Makefile->GetDefinition(
+          "CMAKE_" + lang + "_CLANG_TIDY_DRIVER_MODE");
+        if (!(driverMode && *driverMode)) {
+          driverMode = lang == "C" ? "gcc" : "g++";
+        }
+        run_iwyu += this->GetLocalGenerator()->EscapeForShell(
+          cmStrCat(tidy, ";--driver-mode=", driverMode));
       }
       if (cpplint && *cpplint) {
         run_iwyu += " --cpplint=";