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