summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmMakefileTargetGenerator.cxx19
-rw-r--r--Source/cmNinjaTargetGenerator.cxx18
-rw-r--r--Source/cmTarget.cxx2
-rw-r--r--Source/cmcmd.cxx80
4 files changed, 92 insertions, 27 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index eedc6ab..29708d9 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -667,10 +667,23 @@ cmMakefileTargetGenerator
{
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
const char *iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
- if (iwyu && *iwyu)
+ std::string const tidy_prop = lang + "_CLANG_TIDY";
+ const char *tidy = this->GeneratorTarget->GetProperty(tidy_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy))
{
- std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu --iwyu=";
- run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
+ std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu";
+ if (iwyu && *iwyu)
+ {
+ run_iwyu += " --iwyu=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
+ }
+ if (tidy && *tidy)
+ {
+ run_iwyu += " --tidy=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(tidy);
+ run_iwyu += " --source=";
+ run_iwyu += sourceFile;
+ }
run_iwyu += " -- ";
compileCommands.front().insert(0, run_iwyu);
}
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 753a5ae..fd1d16d 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -419,13 +419,25 @@ cmNinjaTargetGenerator
{
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
const char *iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
- if (iwyu && *iwyu)
+ std::string const tidy_prop = lang + "_CLANG_TIDY";
+ const char *tidy = this->GeneratorTarget->GetProperty(tidy_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy))
{
std::string run_iwyu =
this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- run_iwyu += " -E __run_iwyu --iwyu=";
- run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu);
+ run_iwyu += " -E __run_iwyu";
+ if (iwyu && *iwyu)
+ {
+ run_iwyu += " --iwyu=";
+ run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu);
+ }
+ if (tidy && *tidy)
+ {
+ run_iwyu += " --tidy=";
+ run_iwyu += this->GetLocalGenerator()->EscapeForShell(tidy);
+ run_iwyu += " --source=$in";
+ }
run_iwyu += " -- ";
compileCmds.front().insert(0, run_iwyu);
}
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 576189f..e118356 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -142,11 +142,13 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("MACOSX_BUNDLE", 0);
this->SetPropertyDefault("MACOSX_RPATH", 0);
this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
+ this->SetPropertyDefault("C_CLANG_TIDY", 0);
this->SetPropertyDefault("C_COMPILER_LAUNCHER", 0);
this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", 0);
this->SetPropertyDefault("C_STANDARD", 0);
this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
this->SetPropertyDefault("C_EXTENSIONS", 0);
+ this->SetPropertyDefault("CXX_CLANG_TIDY", 0);
this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", 0);
this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", 0);
this->SetPropertyDefault("CXX_STANDARD", 0);
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index e9d77b2..3c28c35 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -297,12 +297,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if (args.size() < 3)
{
std::cerr << "__run_iwyu Usage: -E __run_iwyu [--iwyu=/path/iwyu]"
- " -- compile command\n";
+ " [--tidy=/path/tidy] -- compile command\n";
return 1;
}
bool doing_options = true;
std::vector<std::string> orig_cmd;
std::string iwyu;
+ std::string tidy;
+ std::string sourceFile;
for (std::string::size_type cc = 2; cc < args.size(); cc ++)
{
std::string const& arg = args[cc];
@@ -314,6 +316,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
{
iwyu = arg.substr(7);
}
+ else if (doing_options && cmHasLiteralPrefix(arg, "--tidy="))
+ {
+ tidy = arg.substr(7);
+ }
+ else if (doing_options && cmHasLiteralPrefix(arg, "--source="))
+ {
+ sourceFile = arg.substr(9);
+ }
else if (doing_options)
{
std::cerr << "__run_iwyu given unknown argument: " << arg << "\n";
@@ -324,9 +334,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
orig_cmd.push_back(arg);
}
}
- if (iwyu.empty())
+ if (tidy.empty() && iwyu.empty())
+ {
+ std::cerr << "__run_iwyu missing --tidy= or --iwyu=\n";
+ return 1;
+ }
+ if (!tidy.empty() && sourceFile.empty())
{
- std::cerr << "__run_iwyu missing --iwyu=\n";
+ std::cerr << "__run_iwyu --tidy= requires --source=\n";
return 1;
}
if (orig_cmd.empty())
@@ -335,29 +350,52 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
- // Construct the iwyu command line by taking what was given
- // and adding all the arguments we give to the compiler.
- std::vector<std::string> iwyu_cmd;
- cmSystemTools::ExpandListArgument(iwyu, iwyu_cmd, true);
- iwyu_cmd.insert(iwyu_cmd.end(), orig_cmd.begin()+1, orig_cmd.end());
-
- // Run the iwyu command line. Capture its stderr and hide its stdout.
int ret = 0;
- std::string stdErr;
- if(!cmSystemTools::RunSingleCommand(iwyu_cmd, 0, &stdErr, &ret,
- 0, cmSystemTools::OUTPUT_NONE))
+
+ if (!iwyu.empty())
{
- std::cerr << "Error running '" << iwyu_cmd[0] << "': "
- << stdErr << "\n";
- return 1;
+ // Construct the iwyu command line by taking what was given
+ // and adding all the arguments we give to the compiler.
+ std::vector<std::string> iwyu_cmd;
+ cmSystemTools::ExpandListArgument(iwyu, iwyu_cmd, true);
+ iwyu_cmd.insert(iwyu_cmd.end(), orig_cmd.begin()+1, orig_cmd.end());
+
+ // Run the iwyu command line. Capture its stderr and hide its stdout.
+ std::string stdErr;
+ if(!cmSystemTools::RunSingleCommand(iwyu_cmd, 0, &stdErr, &ret,
+ 0, cmSystemTools::OUTPUT_NONE))
+ {
+ std::cerr << "Error running '" << iwyu_cmd[0] << "': "
+ << stdErr << "\n";
+ return 1;
+ }
+
+ // Warn if iwyu reported anything.
+ if(stdErr.find("should remove these lines:") != stdErr.npos
+ || stdErr.find("should add these lines:") != stdErr.npos)
+ {
+ std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
+ << stdErr << "\n";
+ }
}
- // Warn if iwyu reported anything.
- if(stdErr.find("should remove these lines:") != stdErr.npos
- || stdErr.find("should add these lines:") != stdErr.npos)
+ if (!tidy.empty())
{
- std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
- << stdErr << "\n";
+ // Construct the clang-tidy command line by taking what was given
+ // and adding all the arguments we give to the compiler.
+ std::vector<std::string> tidy_cmd;
+ cmSystemTools::ExpandListArgument(tidy, tidy_cmd, true);
+ tidy_cmd.push_back(sourceFile);
+ tidy_cmd.push_back("--");
+ tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin()+1, orig_cmd.end());
+
+ // Run the tidy command line.
+ if(!cmSystemTools::RunSingleCommand(tidy_cmd, 0, 0, &ret, 0,
+ cmSystemTools::OUTPUT_PASSTHROUGH))
+ {
+ std::cerr << "Error running '" << tidy_cmd[0] << "'\n";
+ return 1;
+ }
}
// Now run the real compiler command and return its result value.