packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmOptionCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmOptionCommand.h"
13
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
46   std::string initialValue = "Off";
47   // Now check and see if the value has been stored in the cache
48   // already, if so use that value and don't look for the program
49   cmCacheManager::CacheIterator it =
50     this->Makefile->GetCacheManager()->GetCacheIterator(args[0].c_str());
51   if(!it.IsAtEnd())
52     {
53     if ( it.GetType() != cmCacheManager::UNINITIALIZED )
54       {
55       it.SetProperty("HELPSTRING", args[1].c_str());
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 }