2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-08-25 18:31:29 +04:00
|
|
|
#include "cmUnsetCommand.h"
|
|
|
|
|
|
|
|
// cmUnsetCommand
|
|
|
|
bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExecutionStatus&)
|
2008-08-25 18:31:29 +04:00
|
|
|
{
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty() || args.size() > 2) {
|
2008-08-25 18:31:29 +04:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
const char* variable = args[0].c_str();
|
|
|
|
|
|
|
|
// unset(ENV{VAR})
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) {
|
2008-08-25 18:31:29 +04:00
|
|
|
// what is the variable name
|
2016-05-16 17:34:04 +03:00
|
|
|
char* envVarName = new char[strlen(variable)];
|
|
|
|
strncpy(envVarName, variable + 4, strlen(variable) - 5);
|
|
|
|
envVarName[strlen(variable) - 5] = '\0';
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
|
|
|
cmSystemTools::UnsetEnv(envVarName);
|
|
|
|
#endif
|
|
|
|
delete[] envVarName;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-25 18:31:29 +04:00
|
|
|
// unset(VAR)
|
2016-09-16 23:45:24 +03:00
|
|
|
if (args.size() == 1) {
|
2008-08-25 18:31:29 +04:00
|
|
|
this->Makefile->RemoveDefinition(variable);
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-25 18:31:29 +04:00
|
|
|
// unset(VAR CACHE)
|
2016-09-16 23:45:24 +03:00
|
|
|
if ((args.size() == 2) && (args[1] == "CACHE")) {
|
2008-08-25 18:31:29 +04:00
|
|
|
this->Makefile->RemoveCacheDefinition(variable);
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-08 16:37:47 +04:00
|
|
|
// unset(VAR PARENT_SCOPE)
|
2016-09-16 23:45:24 +03:00
|
|
|
if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Makefile->RaiseScope(variable, CM_NULLPTR);
|
2013-10-08 16:37:47 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-08 16:37:47 +04:00
|
|
|
// ERROR: second argument isn't CACHE or PARENT_SCOPE
|
2016-09-16 23:45:24 +03:00
|
|
|
this->SetError("called with an invalid second argument");
|
|
|
|
return false;
|
2008-08-25 18:31:29 +04:00
|
|
|
}
|