cmOptionCommand.cxx 2.3 KB

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