cmOptionCommand.cxx 1.8 KB

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