Rename flags again and use variablewatch for cli

This commit is contained in:
Ben Boeckel 2010-09-01 10:22:08 -04:00
parent 786e2695cb
commit fff9f6d6f7
9 changed files with 48 additions and 39 deletions

View File

@ -121,11 +121,8 @@ CMakeSetupDialog::CMakeSetupDialog()
OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)")); OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
this->WarnUninitializedAction->setCheckable(true); this->WarnUninitializedAction->setCheckable(true);
this->WarnUnusedAction = this->WarnUnusedAction =
OptionsMenu->addAction(tr("&Warn Unused (--warn-unused)")); OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
this->WarnUnusedAction->setCheckable(true); this->WarnUnusedAction->setCheckable(true);
this->WarnUnusedAllAction =
OptionsMenu->addAction(tr("&Warn Unused All (--warn-unused-all)"));
this->WarnUnusedAllAction->setCheckable(true);
QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output")); QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
debugAction->setCheckable(true); debugAction->setCheckable(true);
@ -256,9 +253,6 @@ void CMakeSetupDialog::initialize()
QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)), QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
this->CMakeThread->cmakeInstance(), this->CMakeThread->cmakeInstance(),
SLOT(setWarnUnusedMode(bool))); SLOT(setWarnUnusedMode(bool)));
QObject::connect(this->WarnUnusedAllAction, SIGNAL(triggered(bool)),
this->CMakeThread->cmakeInstance(),
SLOT(setWarnUnusedAllMode(bool)));
if(!this->SourceDirectory->text().isEmpty() || if(!this->SourceDirectory->text().isEmpty() ||
!this->BinaryDirectory->lineEdit()->text().isEmpty()) !this->BinaryDirectory->lineEdit()->text().isEmpty())

View File

@ -95,7 +95,6 @@ protected:
QAction* SuppressDevWarningsAction; QAction* SuppressDevWarningsAction;
QAction* WarnUninitializedAction; QAction* WarnUninitializedAction;
QAction* WarnUnusedAction; QAction* WarnUnusedAction;
QAction* WarnUnusedAllAction;
QAction* InstallForCommandLineAction; QAction* InstallForCommandLineAction;
State CurrentState; State CurrentState;

View File

@ -30,7 +30,6 @@ QCMake::QCMake(QObject* p)
this->SuppressDevWarnings = false; this->SuppressDevWarnings = false;
this->WarnUninitializedMode = false; this->WarnUninitializedMode = false;
this->WarnUnusedMode = false; this->WarnUnusedMode = false;
this->WarnUnusedAllMode = false;
qRegisterMetaType<QCMakeProperty>(); qRegisterMetaType<QCMakeProperty>();
qRegisterMetaType<QCMakePropertyList>(); qRegisterMetaType<QCMakePropertyList>();
@ -170,7 +169,6 @@ void QCMake::configure()
std::cerr << "set warn uninitialized " << this->WarnUninitializedMode << "\n"; std::cerr << "set warn uninitialized " << this->WarnUninitializedMode << "\n";
this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode); this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode); this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode);
this->CMakeInstance->SetDefaultToUsed(!this->WarnUnusedAllMode);
this->CMakeInstance->PreLoadCMakeFiles(); this->CMakeInstance->PreLoadCMakeFiles();
cmSystemTools::ResetErrorOccuredFlag(); cmSystemTools::ResetErrorOccuredFlag();
@ -434,8 +432,3 @@ void QCMake::setWarnUnusedMode(bool value)
{ {
this->WarnUnusedMode = value; this->WarnUnusedMode = value;
} }
void QCMake::setWarnUnusedAllMode(bool value)
{
this->WarnUnusedAllMode = value;
}

View File

@ -92,8 +92,6 @@ public slots:
void setWarnUninitializedMode(bool value); void setWarnUninitializedMode(bool value);
/// set whether to run cmake with warnings about unused variables /// set whether to run cmake with warnings about unused variables
void setWarnUnusedMode(bool value); void setWarnUnusedMode(bool value);
/// set whether to run cmake with warnings about all unused variables
void setWarnUnusedAllMode(bool value);
public: public:
/// get the list of cache properties /// get the list of cache properties

View File

@ -93,7 +93,6 @@ cmMakefile::cmMakefile(): Internal(new Internals)
this->Initialize(); this->Initialize();
this->PreOrder = false; this->PreOrder = false;
this->WarnUnused = false; this->WarnUnused = false;
this->DefaultToUsed = true;
} }
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
@ -137,7 +136,6 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
this->Properties = mf.Properties; this->Properties = mf.Properties;
this->PreOrder = mf.PreOrder; this->PreOrder = mf.PreOrder;
this->WarnUnused = mf.WarnUnused; this->WarnUnused = mf.WarnUnused;
this->DefaultToUsed = mf.DefaultToUsed;
this->ListFileStack = mf.ListFileStack; this->ListFileStack = mf.ListFileStack;
this->Initialize(); this->Initialize();
} }
@ -767,7 +765,6 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
const cmDefinitions& defs = cmDefinitions(); const cmDefinitions& defs = cmDefinitions();
const std::set<cmStdString> globalKeys = defs.LocalKeys(); const std::set<cmStdString> globalKeys = defs.LocalKeys();
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused(); this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
this->DefaultToUsed = this->GetCMakeInstance()->GetDefaultToUsed();
if (this->WarnUnused) if (this->WarnUnused)
{ {
this->Internal->VarUsageStack.push(globalKeys); this->Internal->VarUsageStack.push(globalKeys);
@ -1710,10 +1707,6 @@ void cmMakefile::AddDefinition(const char* name, bool value)
{ {
this->Internal->VarStack.top().Set(name, value? "ON" : "OFF"); this->Internal->VarStack.top().Set(name, value? "ON" : "OFF");
this->Internal->VarInitStack.top().insert(name); this->Internal->VarInitStack.top().insert(name);
if (this->WarnUnused && this->DefaultToUsed)
{
this->Internal->VarUsageStack.top().insert(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch(); cmVariableWatch* vv = this->GetVariableWatch();
if ( vv ) if ( vv )

View File

@ -935,7 +935,6 @@ private:
// Unused variable flags // Unused variable flags
bool WarnUnused; bool WarnUnused;
bool DefaultToUsed;
// stack of list files being read // stack of list files being read
std::deque<cmStdString> ListFileStack; std::deque<cmStdString> ListFileStack;

View File

@ -137,12 +137,19 @@ void cmNeedBackwardsCompatibility(const std::string& variable,
#endif #endif
} }
void cmWarnUnusedCliWarning(const std::string& variable,
int, void* ctx, const char*, const cmMakefile*)
{
cmake* cm = reinterpret_cast<cmake*>(ctx);
cm->MarkCliAsUsed(variable);
}
cmake::cmake() cmake::cmake()
{ {
this->Trace = false; this->Trace = false;
this->WarnUninitialized = false; this->WarnUninitialized = false;
this->WarnUnused = false; this->WarnUnused = false;
this->DefaultToUsed = true; this->WarnUnusedCli = true;
this->SuppressDevWarnings = false; this->SuppressDevWarnings = false;
this->DoSuppressDevWarnings = false; this->DoSuppressDevWarnings = false;
this->DebugOutput = false; this->DebugOutput = false;
@ -193,6 +200,19 @@ cmake::cmake()
cmake::~cmake() cmake::~cmake()
{ {
if(this->WarnUnusedCli)
{
std::map<std::string, bool>::const_iterator it;
for(it = this->UsedCliVariables.begin(); it != this->UsedCliVariables.end(); ++it)
{
if(!it->second)
{
std::string message = "The variable, \"" + it->first + "\", given "
"on the command line was not used within the build.";
cmSystemTools::Message(message.c_str());
}
}
}
delete this->CacheManager; delete this->CacheManager;
delete this->Policies; delete this->Policies;
if (this->GlobalGenerator) if (this->GlobalGenerator)
@ -370,6 +390,11 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
{ {
this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(), this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
"No help, variable specified on the command line.", type); "No help, variable specified on the command line.", type);
if(this->WarnUnusedCli)
{
this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
this->UsedCliVariables[var] = false;
}
} }
else else
{ {
@ -621,16 +646,15 @@ void cmake::SetArgs(const std::vector<std::string>& args)
std::cout << "Warn about uninitialized values.\n"; std::cout << "Warn about uninitialized values.\n";
this->SetWarnUninitialized(true); this->SetWarnUninitialized(true);
} }
else if(arg.find("--warn-unused",0) == 0) else if(arg.find("--warn-unused-vars",0) == 0)
{
std::cout << "Finding unused command line variables.\n";
this->SetWarnUnused(true);
}
else if(arg.find("--warn-unused-all",0) == 0)
{ {
std::cout << "Finding unused variables.\n"; std::cout << "Finding unused variables.\n";
this->SetWarnUnused(true); this->SetWarnUnused(true);
this->SetDefaultToUsed(false); }
else if(arg.find("--warn-unused-cli",0) == 0)
{
std::cout << "Finding unused variables given on the command line.\n";
this->SetWarnUnusedCli(true);
} }
else if(arg.find("-G",0) == 0) else if(arg.find("-G",0) == 0)
{ {
@ -2836,6 +2860,11 @@ const char* cmake::GetCPackCommand()
return this->CPackCommand.c_str(); return this->CPackCommand.c_str();
} }
void cmake::MarkCliAsUsed(const std::string& variable)
{
this->UsedCliVariables[variable] = true;
}
void cmake::GenerateGraphViz(const char* fileName) const void cmake::GenerateGraphViz(const char* fileName) const
{ {
cmGeneratedFileStream str(fileName); cmGeneratedFileStream str(fileName);

View File

@ -310,8 +310,11 @@ class cmake
void SetWarnUninitialized(bool b) { this->WarnUninitialized = b;} void SetWarnUninitialized(bool b) { this->WarnUninitialized = b;}
bool GetWarnUnused() { return this->WarnUnused;} bool GetWarnUnused() { return this->WarnUnused;}
void SetWarnUnused(bool b) { this->WarnUnused = b;} void SetWarnUnused(bool b) { this->WarnUnused = b;}
bool GetDefaultToUsed() { return this->DefaultToUsed;} bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
void SetDefaultToUsed(bool b) { this->DefaultToUsed = b;} void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;}
void MarkCliAsUsed(const std::string& variable);
// Define a property // Define a property
void DefineProperty(const char *name, cmProperty::ScopeType scope, void DefineProperty(const char *name, cmProperty::ScopeType scope,
const char *ShortDescription, const char *ShortDescription,
@ -451,7 +454,8 @@ private:
bool Trace; bool Trace;
bool WarnUninitialized; bool WarnUninitialized;
bool WarnUnused; bool WarnUnused;
bool DefaultToUsed; bool WarnUnusedCli;
std::map<std::string, bool> UsedCliVariables;
std::string CMakeEditCommand; std::string CMakeEditCommand;
std::string CMakeCommand; std::string CMakeCommand;
std::string CXXEnvironment; std::string CXXEnvironment;

View File

@ -122,10 +122,10 @@ static const char * cmDocumentationOptions[][3] =
"message(send_error ) calls."}, "message(send_error ) calls."},
{"--warn-uninitialized", "Warn about uninitialized values.", {"--warn-uninitialized", "Warn about uninitialized values.",
"Print a warning when an uninitialized variable is used."}, "Print a warning when an uninitialized variable is used."},
{"--warn-unused", "Warn about unused variables.", {"--warn-unused-all", "Warn about unused variables.",
"Find variables that are declared or set, but not used."},
{"--warn-unused-cli", "Warn about command line options.",
"Find variables that are declared on the command line, but not used."}, "Find variables that are declared on the command line, but not used."},
{"--warn-unused-all", "Warn about all unused variables.",
"Find variables that are declared, but not used."},
{"--help-command cmd [file]", "Print help for a single command and exit.", {"--help-command cmd [file]", "Print help for a single command and exit.",
"Full documentation specific to the given command is displayed. " "Full documentation specific to the given command is displayed. "
"If a file is specified, the documentation is written into and the output " "If a file is specified, the documentation is written into and the output "