cmMarkAsAdvancedCommand.cxx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmMarkAsAdvancedCommand.h"
  4. #include "cmMakefile.h"
  5. #include "cmState.h"
  6. #include "cmStateTypes.h"
  7. #include "cmSystemTools.h"
  8. #include "cmake.h"
  9. class cmExecutionStatus;
  10. // cmMarkAsAdvancedCommand
  11. bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& args,
  12. cmExecutionStatus&)
  13. {
  14. if (args.empty()) {
  15. this->SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. unsigned int i = 0;
  19. const char* value = "1";
  20. bool overwrite = false;
  21. if (args[0] == "CLEAR" || args[0] == "FORCE") {
  22. overwrite = true;
  23. if (args[0] == "CLEAR") {
  24. value = "0";
  25. }
  26. i = 1;
  27. }
  28. for (; i < args.size(); ++i) {
  29. std::string const& variable = args[i];
  30. cmState* state = this->Makefile->GetState();
  31. if (!state->GetCacheEntryValue(variable)) {
  32. this->Makefile->GetCMakeInstance()->AddCacheEntry(
  33. variable, nullptr, nullptr, cmStateEnums::UNINITIALIZED);
  34. overwrite = true;
  35. }
  36. if (!state->GetCacheEntryValue(variable)) {
  37. cmSystemTools::Error("This should never happen...");
  38. return false;
  39. }
  40. if (!state->GetCacheEntryProperty(variable, "ADVANCED") || overwrite) {
  41. state->SetCacheEntryProperty(variable, "ADVANCED", value);
  42. }
  43. }
  44. return true;
  45. }