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

Function cmOptionCommand

Source/cmOptionCommand.cxx:16–91  ·  view source on GitHub ↗

cmOptionCommand

Source from the content-addressed store, hash-verified

14
15// cmOptionCommand
16bool cmOptionCommand(std::vector<std::string> const& args,
17 cmExecutionStatus& status)
18{
19 bool const argError = (args.size() < 2) || (args.size() > 3);
20 if (argError) {
21 std::string m = cmStrCat("called with incorrect number of arguments: ",
22 cmJoin(args, " "));
23 status.SetError(m);
24 return false;
25 }
26
27 // Determine the state of the option policy
28 bool checkAndWarn = false;
29 {
30 auto policyStatus =
31 status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0077);
32 auto const& existsBeforeSet =
33 status.GetMakefile().GetStateSnapshot().GetDefinition(args[0]);
34 switch (policyStatus) {
35 case cmPolicies::WARN:
36 checkAndWarn = (existsBeforeSet != nullptr);
37 CM_FALLTHROUGH;
38 case cmPolicies::OLD:
39 // OLD behavior does not warn.
40 break;
41 case cmPolicies::NEW: {
42 // See if a local variable with this name already exists.
43 // If so we ignore the option command.
44 if (existsBeforeSet) {
45 return true;
46 }
47 } break;
48 }
49 }
50
51 // See if a cache variable with this name already exists
52 // If so just make sure the doc state is correct
53 cmState* state = status.GetMakefile().GetState();
54 cmValue existingValue = state->GetCacheEntryValue(args[0]);
55 if (existingValue &&
56 (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED)) {
57 state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
58 return true;
59 }
60
61 // Nothing in the cache so add it
62 std::string initialValue = existingValue ? *existingValue : "Off";
63 if (args.size() == 3) {
64 initialValue = args[2];
65 }
66 bool init = cmIsOn(initialValue);
67 status.GetMakefile().AddCacheDefinition(args[0], init ? "ON" : "OFF",
68 args[1], cmStateEnums::BOOL);
69 if (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0077) !=
70 cmPolicies::NEW &&
71 status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0126) ==
72 cmPolicies::NEW) {
73 // if there was a definition then remove it

Callers

nothing calls this directly

Calls 15

cmIsOnFunction · 0.85
cmStrCatFunction · 0.70
cmJoinFunction · 0.70
sizeMethod · 0.45
SetErrorMethod · 0.45
GetPolicyStatusMethod · 0.45
GetMakefileMethod · 0.45
GetDefinitionMethod · 0.45
GetStateSnapshotMethod · 0.45
GetStateMethod · 0.45
GetCacheEntryValueMethod · 0.45
GetCacheEntryTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…