diff options
author | Brad King <brad.king@kitware.com> | 2011-03-31 17:22:54 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2011-03-31 17:22:54 (GMT) |
commit | 0506e37499929e3c6797328f3dc9b9b46e89aef4 (patch) | |
tree | 3fa6b5c3d65167cc7a47d3e2c1196c4ef004f126 | |
parent | 3c7c1f07a0f0ed208efff80769bf87724f1f9210 (diff) | |
parent | a4335a621eabd74645dfdb6b0c731a6d354fcd30 (diff) | |
download | CMake-0506e37499929e3c6797328f3dc9b9b46e89aef4.zip CMake-0506e37499929e3c6797328f3dc9b9b46e89aef4.tar.gz CMake-0506e37499929e3c6797328f3dc9b9b46e89aef4.tar.bz2 |
Merge topic 'cleanup-unused-variable-check'
a4335a6 Fix unused cache warning after multiple configure iterations
a75ebe3 Refine unused cache variable warning
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmake.cxx | 47 | ||||
-rw-r--r-- | Source/cmake.h | 4 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 2 |
4 files changed, 28 insertions, 27 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d47fb6f..6c8938e 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -903,8 +903,6 @@ void cmGlobalGenerator::Generate() } this->CMakeInstance->UpdateProgress("Generating done", -1); - - this->CMakeInstance->RunCheckForUnusedVariables("generation"); } //---------------------------------------------------------------------------- diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ea8cdfd..4eef7dd 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2346,11 +2346,6 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) std::string oldstartoutputdir = this->GetStartOutputDirectory(); this->SetStartDirectory(this->GetHomeDirectory()); this->SetStartOutputDirectory(this->GetHomeOutputDirectory()); - const bool warncli = this->WarnUnusedCli; - if (!this->ScriptMode) - { - this->WarnUnusedCli = false; - } int ret = this->Configure(); if (ret || this->ScriptMode) { @@ -2372,7 +2367,6 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) #endif return ret; } - this->WarnUnusedCli = warncli; ret = this->Generate(); std::string message = "Build files have been written to: "; message += this->GetHomeOutputDirectory(); @@ -2394,6 +2388,10 @@ int cmake::Generate() return -1; } this->GlobalGenerator->Generate(); + if(this->WarnUnusedCli) + { + this->RunCheckForUnusedVariables(); + } if(cmSystemTools::GetErrorOccuredFlag()) { return -1; @@ -4347,7 +4345,10 @@ void cmake::WatchUnusedCli(const char* var) { #ifdef CMAKE_BUILD_WITH_CMAKE this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this); - this->UsedCliVariables[var] = false; + if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end()) + { + this->UsedCliVariables[var] = false; + } #endif } @@ -4355,27 +4356,29 @@ void cmake::UnwatchUnusedCli(const char* var) { #ifdef CMAKE_BUILD_WITH_CMAKE this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning); - this->UsedCliVariables[var] = true; + this->UsedCliVariables.erase(var); #endif } -void cmake::RunCheckForUnusedVariables(const std::string& reason) const +void cmake::RunCheckForUnusedVariables() { #ifdef CMAKE_BUILD_WITH_CMAKE - if(this->WarnUnusedCli) + bool haveUnused = false; + cmOStringStream msg; + msg << "Manually-specified variables were not used by the project:"; + for(std::map<cmStdString, bool>::const_iterator + it = this->UsedCliVariables.begin(); + it != this->UsedCliVariables.end(); ++it) + { + if(!it->second) { - std::map<std::string, bool>::const_iterator it; - for(it = this->UsedCliVariables.begin(); - it != this->UsedCliVariables.end(); ++it) - { - if(!it->second) - { - std::string message = "CMake Warning: The variable, '" + it->first + - "', specified manually, was not used during the " + reason + - "."; - cmSystemTools::Message(message.c_str()); - } - } + haveUnused = true; + msg << "\n " << it->first; } + } + if(haveUnused) + { + this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace()); + } #endif } diff --git a/Source/cmake.h b/Source/cmake.h index 132a86d..fac86c1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -368,8 +368,8 @@ class cmake void UnwatchUnusedCli(const char* var); void WatchUnusedCli(const char* var); - void RunCheckForUnusedVariables(const std::string& reason) const; protected: + void RunCheckForUnusedVariables(); void InitializeProperties(); int HandleDeleteCacheVariables(const char* var); cmPropertyMap Properties; @@ -467,7 +467,7 @@ private: bool WarnUnused; bool WarnUnusedCli; bool CheckSystemVars; - std::map<std::string, bool> UsedCliVariables; + std::map<cmStdString, bool> UsedCliVariables; std::string CMakeEditCommand; std::string CMakeCommand; std::string CXXEnvironment; diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 016b213..6265f81 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1244,7 +1244,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ --build-project WarnUnusedCliUnused --build-options "-DUNUSED_CLI_VARIABLE=Unused") SET_TESTS_PROPERTIES(WarnUnusedCliUnused PROPERTIES - PASS_REGULAR_EXPRESSION "CMake Warning: The variable, 'UNUSED_CLI_VARIABLE'") + PASS_REGULAR_EXPRESSION "CMake Warning:.*Manually-specified variables were not used by the project:.* UNUSED_CLI_VARIABLE") LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused") ADD_TEST(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND} |