cmOptionCommand.cxx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. for(size_t i =0; i < args.size(); ++i)
  35. {
  36. m += args[i];
  37. m += " ";
  38. }
  39. this->SetError(m.c_str());
  40. return false;
  41. }
  42. std::string initialValue = "Off";
  43. // Now check and see if the value has been stored in the cache
  44. // already, if so use that value and don't look for the program
  45. cmCacheManager::CacheIterator it =
  46. this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
  47. if(!it.IsAtEnd())
  48. {
  49. if ( it.GetType() != cmCacheManager::UNINITIALIZED )
  50. {
  51. it.SetProperty("HELPSTRING", args[1].c_str());
  52. return true;
  53. }
  54. if ( it.GetValue() )
  55. {
  56. initialValue = it.GetValue();
  57. }
  58. }
  59. if(args.size() == 3)
  60. {
  61. initialValue = args[2];
  62. }
  63. bool init = cmSystemTools::IsOn(initialValue.c_str());
  64. this->Makefile->AddCacheDefinition(args[0].c_str(), init? "ON":"OFF",
  65. args[1].c_str(), cmCacheManager::BOOL);
  66. return true;
  67. }