Browse Source

Merge topic 'clang-tidy-for-objc'

1134064e22 clang-tidy: allow OBJC and OBJCXX

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5467
Brad King 5 years ago
parent
commit
ffda92d4bf

+ 2 - 0
Auxiliary/vim/syntax/cmake.vim

@@ -1260,9 +1260,11 @@ syn keyword cmakeVariable contained
             \ CMAKE_NOT_USING_CONFIG_FLAGS
             \ CMAKE_NOT_USING_CONFIG_FLAGS
             \ CMAKE_NO_BUILTIN_CHRPATH
             \ CMAKE_NO_BUILTIN_CHRPATH
             \ CMAKE_NO_SYSTEM_FROM_IMPORTED
             \ CMAKE_NO_SYSTEM_FROM_IMPORTED
+            \ CMAKE_OBJCXX_CLANG_TIDY
             \ CMAKE_OBJCXX_EXTENSIONS
             \ CMAKE_OBJCXX_EXTENSIONS
             \ CMAKE_OBJCXX_STANDARD
             \ CMAKE_OBJCXX_STANDARD
             \ CMAKE_OBJCXX_STANDARD_REQUIRED
             \ CMAKE_OBJCXX_STANDARD_REQUIRED
+            \ CMAKE_OBJC_CLANG_TIDY
             \ CMAKE_OBJC_EXTENSIONS
             \ CMAKE_OBJC_EXTENSIONS
             \ CMAKE_OBJC_STANDARD
             \ CMAKE_OBJC_STANDARD
             \ CMAKE_OBJC_STANDARD_REQUIRED
             \ CMAKE_OBJC_STANDARD_REQUIRED

+ 1 - 1
Help/prop_tgt/LANG_CLANG_TIDY.rst

@@ -3,7 +3,7 @@
 
 
 .. versionadded:: 3.6
 .. versionadded:: 3.6
 
 
-This property is implemented only when ``<LANG>`` is ``C`` or ``CXX``.
+This property is implemented only when ``<LANG>`` is ``C``, ``CXX``, ``OBJC`` or ``OBJCXX``.
 
 
 Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command
 Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command
 line for the ``clang-tidy`` tool.  The :ref:`Makefile Generators`
 line for the ``clang-tidy`` tool.  The :ref:`Makefile Generators`

+ 5 - 0
Help/release/dev/clang-tidy-objc.rst

@@ -0,0 +1,5 @@
+clang-tidy-objc
+---------------
+
+* The target property :prop_tgt:`<LANG>_CLANG_TIDY` and the associated
+  variable :variable:`CMAKE_<LANG>_CLANG_TIDY` learned to support OBJC and OBJCXX.

+ 1 - 1
Help/variable/CMAKE_LANG_CLANG_TIDY.rst

@@ -4,7 +4,7 @@ CMAKE_<LANG>_CLANG_TIDY
 .. versionadded:: 3.6
 .. versionadded:: 3.6
 
 
 Default value for :prop_tgt:`<LANG>_CLANG_TIDY` target property
 Default value for :prop_tgt:`<LANG>_CLANG_TIDY` target property
-when ``<LANG>`` is ``C`` or ``CXX``.
+when ``<LANG>`` is ``C``, ``CXX``, ``OBJC`` or ``OBJCXX``.
 
 
 This variable is used to initialize the property on each target as it is
 This variable is used to initialize the property on each target as it is
 created.  For example:
 created.  For example:

+ 13 - 7
Source/cmMakefileTargetGenerator.cxx

@@ -873,15 +873,21 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
     }
     }
 
 
     // Maybe insert an include-what-you-use runner.
     // Maybe insert an include-what-you-use runner.
-    if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
-      std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
-      cmProp iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
+    if (!compileCommands.empty() &&
+        (lang == "C" || lang == "CXX" || lang == "OBJC" || lang == "OBJCXX")) {
       std::string const tidy_prop = lang + "_CLANG_TIDY";
       std::string const tidy_prop = lang + "_CLANG_TIDY";
       cmProp tidy = this->GeneratorTarget->GetProperty(tidy_prop);
       cmProp tidy = this->GeneratorTarget->GetProperty(tidy_prop);
-      std::string const cpplint_prop = lang + "_CPPLINT";
-      cmProp cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
-      std::string const cppcheck_prop = lang + "_CPPCHECK";
-      cmProp cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+      cmProp iwyu = nullptr;
+      cmProp cpplint = nullptr;
+      cmProp cppcheck = nullptr;
+      if (lang == "C" || lang == "CXX") {
+        std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
+        iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
+        std::string const cpplint_prop = lang + "_CPPLINT";
+        cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
+        std::string const cppcheck_prop = lang + "_CPPCHECK";
+        cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+      }
       if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
       if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
           cmNonempty(cppcheck)) {
           cmNonempty(cppcheck)) {
         std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_co_compile";
         std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_co_compile";

+ 13 - 7
Source/cmNinjaTargetGenerator.cxx

@@ -824,15 +824,21 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
   }
   }
 
 
   // Maybe insert an include-what-you-use runner.
   // Maybe insert an include-what-you-use runner.
-  if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
-    std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
-    cmProp iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
+  if (!compileCmds.empty() &&
+      (lang == "C" || lang == "CXX" || lang == "OBJC" || lang == "OBJCXX")) {
     std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
     std::string const tidy_prop = cmStrCat(lang, "_CLANG_TIDY");
     cmProp tidy = this->GeneratorTarget->GetProperty(tidy_prop);
     cmProp tidy = this->GeneratorTarget->GetProperty(tidy_prop);
-    std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
-    cmProp cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
-    std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
-    cmProp cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+    cmProp iwyu = nullptr;
+    cmProp cpplint = nullptr;
+    cmProp cppcheck = nullptr;
+    if (lang == "C" || lang == "CXX") {
+      std::string const iwyu_prop = cmStrCat(lang, "_INCLUDE_WHAT_YOU_USE");
+      iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
+      std::string const cpplint_prop = cmStrCat(lang, "_CPPLINT");
+      cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
+      std::string const cppcheck_prop = cmStrCat(lang, "_CPPCHECK");
+      cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+    }
     if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
     if (cmNonempty(iwyu) || cmNonempty(tidy) || cmNonempty(cpplint) ||
         cmNonempty(cppcheck)) {
         cmNonempty(cppcheck)) {
       std::string run_iwyu = cmStrCat(cmakeCmd, " -E __run_co_compile");
       std::string run_iwyu = cmStrCat(cmakeCmd, " -E __run_co_compile");

+ 2 - 0
Source/cmTarget.cxx

@@ -372,6 +372,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
     initProp("ISPC_INSTRUCTION_SETS");
     initProp("ISPC_INSTRUCTION_SETS");
     initProp("LINK_SEARCH_START_STATIC");
     initProp("LINK_SEARCH_START_STATIC");
     initProp("LINK_SEARCH_END_STATIC");
     initProp("LINK_SEARCH_END_STATIC");
+    initProp("OBJC_CLANG_TIDY");
+    initProp("OBJCXX_CLANG_TIDY");
     initProp("Swift_LANGUAGE_VERSION");
     initProp("Swift_LANGUAGE_VERSION");
     initProp("Swift_MODULE_DIRECTORY");
     initProp("Swift_MODULE_DIRECTORY");
     initProp("VS_JUST_MY_CODE_DEBUGGING");
     initProp("VS_JUST_MY_CODE_DEBUGGING");

+ 1 - 0
Tests/RunCMake/ClangTidy/OBJC-Build-stdout.txt

@@ -0,0 +1 @@
+Tests[/\]RunCMake[/\]ClangTidy[/\]main\.m:0:0: warning: message \[checker\]

+ 1 - 0
Tests/RunCMake/ClangTidy/OBJC-launch-Build-stdout.txt

@@ -0,0 +1 @@
+Tests[/\]RunCMake[/\]ClangTidy[/\]main\.m:0:0: warning: message \[checker\]

+ 3 - 0
Tests/RunCMake/ClangTidy/OBJC-launch.cmake

@@ -0,0 +1,3 @@
+set(CTEST_USE_LAUNCHERS 1)
+include(CTestUseLaunchers)
+include(OBJC.cmake)

+ 3 - 0
Tests/RunCMake/ClangTidy/OBJC.cmake

@@ -0,0 +1,3 @@
+enable_language(OBJC)
+set(CMAKE_OBJC_CLANG_TIDY "${PSEUDO_TIDY}" -some -args)
+add_executable(main main.m)

+ 1 - 0
Tests/RunCMake/ClangTidy/OBJCXX-Build-stdout.txt

@@ -0,0 +1 @@
+Tests[/\]RunCMake[/\]ClangTidy[/\]main\.mm:0:0: warning: message \[checker\]

+ 1 - 0
Tests/RunCMake/ClangTidy/OBJCXX-launch-Build-stdout.txt

@@ -0,0 +1 @@
+Tests[/\]RunCMake[/\]ClangTidy[/\]main\.mm:0:0: warning: message \[checker\]

+ 3 - 0
Tests/RunCMake/ClangTidy/OBJCXX-launch.cmake

@@ -0,0 +1,3 @@
+set(CTEST_USE_LAUNCHERS 1)
+include(CTestUseLaunchers)
+include(OBJCXX.cmake)

+ 3 - 0
Tests/RunCMake/ClangTidy/OBJCXX.cmake

@@ -0,0 +1,3 @@
+enable_language(OBJCXX)
+set(CMAKE_OBJCXX_CLANG_TIDY "${PSEUDO_TIDY}" -some -args)
+add_executable(main main.mm)

+ 8 - 0
Tests/RunCMake/ClangTidy/RunCMakeTest.cmake

@@ -16,8 +16,16 @@ endfunction()
 
 
 run_tidy(C)
 run_tidy(C)
 run_tidy(CXX)
 run_tidy(CXX)
+if (APPLE)
+  run_tidy(OBJC)
+  run_tidy(OBJCXX)
+endif()
 if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
 if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
   run_tidy(C-launch)
   run_tidy(C-launch)
   run_tidy(CXX-launch)
   run_tidy(CXX-launch)
+  if (APPLE)
+    run_tidy(OBJC-launch)
+    run_tidy(OBJCXX-launch)
+  endif()
 endif()
 endif()
 run_tidy(C-bad)
 run_tidy(C-bad)

+ 4 - 0
Tests/RunCMake/ClangTidy/main.m

@@ -0,0 +1,4 @@
+int main(void)
+{
+  return 0;
+}

+ 4 - 0
Tests/RunCMake/ClangTidy/main.mm

@@ -0,0 +1,4 @@
+int main()
+{
+  return 0;
+}