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

Function cmSetCommand

Source/cmSetCommand.cxx:40–266  ·  view source on GitHub ↗

cmSetCommand

Source from the content-addressed store, hash-verified

38
39// cmSetCommand
40bool cmSetCommand(std::vector<std::string> const& args,
41 cmExecutionStatus& status)
42{
43 if (args.empty()) {
44 status.SetError("called with incorrect number of arguments");
45 return false;
46 }
47
48 auto const& variable = args[0]; // VAR is always first
49 // watch for ENV{} signature
50 if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 5) {
51 // what is the variable name
52 auto const& varName = variable.substr(4, variable.size() - 5);
53
54 // what is the current value if any
55 std::string currValue;
56 bool const currValueSet = cmSystemTools::GetEnv(varName, currValue);
57
58 // will it be set to something, then set it
59 if (args.size() > 1 && !args[1].empty()) {
60 // but only if it is different from current value
61 if (!currValueSet || currValue != args[1]) {
62 setENV(varName, args[1]);
63 }
64 // if there's extra arguments, warn user
65 // that they are ignored by this command.
66 if (args.size() > 2) {
67 std::string m = "Only the first value argument is used when setting "
68 "an environment variable. Argument '" +
69 args[2] + "' and later are unused.";
70 status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, m);
71 }
72 return true;
73 }
74
75 // if it will be cleared, then clear it if it isn't already clear
76 if (currValueSet) {
77 setENV(varName, ""_s);
78 }
79 return true;
80 }
81
82 // watch for CACHE{} signature
83 if (cmHasLiteralPrefix(variable, "CACHE{") && variable.size() > 7 &&
84 cmHasSuffix(variable, '}')) {
85 // what is the variable name
86 auto const& varName = variable.substr(6, variable.size() - 7);
87 // VALUE handling
88 auto valueArg = std::find(args.cbegin() + 1, args.cend(), "VALUE");
89 if (valueArg == args.cend()) {
90 status.SetError("Required argument 'VALUE' is missing.");
91 return false;
92 }
93 auto value = cmMakeRange(valueArg + 1, args.cend());
94 // Handle options
95 struct Arguments : public ArgumentParser::ParseResult
96 {
97 ArgumentParser::Continue validateTypeValue(cm::string_view type)

Callers

nothing calls this directly

Calls 15

cmHasLiteralPrefixFunction · 0.85
setENVFunction · 0.85
cmHasSuffixFunction · 0.85
cmMakeRangeFunction · 0.85
to_stringFunction · 0.85
cbeginMethod · 0.80
cendMethod · 0.80
MaybeReportErrorMethod · 0.80
retreatMethod · 0.80
c_strMethod · 0.80
cmStrCatFunction · 0.70
cmJoinFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…