cmOptionCommand.cxx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "cmOptionCommand.h"
  4. #include "cmState.h"
  5. #include "cmSystemTools.h"
  6. // cmOptionCommand
  7. bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
  8. cmExecutionStatus&)
  9. {
  10. bool argError = false;
  11. if (args.size() < 2) {
  12. argError = true;
  13. }
  14. // for VTK 4.0 we have to support the option command with more than 3
  15. // arguments if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if
  16. // CMAKE_MINIMUM_REQUIRED_VERSION is defined, then we can have stricter
  17. // checking.
  18. if (this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) {
  19. if (args.size() > 3) {
  20. argError = true;
  21. }
  22. }
  23. if (argError) {
  24. std::string m = "called with incorrect number of arguments: ";
  25. m += cmJoin(args, " ");
  26. this->SetError(m);
  27. return false;
  28. }
  29. std::string initialValue = "Off";
  30. // Now check and see if the value has been stored in the cache
  31. // already, if so use that value and don't look for the program
  32. cmState* state = this->Makefile->GetState();
  33. const char* existingValue = state->GetCacheEntryValue(args[0]);
  34. if (existingValue) {
  35. if (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED) {
  36. state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
  37. return true;
  38. }
  39. initialValue = existingValue;
  40. }
  41. if (args.size() == 3) {
  42. initialValue = args[2];
  43. }
  44. bool init = cmSystemTools::IsOn(initialValue.c_str());
  45. this->Makefile->AddCacheDefinition(args[0], init ? "ON" : "OFF",
  46. args[1].c_str(), cmStateEnums::BOOL);
  47. return true;
  48. }