MCPcopy Create free account
hub / github.com/Kitware/CMake / cmUnsetCommand

Function cmUnsetCommand

Source/cmUnsetCommand.cxx:11–57  ·  view source on GitHub ↗

cmUnsetCommand

Source from the content-addressed store, hash-verified

9
10// cmUnsetCommand
11bool 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(CACHE{VAR})
32 if (cmHasLiteralPrefix(variable, "CACHE{") && variable.size() > 7 &&
33 cmHasSuffix(variable, '}')) {
34 // get the variable name
35 auto const& varName = variable.substr(6, variable.size() - 7);
36 status.GetMakefile().RemoveCacheDefinition(varName);
37 return true;
38 }
39 // unset(VAR)
40 if (args.size() == 1) {
41 status.GetMakefile().RemoveDefinition(variable);
42 return true;
43 }
44 // unset(VAR CACHE)
45 if ((args.size() == 2) && (args[1] == "CACHE")) {
46 status.GetMakefile().RemoveCacheDefinition(variable);
47 return true;
48 }
49 // unset(VAR PARENT_SCOPE)
50 if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
51 status.GetMakefile().RaiseScope(variable, nullptr);
52 return true;
53 }
54 // ERROR: second argument isn't CACHE or PARENT_SCOPE
55 status.SetError("called with an invalid second argument");
56 return false;
57}

Callers

nothing calls this directly

Calls 11

cmHasLiteralPrefixFunction · 0.85
cmHasSuffixFunction · 0.85
c_strMethod · 0.80
RemoveCacheDefinitionMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
SetErrorMethod · 0.45
substrMethod · 0.45
GetMakefileMethod · 0.45
RemoveDefinitionMethod · 0.45
RaiseScopeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…