cmOptionCommand.cxx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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::InitialPass(std::vector<std::string> const& args)
  16. {
  17. bool argError = false;
  18. if(args.size() < 2)
  19. {
  20. argError = true;
  21. }
  22. // for VTK 4.0 we have to support the option command with more than 3 arguments
  23. // if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if CMAKE_MINIMUM_REQUIRED_VERSION
  24. // is defined, then we can have stricter checking.
  25. if(m_Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
  26. {
  27. if(args.size() > 3)
  28. {
  29. argError = true;
  30. }
  31. }
  32. if(argError)
  33. {
  34. std::string m = "called with incorrect number of arguments: ";
  35. for(size_t i =0; i < args.size(); ++i)
  36. {
  37. m += args[i];
  38. m += " ";
  39. }
  40. this->SetError(m.c_str());
  41. return false;
  42. }
  43. std::string initialValue = "Off";
  44. // Now check and see if the value has been stored in the cache
  45. // already, if so use that value and don't look for the program
  46. cmCacheManager::CacheIterator it =
  47. m_Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
  48. if(!it.IsAtEnd())
  49. {
  50. if ( it.GetType() != cmCacheManager::UNINITIALIZED )
  51. {
  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. m_Makefile->AddCacheDefinition(args[0].c_str(),
  64. cmSystemTools::IsOn(initialValue.c_str()),
  65. args[1].c_str());
  66. return true;
  67. }