cmOptionCommand.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmOptionCommand.h"
  11. // cmOptionCommand
  12. bool cmOptionCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. bool argError = false;
  16. if(args.size() < 2)
  17. {
  18. argError = true;
  19. }
  20. // for VTK 4.0 we have to support the option command with more than 3
  21. // arguments if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if
  22. // CMAKE_MINIMUM_REQUIRED_VERSION is defined, then we can have stricter
  23. // checking.
  24. if(this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
  25. {
  26. if(args.size() > 3)
  27. {
  28. argError = true;
  29. }
  30. }
  31. if(argError)
  32. {
  33. std::string m = "called with incorrect number of arguments: ";
  34. m += cmJoin(args, " ");
  35. this->SetError(m);
  36. return false;
  37. }
  38. std::string initialValue = "Off";
  39. // Now check and see if the value has been stored in the cache
  40. // already, if so use that value and don't look for the program
  41. cmCacheManager* manager = this->Makefile->GetCacheManager();
  42. const char* existingValue = manager->GetCacheEntryValue(args[0]);
  43. if(existingValue)
  44. {
  45. if (manager->GetCacheEntryType(args[0]) != cmCacheManager::UNINITIALIZED)
  46. {
  47. manager->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
  48. return true;
  49. }
  50. initialValue = existingValue;
  51. }
  52. if(args.size() == 3)
  53. {
  54. initialValue = args[2];
  55. }
  56. bool init = cmSystemTools::IsOn(initialValue.c_str());
  57. this->Makefile->AddCacheDefinition(args[0], init? "ON":"OFF",
  58. args[1].c_str(), cmCacheManager::BOOL);
  59. return true;
  60. }