Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmMarkAsAdvancedCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmMarkAsAdvancedCommand.h"
4
5
#include "cmExecutionStatus.h"
6
#include "cmMakefile.h"
7
#include "cmMessageType.h"
8
#include "cmPolicies.h"
9
#include "cmState.h"
10
#include "cmStateTypes.h"
11
#include "cmStringAlgorithms.h"
12
#include "cmSystemTools.h"
13
#include "cmValue.h"
14
#include "cmake.h"
15
16
// cmMarkAsAdvancedCommand
17
bool cmMarkAsAdvancedCommand(std::vector<std::string> const& args,
18
                             cmExecutionStatus& status)
19
0
{
20
0
  if (args.empty()) {
21
0
    status.SetError("called with incorrect number of arguments");
22
0
    return false;
23
0
  }
24
25
0
  unsigned int i = 0;
26
0
  char const* value = "1";
27
0
  bool overwrite = false;
28
0
  if (args[0] == "CLEAR" || args[0] == "FORCE") {
29
0
    overwrite = true;
30
0
    if (args[0] == "CLEAR") {
31
0
      value = "0";
32
0
    }
33
0
    i = 1;
34
0
  }
35
36
0
  cmMakefile& mf = status.GetMakefile();
37
0
  cmState* state = mf.GetState();
38
39
0
  for (; i < args.size(); ++i) {
40
0
    std::string const& variable = args[i];
41
42
0
    bool issueMessage = false;
43
0
    bool oldBehavior = false;
44
0
    bool ignoreVariable = false;
45
0
    switch (mf.GetPolicyStatus(cmPolicies::CMP0102)) {
46
0
      case cmPolicies::WARN:
47
0
        if (mf.PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0102")) {
48
0
          if (!state->GetCacheEntryValue(variable)) {
49
0
            issueMessage = true;
50
0
          }
51
0
        }
52
0
        CM_FALLTHROUGH;
53
0
      case cmPolicies::OLD:
54
0
        oldBehavior = true;
55
0
        break;
56
0
      case cmPolicies::NEW:
57
0
        if (!state->GetCacheEntryValue(variable)) {
58
0
          ignoreVariable = true;
59
0
        }
60
0
        break;
61
0
    }
62
63
    // First see if we should issue a message about CMP0102
64
0
    if (issueMessage) {
65
0
      std::string err = cmStrCat(
66
0
        "Policy CMP0102 is not set: The variable named \"", variable,
67
0
        "\" is not in the cache. This results in an empty cache entry which "
68
0
        "is no longer created when policy CMP0102 is set to NEW. Run \"cmake "
69
0
        "--help-policy CMP0102\" for policy details. Use the cmake_policy "
70
0
        "command to set the policy and suppress this warning.");
71
0
      mf.IssueMessage(MessageType::AUTHOR_WARNING, err);
72
0
    }
73
74
    // If it's not in the cache and we're using the new behavior, nothing to
75
    // see here.
76
0
    if (ignoreVariable) {
77
0
      continue;
78
0
    }
79
80
    // Check if we want the old behavior of making a dummy cache entry.
81
0
    if (oldBehavior) {
82
0
      if (!state->GetCacheEntryValue(variable)) {
83
0
        status.GetMakefile().GetCMakeInstance()->AddCacheEntry(
84
0
          variable, cmValue{ nullptr }, cmValue{ nullptr },
85
0
          cmStateEnums::UNINITIALIZED);
86
0
        overwrite = true;
87
0
      }
88
0
    }
89
90
    // We need a cache entry to do this.
91
0
    if (!state->GetCacheEntryValue(variable)) {
92
0
      cmSystemTools::Error("This should never happen...");
93
0
      return false;
94
0
    }
95
0
    if (!state->GetCacheEntryProperty(variable, "ADVANCED") || overwrite) {
96
0
      state->SetCacheEntryProperty(variable, "ADVANCED", value);
97
0
    }
98
0
  }
99
0
  return true;
100
0
}