clang-tidy: allow OBJC and OBJCXX

This commit is contained in:
Andrew Fuller 2020-11-04 20:46:51 -08:00
parent da0a7d28a4
commit 1134064e22
18 changed files with 69 additions and 16 deletions

View File

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

View File

@ -3,7 +3,7 @@
.. 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
line for the ``clang-tidy`` tool. The :ref:`Makefile Generators`

View File

@ -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.

View File

@ -4,7 +4,7 @@ CMAKE_<LANG>_CLANG_TIDY
.. versionadded:: 3.6
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
created. For example:

View File

@ -873,15 +873,21 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
}
// 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";
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) ||
cmNonempty(cppcheck)) {
std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_co_compile";

View File

@ -824,15 +824,21 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
}
// 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");
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) ||
cmNonempty(cppcheck)) {
std::string run_iwyu = cmStrCat(cmakeCmd, " -E __run_co_compile");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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