resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmUnsetCommand.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmUnsetCommand.h"
4
5 #include "cmExecutionStatus.h"
6 #include "cmMakefile.h"
7 #include "cmStringAlgorithms.h"
8 #include "cmSystemTools.h"
9
10 // cmUnsetCommand
11 bool cmUnsetCommand(std::vector<std::string> const& args,
12                     cmExecutionStatus& status)
13 {
14   if (args.empty() || args.size() > 2) {
15     status.SetError("called with incorrect number of arguments");
16     return false;
17   }
18
19   auto const& variable = args[0];
20
21   // unset(ENV{VAR})
22   if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 5) {
23     // what is the variable name
24     auto const& envVarName = variable.substr(4, variable.size() - 5);
25
26 #ifndef CMAKE_BOOTSTRAP
27     cmSystemTools::UnsetEnv(envVarName.c_str());
28 #endif
29     return true;
30   }
31   // unset(VAR)
32   if (args.size() == 1) {
33     status.GetMakefile().RemoveDefinition(variable);
34     return true;
35   }
36   // unset(VAR CACHE)
37   if ((args.size() == 2) && (args[1] == "CACHE")) {
38     status.GetMakefile().RemoveCacheDefinition(variable);
39     return true;
40   }
41   // unset(VAR PARENT_SCOPE)
42   if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
43     status.GetMakefile().RaiseScope(variable, nullptr);
44     return true;
45   }
46   // ERROR: second argument isn't CACHE or PARENT_SCOPE
47   status.SetError("called with an invalid second argument");
48   return false;
49 }