cmOptionCommand.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. this->Makefile->UseCacheDefinition(it);
  53. return true;
  54. }
  55. if ( it.GetValue() )
  56. {
  57. initialValue = it.GetValue();
  58. }
  59. }
  60. if(args.size() == 3)
  61. {
  62. initialValue = args[2];
  63. }
  64. bool init = cmSystemTools::IsOn(initialValue.c_str());
  65. this->Makefile->AddCacheDefinition(args[0].c_str(), init? "ON":"OFF",
  66. args[1].c_str(), cmCacheManager::BOOL);
  67. return true;
  68. }