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.
This commit is contained in:
parent
d5d661d2b2
commit
a75ebe3ea4
|
@ -903,8 +903,6 @@ void cmGlobalGenerator::Generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
this->CMakeInstance->UpdateProgress("Generating done", -1);
|
this->CMakeInstance->UpdateProgress("Generating done", -1);
|
||||||
|
|
||||||
this->CMakeInstance->RunCheckForUnusedVariables("generation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -2310,11 +2310,6 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
|
||||||
std::string oldstartoutputdir = this->GetStartOutputDirectory();
|
std::string oldstartoutputdir = this->GetStartOutputDirectory();
|
||||||
this->SetStartDirectory(this->GetHomeDirectory());
|
this->SetStartDirectory(this->GetHomeDirectory());
|
||||||
this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
|
this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
|
||||||
const bool warncli = this->WarnUnusedCli;
|
|
||||||
if (!this->ScriptMode)
|
|
||||||
{
|
|
||||||
this->WarnUnusedCli = false;
|
|
||||||
}
|
|
||||||
int ret = this->Configure();
|
int ret = this->Configure();
|
||||||
if (ret || this->ScriptMode)
|
if (ret || this->ScriptMode)
|
||||||
{
|
{
|
||||||
|
@ -2336,7 +2331,6 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
this->WarnUnusedCli = warncli;
|
|
||||||
ret = this->Generate();
|
ret = this->Generate();
|
||||||
std::string message = "Build files have been written to: ";
|
std::string message = "Build files have been written to: ";
|
||||||
message += this->GetHomeOutputDirectory();
|
message += this->GetHomeOutputDirectory();
|
||||||
|
@ -2358,6 +2352,10 @@ int cmake::Generate()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
this->GlobalGenerator->Generate();
|
this->GlobalGenerator->Generate();
|
||||||
|
if(this->WarnUnusedCli)
|
||||||
|
{
|
||||||
|
this->RunCheckForUnusedVariables();
|
||||||
|
}
|
||||||
if(cmSystemTools::GetErrorOccuredFlag())
|
if(cmSystemTools::GetErrorOccuredFlag())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -4320,23 +4318,25 @@ void cmake::UnwatchUnusedCli(const char* var)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmake::RunCheckForUnusedVariables(const std::string& reason) const
|
void cmake::RunCheckForUnusedVariables()
|
||||||
{
|
{
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#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;
|
haveUnused = true;
|
||||||
for(it = this->UsedCliVariables.begin();
|
msg << "\n " << it->first;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(haveUnused)
|
||||||
|
{
|
||||||
|
this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,8 +368,8 @@ class cmake
|
||||||
|
|
||||||
void UnwatchUnusedCli(const char* var);
|
void UnwatchUnusedCli(const char* var);
|
||||||
void WatchUnusedCli(const char* var);
|
void WatchUnusedCli(const char* var);
|
||||||
void RunCheckForUnusedVariables(const std::string& reason) const;
|
|
||||||
protected:
|
protected:
|
||||||
|
void RunCheckForUnusedVariables();
|
||||||
void InitializeProperties();
|
void InitializeProperties();
|
||||||
int HandleDeleteCacheVariables(const char* var);
|
int HandleDeleteCacheVariables(const char* var);
|
||||||
cmPropertyMap Properties;
|
cmPropertyMap Properties;
|
||||||
|
@ -465,7 +465,7 @@ private:
|
||||||
bool WarnUnused;
|
bool WarnUnused;
|
||||||
bool WarnUnusedCli;
|
bool WarnUnusedCli;
|
||||||
bool CheckSystemVars;
|
bool CheckSystemVars;
|
||||||
std::map<std::string, bool> UsedCliVariables;
|
std::map<cmStdString, bool> UsedCliVariables;
|
||||||
std::string CMakeEditCommand;
|
std::string CMakeEditCommand;
|
||||||
std::string CMakeCommand;
|
std::string CMakeCommand;
|
||||||
std::string CXXEnvironment;
|
std::string CXXEnvironment;
|
||||||
|
|
|
@ -1202,7 +1202,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
|
||||||
--build-project WarnUnusedCliUnused
|
--build-project WarnUnusedCliUnused
|
||||||
--build-options "-DUNUSED_CLI_VARIABLE=Unused")
|
--build-options "-DUNUSED_CLI_VARIABLE=Unused")
|
||||||
SET_TESTS_PROPERTIES(WarnUnusedCliUnused PROPERTIES
|
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")
|
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WarnUnusedCliUnused")
|
||||||
|
|
||||||
ADD_TEST(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND}
|
ADD_TEST(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND}
|
||||||
|
|
Loading…
Reference in New Issue