mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
cmCommand refactor: cmUnsetCommand
This commit is contained in:
@@ -161,7 +161,7 @@ void GetScriptingCommands(cmState* state)
|
||||
cm::make_unique<cmSetPropertyCommand>());
|
||||
state->AddBuiltinCommand("site_name", cmSiteNameCommand);
|
||||
state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
|
||||
state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>());
|
||||
state->AddBuiltinCommand("unset", cmUnsetCommand);
|
||||
state->AddBuiltinCommand("while", cmWhileCommand);
|
||||
|
||||
state->AddUnexpectedCommand(
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmUnsetCommand.h"
|
||||
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
|
||||
// cmUnsetCommand
|
||||
bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus&)
|
||||
bool cmUnsetCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty() || args.size() > 2) {
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
status.SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,20 +30,20 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
|
||||
}
|
||||
// unset(VAR)
|
||||
if (args.size() == 1) {
|
||||
this->Makefile->RemoveDefinition(variable);
|
||||
status.GetMakefile().RemoveDefinition(variable);
|
||||
return true;
|
||||
}
|
||||
// unset(VAR CACHE)
|
||||
if ((args.size() == 2) && (args[1] == "CACHE")) {
|
||||
this->Makefile->RemoveCacheDefinition(variable);
|
||||
status.GetMakefile().RemoveCacheDefinition(variable);
|
||||
return true;
|
||||
}
|
||||
// unset(VAR PARENT_SCOPE)
|
||||
if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
|
||||
this->Makefile->RaiseScope(variable, nullptr);
|
||||
status.GetMakefile().RaiseScope(variable, nullptr);
|
||||
return true;
|
||||
}
|
||||
// ERROR: second argument isn't CACHE or PARENT_SCOPE
|
||||
this->SetError("called with an invalid second argument");
|
||||
status.SetError("called with an invalid second argument");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,34 +8,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cm_memory.hxx"
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmExecutionStatus;
|
||||
|
||||
/** \class cmUnsetCommand
|
||||
/**
|
||||
* \brief Unset a CMAKE variable
|
||||
*
|
||||
* cmUnsetCommand unsets or removes a variable.
|
||||
*/
|
||||
class cmUnsetCommand : public cmCommand
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This is a virtual constructor for the command.
|
||||
*/
|
||||
std::unique_ptr<cmCommand> Clone() override
|
||||
{
|
||||
return cm::make_unique<cmUnsetCommand>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
*/
|
||||
bool InitialPass(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status) override;
|
||||
};
|
||||
bool cmUnsetCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user