cmOptionCommand.cxx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmOptionCommand.h"
  14. // cmOptionCommand
  15. bool cmOptionCommand
  16. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  17. {
  18. bool argError = false;
  19. if(args.size() < 2)
  20. {
  21. argError = true;
  22. }
  23. // for VTK 4.0 we have to support the option command with more than 3
  24. // arguments if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if
  25. // CMAKE_MINIMUM_REQUIRED_VERSION is defined, then we can have stricter
  26. // checking.
  27. if(this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
  28. {
  29. if(args.size() > 3)
  30. {
  31. argError = true;
  32. }
  33. }
  34. if(argError)
  35. {
  36. std::string m = "called with incorrect number of arguments: ";
  37. for(size_t i =0; i < args.size(); ++i)
  38. {
  39. m += args[i];
  40. m += " ";
  41. }
  42. this->SetError(m.c_str());
  43. return false;
  44. }
  45. std::string initialValue = "Off";
  46. // Now check and see if the value has been stored in the cache
  47. // already, if so use that value and don't look for the program
  48. cmCacheManager::CacheIterator it =
  49. this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
  50. if(!it.IsAtEnd())
  51. {
  52. if ( it.GetType() != cmCacheManager::UNINITIALIZED )
  53. {
  54. it.SetProperty("HELPSTRING", args[1].c_str());
  55. return true;
  56. }
  57. if ( it.GetValue() )
  58. {
  59. initialValue = it.GetValue();
  60. }
  61. }
  62. if(args.size() == 3)
  63. {
  64. initialValue = args[2];
  65. }
  66. this->Makefile->AddCacheDefinition(args[0].c_str(), initialValue.c_str(),
  67. args[1].c_str(), cmCacheManager::BOOL);
  68. return true;
  69. }