cmMarkAsAdvancedCommand.cxx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "cmExecutionStatus.h"
  5. #include "cmMakefile.h"
  6. #include "cmState.h"
  7. #include "cmStateTypes.h"
  8. #include "cmSystemTools.h"
  9. #include "cmake.h"
  10. // cmMarkAsAdvancedCommand
  11. bool cmMarkAsAdvancedCommand(std::vector<std::string> const& args,
  12. cmExecutionStatus& status)
  13. {
  14. if (args.empty()) {
  15. status.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 = status.GetMakefile().GetState();
  31. if (!state->GetCacheEntryValue(variable)) {
  32. status.GetMakefile().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. }