Brad King | 86578ec | 2016-09-27 15:01:08 -0400 | [diff] [blame] | 1 | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 2 | file Copyright.txt or https://cmake.org/licensing for details. */ |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 3 | #include "cmMarkAsAdvancedCommand.h" |
| 4 | |
Gabor Bencze | 2b58ae7 | 2019-08-04 18:31:29 +0200 | [diff] [blame] | 5 | #include "cmExecutionStatus.h" |
Daniel Pfeifer | e81c323 | 2016-10-25 20:35:04 +0200 | [diff] [blame] | 6 | #include "cmMakefile.h" |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 7 | #include "cmMessageType.h" |
| 8 | #include "cmPolicies.h" |
Daniel Pfeifer | 608afd4 | 2016-10-19 22:30:58 +0200 | [diff] [blame] | 9 | #include "cmState.h" |
Daniel Pfeifer | e81c323 | 2016-10-25 20:35:04 +0200 | [diff] [blame] | 10 | #include "cmStateTypes.h" |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 11 | #include "cmStringAlgorithms.h" |
Daniel Pfeifer | 608afd4 | 2016-10-19 22:30:58 +0200 | [diff] [blame] | 12 | #include "cmSystemTools.h" |
Marc Chevrier | cc56dc7 | 2021-09-21 17:12:35 +0200 | [diff] [blame] | 13 | #include "cmValue.h" |
Daniel Pfeifer | e81c323 | 2016-10-25 20:35:04 +0200 | [diff] [blame] | 14 | #include "cmake.h" |
| 15 | |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 16 | // cmMarkAsAdvancedCommand |
Gabor Bencze | 2b58ae7 | 2019-08-04 18:31:29 +0200 | [diff] [blame] | 17 | bool cmMarkAsAdvancedCommand(std::vector<std::string> const& args, |
| 18 | cmExecutionStatus& status) |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 19 | { |
Daniel Pfeifer | 73f648f | 2016-09-15 23:59:29 +0200 | [diff] [blame] | 20 | if (args.empty()) { |
Gabor Bencze | 2b58ae7 | 2019-08-04 18:31:29 +0200 | [diff] [blame] | 21 | status.SetError("called with incorrect number of arguments"); |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 22 | return false; |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 23 | } |
Bill Hoffman | 7d76de4 | 2002-03-29 14:20:32 -0500 | [diff] [blame] | 24 | |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 25 | unsigned int i = 0; |
Bill Hoffman | 8e5f3bb | 2001-12-07 15:47:39 -0500 | [diff] [blame] | 26 | const char* value = "1"; |
| 27 | bool overwrite = false; |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 28 | if (args[0] == "CLEAR" || args[0] == "FORCE") { |
Bill Hoffman | 8e5f3bb | 2001-12-07 15:47:39 -0500 | [diff] [blame] | 29 | overwrite = true; |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 30 | if (args[0] == "CLEAR") { |
Bill Hoffman | 8e5f3bb | 2001-12-07 15:47:39 -0500 | [diff] [blame] | 31 | value = "0"; |
Bill Hoffman | 8e5f3bb | 2001-12-07 15:47:39 -0500 | [diff] [blame] | 32 | } |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 33 | i = 1; |
| 34 | } |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 35 | |
| 36 | cmMakefile& mf = status.GetMakefile(); |
| 37 | cmState* state = mf.GetState(); |
| 38 | |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 39 | for (; i < args.size(); ++i) { |
Pavel Solodovnikov | 86dc86d | 2017-05-24 23:18:28 +0300 | [diff] [blame] | 40 | std::string const& variable = args[i]; |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 41 | |
| 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 Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 63 | } |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 64 | |
| 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 Chevrier | 4fc322b | 2023-05-28 16:27:03 +0200 | [diff] [blame] | 86 | variable, cmValue{ nullptr }, cmValue{ nullptr }, |
| 87 | cmStateEnums::UNINITIALIZED); |
Ben Boeckel | 3ec82b7 | 2019-12-19 08:46:50 -0500 | [diff] [blame] | 88 | overwrite = true; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // We need a cache entry to do this. |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 93 | if (!state->GetCacheEntryValue(variable)) { |
Andy Cedilnik | bef93dc | 2002-09-11 14:05:45 -0400 | [diff] [blame] | 94 | cmSystemTools::Error("This should never happen..."); |
| 95 | return false; |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 96 | } |
Kitware Robot | d9fd2f5 | 2016-05-16 10:34:04 -0400 | [diff] [blame] | 97 | if (!state->GetCacheEntryProperty(variable, "ADVANCED") || overwrite) { |
| 98 | state->SetCacheEntryProperty(variable, "ADVANCED", value); |
| 99 | } |
| 100 | } |
Bill Hoffman | eecf4b9 | 2001-11-26 18:28:27 -0500 | [diff] [blame] | 101 | return true; |
| 102 | } |