diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2010-09-01 15:24:20 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2010-09-01 17:09:08 (GMT) |
commit | 74997000c89ee3a82d68e4107d4a4264e7e57229 (patch) | |
tree | 2551f29fd89495df47cec7bbded5efaa6e074239 /Source | |
parent | fff9f6d6f74aa92d0bc4adf3a80a25b1b662458d (diff) | |
download | CMake-74997000c89ee3a82d68e4107d4a4264e7e57229.zip CMake-74997000c89ee3a82d68e4107d4a4264e7e57229.tar.gz CMake-74997000c89ee3a82d68e4107d4a4264e7e57229.tar.bz2 |
Add a flag to warn about system files
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCommandArgumentParserHelper.cxx | 14 | ||||
-rw-r--r-- | Source/cmCommandArgumentParserHelper.h | 1 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 14 | ||||
-rw-r--r-- | Source/cmMakefile.h | 1 | ||||
-rw-r--r-- | Source/cmake.cxx | 6 | ||||
-rw-r--r-- | Source/cmake.h | 3 |
6 files changed, 32 insertions, 7 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 1460e5d..e9381d4 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -21,6 +21,7 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner ); cmCommandArgumentParserHelper::cmCommandArgumentParserHelper() { this->WarnUninitialized = false; + this->CheckSystemVars = false; this->FileLine = -1; this->FileName = 0; this->RemoveEmpty = true; @@ -129,10 +130,14 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) // not been "cleared"/initialized with a set(foo ) call if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var)) { - cmOStringStream msg; - msg << this->FileName << ":" << this->FileLine << ":" << - " warning: uninitialized variable \'" << var << "\'"; - cmSystemTools::Message(msg.str().c_str()); + const char* root = this->Makefile->GetDefinition("CMAKE_ROOT"); + if (this->CheckSystemVars || strstr(this->FileName, root) != this->FileName) + { + cmOStringStream msg; + msg << this->FileName << ":" << this->FileLine << ":" << + " warning: uninitialized variable \'" << var << "\'"; + cmSystemTools::Message(msg.str().c_str()); + } } return 0; } @@ -331,6 +336,7 @@ void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf) { this->Makefile = mf; this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized(); + this->CheckSystemVars = mf->GetCMakeInstance()->GetCheckSystemVars(); } void cmCommandArgumentParserHelper::SetResult(const char* value) diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h index 1df0042..a211e95 100644 --- a/Source/cmCommandArgumentParserHelper.h +++ b/Source/cmCommandArgumentParserHelper.h @@ -97,6 +97,7 @@ private: std::string Result; const char* FileName; bool WarnUninitialized; + bool CheckSystemVars; long FileLine; bool EscapeQuotes; std::string ErrorString; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 242900e..3a23590 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -93,6 +93,7 @@ cmMakefile::cmMakefile(): Internal(new Internals) this->Initialize(); this->PreOrder = false; this->WarnUnused = false; + this->CheckSystemVars = false; } cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) @@ -136,6 +137,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) this->Properties = mf.Properties; this->PreOrder = mf.PreOrder; this->WarnUnused = mf.WarnUnused; + this->CheckSystemVars = mf.CheckSystemVars; this->ListFileStack = mf.ListFileStack; this->Initialize(); } @@ -774,6 +776,7 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg) this->Internal->VarUsageStack.push(std::set<cmStdString>()); } } + this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars(); } bool cmMakefile::NeedBackwardsCompatibility(unsigned int major, @@ -3386,9 +3389,14 @@ void cmMakefile::PopScope() init.erase(*it); if (this->WarnUnused && usage.find(*it) == usage.end()) { - cmOStringStream m; - m << "unused variable \'" << *it << "\'"; - this->IssueMessage(cmake::AUTHOR_WARNING, m.str()); + const char* cdir = this->ListFileStack.back().c_str(); + const char* root = this->GetDefinition("CMAKE_ROOT"); + if (this->CheckSystemVars || strstr(cdir, root) != cdir) + { + cmOStringStream m; + m << "unused variable \'" << *it << "\'"; + this->IssueMessage(cmake::AUTHOR_WARNING, m.str()); + } } else { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 4ce3b9b..f1ad54d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -935,6 +935,7 @@ private: // Unused variable flags bool WarnUnused; + bool CheckSystemVars; // stack of list files being read std::deque<cmStdString> ListFileStack; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 93ca9e3..27bfbee 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -150,6 +150,7 @@ cmake::cmake() this->WarnUninitialized = false; this->WarnUnused = false; this->WarnUnusedCli = true; + this->CheckSystemVars = false; this->SuppressDevWarnings = false; this->DoSuppressDevWarnings = false; this->DebugOutput = false; @@ -656,6 +657,11 @@ void cmake::SetArgs(const std::vector<std::string>& args) std::cout << "Finding unused variables given on the command line.\n"; this->SetWarnUnusedCli(true); } + else if(arg.find("--check-system-vars",0) == 0) + { + std::cout << "Also check system files when warning about unused and uninitialized variables.\n"; + this->SetCheckSystemVars(true); + } else if(arg.find("-G",0) == 0) { std::string value = arg.substr(2); diff --git a/Source/cmake.h b/Source/cmake.h index 7f7546a..403809f 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -312,6 +312,8 @@ class cmake void SetWarnUnused(bool b) { this->WarnUnused = b;} bool GetWarnUnusedCli() { return this->WarnUnusedCli;} void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;} + bool GetCheckSystemVars() { return this->CheckSystemVars;} + void SetCheckSystemVars(bool b) { this->CheckSystemVars = b;} void MarkCliAsUsed(const std::string& variable); @@ -455,6 +457,7 @@ private: bool WarnUninitialized; bool WarnUnused; bool WarnUnusedCli; + bool CheckSystemVars; std::map<std::string, bool> UsedCliVariables; std::string CMakeEditCommand; std::string CMakeCommand; |