summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorJamie Snape <jamie.snape@kitware.com>2017-01-23 19:47:13 (GMT)
committerJamie Snape <jamie.snape@kitware.com>2017-01-23 19:47:13 (GMT)
commit0618ddf6b1da3a886f12b6ad2b19da49b2f87e28 (patch)
treeadb7c502f13bd571ff192e644de923f195b8fc81 /Source
parent7b4514fb33cf256ef165b2b28ba4affd1930a957 (diff)
downloadCMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.zip
CMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.tar.gz
CMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.tar.bz2
Add properties to run the cpplint style checker with the compiler
Create a `<LANG>_CPPLINT` target property (initialized by a `CMAKE_<LANG>_CPPLINT` variable) to specify a `cpplint` style checker command line to be run along with the compiler.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmMakefileTargetGenerator.cxx10
-rw-r--r--Source/cmNinjaTargetGenerator.cxx10
-rw-r--r--Source/cmTarget.cxx2
-rw-r--r--Source/cmcmd.cxx42
4 files changed, 57 insertions, 7 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 379ae16..866c132 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -631,7 +631,9 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
std::string const tidy_prop = lang + "_CLANG_TIDY";
const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
- if ((iwyu && *iwyu) || (tidy && *tidy)) {
+ std::string const cpplint_prop = lang + "_CPPLINT";
+ const char* cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint)) {
std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu";
if (iwyu && *iwyu) {
run_iwyu += " --iwyu=";
@@ -640,6 +642,12 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
if (tidy && *tidy) {
run_iwyu += " --tidy=";
run_iwyu += this->LocalGenerator->EscapeForShell(tidy);
+ }
+ if (cpplint && *cpplint) {
+ run_iwyu += " --cpplint=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(cpplint);
+ }
+ if ((tidy && *tidy) || (cpplint && *cpplint)) {
run_iwyu += " --source=";
run_iwyu += sourceFile;
}
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 8ad2efe..0b33b19 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -600,7 +600,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
std::string const tidy_prop = lang + "_CLANG_TIDY";
const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
- if ((iwyu && *iwyu) || (tidy && *tidy)) {
+ std::string const cpplint_prop = lang + "_CPPLINT";
+ const char* cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint)) {
std::string run_iwyu = this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
run_iwyu += " -E __run_iwyu";
@@ -611,6 +613,12 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
if (tidy && *tidy) {
run_iwyu += " --tidy=";
run_iwyu += this->GetLocalGenerator()->EscapeForShell(tidy);
+ }
+ if (cpplint && *cpplint) {
+ run_iwyu += " --cpplint=";
+ run_iwyu += this->GetLocalGenerator()->EscapeForShell(cpplint);
+ }
+ if ((tidy && *tidy) || (cpplint && *cpplint)) {
run_iwyu += " --source=$in";
}
run_iwyu += " -- ";
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index d825e5c..8c62c48 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -255,6 +255,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->SetPropertyDefault("MACOSX_RPATH", CM_NULLPTR);
this->SetPropertyDefault("C_CLANG_TIDY", CM_NULLPTR);
this->SetPropertyDefault("C_COMPILER_LAUNCHER", CM_NULLPTR);
+ this->SetPropertyDefault("C_CPPLINT", CM_NULLPTR);
this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
this->SetPropertyDefault("LINK_WHAT_YOU_USE", CM_NULLPTR);
this->SetPropertyDefault("C_STANDARD", CM_NULLPTR);
@@ -262,6 +263,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->SetPropertyDefault("C_EXTENSIONS", CM_NULLPTR);
this->SetPropertyDefault("CXX_CLANG_TIDY", CM_NULLPTR);
this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", CM_NULLPTR);
+ this->SetPropertyDefault("CXX_CPPLINT", CM_NULLPTR);
this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
this->SetPropertyDefault("CXX_STANDARD", CM_NULLPTR);
this->SetPropertyDefault("CXX_STANDARD_REQUIRED", CM_NULLPTR);
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 5b12a75..823b38f 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -276,7 +276,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if (args[1] == "__run_iwyu") {
if (args.size() < 3) {
std::cerr << "__run_iwyu Usage: -E __run_iwyu [--iwyu=/path/iwyu]"
- " [--tidy=/path/tidy] -- compile command\n";
+ " [--cpplint=/path/cpplint] [--tidy=/path/tidy]"
+ " -- compile command\n";
return 1;
}
bool doing_options = true;
@@ -285,6 +286,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::string tidy;
std::string sourceFile;
std::string lwyu;
+ std::string cpplint;
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
std::string const& arg = args[cc];
if (arg == "--") {
@@ -297,6 +299,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
sourceFile = arg.substr(9);
} else if (doing_options && cmHasLiteralPrefix(arg, "--lwyu=")) {
lwyu = arg.substr(7);
+ } else if (doing_options && cmHasLiteralPrefix(arg, "--cpplint=")) {
+ cpplint = arg.substr(10);
} else if (doing_options) {
std::cerr << "__run_iwyu given unknown argument: " << arg << "\n";
return 1;
@@ -304,12 +308,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
orig_cmd.push_back(arg);
}
}
- if (tidy.empty() && iwyu.empty() && lwyu.empty()) {
- std::cerr << "__run_iwyu missing --tidy= or --iwyu=\n";
+ if (tidy.empty() && iwyu.empty() && lwyu.empty() && cpplint.empty()) {
+ std::cerr << "__run_iwyu missing --cpplint=, --iwyu=, --lwyu=, and/or"
+ " --tidy=\n";
return 1;
}
- if (!tidy.empty() && sourceFile.empty()) {
- std::cerr << "__run_iwyu --tidy= requires --source=\n";
+ if ((!cpplint.empty() || !tidy.empty()) && sourceFile.empty()) {
+ std::cerr << "__run_iwyu --cpplint= and/or __run_iwyu --tidy="
+ " require --source=\n";
return 1;
}
if (orig_cmd.empty() && lwyu.empty()) {
@@ -403,6 +409,32 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::cerr << "Warning: " << stdOut;
}
}
+
+ if (!cpplint.empty()) {
+ // Construct the cpplint command line.
+ std::vector<std::string> cpplint_cmd;
+ cmSystemTools::ExpandListArgument(cpplint, cpplint_cmd, true);
+ cpplint_cmd.push_back(sourceFile);
+
+ // Run the cpplint command line. Capture its output.
+ std::string stdOut;
+ if (!cmSystemTools::RunSingleCommand(cpplint_cmd, &stdOut, &stdOut,
+ &ret, CM_NULLPTR,
+ cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << cpplint_cmd[0] << "': " << stdOut
+ << "\n";
+ return 1;
+ }
+
+ // Output the output from cpplint to stderr
+ std::cerr << stdOut;
+
+ // If cpplint exited with an error do the same.
+ if (ret != 0) {
+ return ret;
+ }
+ }
+
ret = 0;
// Now run the real compiler command and return its result value.
if (lwyu.empty() &&