summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-03-24 13:24:27 (GMT)
committerBrad King <brad.king@kitware.com>2011-03-24 13:45:33 (GMT)
commita75ebe3ea48c957e3e7b8c1438ceb6136595eb61 (patch)
tree946038ca7600d9066fba3d30518a219d9bf4af7c
parentd5d661d2b259447edfc89d130878f3a9b2203ea1 (diff)
downloadCMake-a75ebe3ea48c957e3e7b8c1438ceb6136595eb61.zip
CMake-a75ebe3ea48c957e3e7b8c1438ceb6136595eb61.tar.gz
CMake-a75ebe3ea48c957e3e7b8c1438ceb6136595eb61.tar.bz2
Refine unused cache variable warning
List all unused variables in one warning. Cleanup implementation to run the check exactly once at the end of generation.
-rw-r--r--Source/cmGlobalGenerator.cxx2
-rw-r--r--Source/cmake.cxx40
-rw-r--r--Source/cmake.h4
-rw-r--r--Tests/CMakeLists.txt2
4 files changed, 23 insertions, 25 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 bab0aaf..221a2f3 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -2310,11 +2310,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)
{
@@ -2336,7 +2331,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();
@@ -2358,6 +2352,10 @@ int cmake::Generate()
return -1;
}
this->GlobalGenerator->Generate();
+ if(this->WarnUnusedCli)
+ {
+ this->RunCheckForUnusedVariables();
+ }
if(cmSystemTools::GetErrorOccuredFlag())
{
return -1;
@@ -4320,23 +4318,25 @@ void cmake::UnwatchUnusedCli(const char* 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 1bb42d3..00fba57 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;
@@ -465,7 +465,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 2c11919..9fdc9f9 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1202,7 +1202,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}