blob: 87421f56ca4cb2858fdfd3d932747502e2f5b042 [file] [log] [blame]
Brad King86578ec2016-09-27 15:01:08 -04001/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
Bill Hoffmaneecf4b92001-11-26 18:28:27 -05003#include "cmMarkAsAdvancedCommand.h"
4
Gabor Bencze2b58ae72019-08-04 18:31:29 +02005#include "cmExecutionStatus.h"
Daniel Pfeifere81c3232016-10-25 20:35:04 +02006#include "cmMakefile.h"
Ben Boeckel3ec82b72019-12-19 08:46:50 -05007#include "cmMessageType.h"
8#include "cmPolicies.h"
Daniel Pfeifer608afd42016-10-19 22:30:58 +02009#include "cmState.h"
Daniel Pfeifere81c3232016-10-25 20:35:04 +020010#include "cmStateTypes.h"
Ben Boeckel3ec82b72019-12-19 08:46:50 -050011#include "cmStringAlgorithms.h"
Daniel Pfeifer608afd42016-10-19 22:30:58 +020012#include "cmSystemTools.h"
Marc Chevriercc56dc72021-09-21 17:12:35 +020013#include "cmValue.h"
Daniel Pfeifere81c3232016-10-25 20:35:04 +020014#include "cmake.h"
15
Bill Hoffmaneecf4b92001-11-26 18:28:27 -050016// cmMarkAsAdvancedCommand
Gabor Bencze2b58ae72019-08-04 18:31:29 +020017bool cmMarkAsAdvancedCommand(std::vector<std::string> const& args,
18 cmExecutionStatus& status)
Bill Hoffmaneecf4b92001-11-26 18:28:27 -050019{
Daniel Pfeifer73f648f2016-09-15 23:59:29 +020020 if (args.empty()) {
Gabor Bencze2b58ae72019-08-04 18:31:29 +020021 status.SetError("called with incorrect number of arguments");
Bill Hoffmaneecf4b92001-11-26 18:28:27 -050022 return false;
Kitware Robotd9fd2f52016-05-16 10:34:04 -040023 }
Bill Hoffman7d76de42002-03-29 14:20:32 -050024
Kitware Robotd9fd2f52016-05-16 10:34:04 -040025 unsigned int i = 0;
Bill Hoffman8e5f3bb2001-12-07 15:47:39 -050026 const char* value = "1";
27 bool overwrite = false;
Kitware Robotd9fd2f52016-05-16 10:34:04 -040028 if (args[0] == "CLEAR" || args[0] == "FORCE") {
Bill Hoffman8e5f3bb2001-12-07 15:47:39 -050029 overwrite = true;
Kitware Robotd9fd2f52016-05-16 10:34:04 -040030 if (args[0] == "CLEAR") {
Bill Hoffman8e5f3bb2001-12-07 15:47:39 -050031 value = "0";
Bill Hoffman8e5f3bb2001-12-07 15:47:39 -050032 }
Kitware Robotd9fd2f52016-05-16 10:34:04 -040033 i = 1;
34 }
Ben Boeckel3ec82b72019-12-19 08:46:50 -050035
36 cmMakefile& mf = status.GetMakefile();
37 cmState* state = mf.GetState();
38
Kitware Robotd9fd2f52016-05-16 10:34:04 -040039 for (; i < args.size(); ++i) {
Pavel Solodovnikov86dc86d2017-05-24 23:18:28 +030040 std::string const& variable = args[i];
Ben Boeckel3ec82b72019-12-19 08:46:50 -050041
42 bool issueMessage = false;
43 bool oldBehavior = false;
44 bool ignoreVariable = false;
45 switch (mf.GetPolicyStatus(cmPolicies::CMP0102)) {
46 case cmPolicies::WARN:
47 if (mf.PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0102")) {
48 if (!state->GetCacheEntryValue(variable)) {
49 issueMessage = true;
50 }
51 }
52 CM_FALLTHROUGH;
53 case cmPolicies::OLD:
54 oldBehavior = true;
55 break;
56 case cmPolicies::NEW:
57 case cmPolicies::REQUIRED_IF_USED:
58 case cmPolicies::REQUIRED_ALWAYS:
59 if (!state->GetCacheEntryValue(variable)) {
60 ignoreVariable = true;
61 }
62 break;
Kitware Robotd9fd2f52016-05-16 10:34:04 -040063 }
Ben Boeckel3ec82b72019-12-19 08:46:50 -050064
65 // First see if we should issue a message about CMP0102
66 if (issueMessage) {
67 std::string err = cmStrCat(
68 "Policy CMP0102 is not set: The variable named \"", variable,
69 "\" is not in the cache. This results in an empty cache entry which "
70 "is no longer created when policy CMP0102 is set to NEW. Run \"cmake "
71 "--help-policy CMP0102\" for policy details. Use the cmake_policy "
72 "command to set the policy and suppress this warning.");
73 mf.IssueMessage(MessageType::AUTHOR_WARNING, err);
74 }
75
76 // If it's not in the cache and we're using the new behavior, nothing to
77 // see here.
78 if (ignoreVariable) {
79 continue;
80 }
81
82 // Check if we want the old behavior of making a dummy cache entry.
83 if (oldBehavior) {
84 if (!state->GetCacheEntryValue(variable)) {
85 status.GetMakefile().GetCMakeInstance()->AddCacheEntry(
Marc Chevrier4fc322b2023-05-28 16:27:03 +020086 variable, cmValue{ nullptr }, cmValue{ nullptr },
87 cmStateEnums::UNINITIALIZED);
Ben Boeckel3ec82b72019-12-19 08:46:50 -050088 overwrite = true;
89 }
90 }
91
92 // We need a cache entry to do this.
Kitware Robotd9fd2f52016-05-16 10:34:04 -040093 if (!state->GetCacheEntryValue(variable)) {
Andy Cedilnikbef93dc2002-09-11 14:05:45 -040094 cmSystemTools::Error("This should never happen...");
95 return false;
Bill Hoffmaneecf4b92001-11-26 18:28:27 -050096 }
Kitware Robotd9fd2f52016-05-16 10:34:04 -040097 if (!state->GetCacheEntryProperty(variable, "ADVANCED") || overwrite) {
98 state->SetCacheEntryProperty(variable, "ADVANCED", value);
99 }
100 }
Bill Hoffmaneecf4b92001-11-26 18:28:27 -0500101 return true;
102}