FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmSetCommand.cxx
blob8f4c522766a9ef461c57f48ab76b6eda9b04af82
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSetCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-04-02 20:42:13 $
7 Version: $Revision: 1.18 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSetCommand.h"
19 // cmSetCommand
20 bool cmSetCommand::InitialPass(std::vector<std::string> const& args)
22 if(args.size() < 1 )
24 this->SetError("called with incorrect number of arguments");
25 return false;
27 // SET (VAR ) // this is a no-op
28 if (args.size() == 1)
30 return true;
32 // here are the options
33 // SET (VAR)
34 // SET (VAR value )
35 // SET (VAR CACHE TYPE "doc String")
36 // SET (VAR value CACHE TYPE "doc string")
38 const char* variable = args[0].c_str(); // VAR is always first
39 std::string value; // optional
40 bool cache = false; // optional
41 cmCacheManager::CacheEntryType type = cmCacheManager::STRING; // required if cache
42 const char* docstring = 0; // required if cache
43 std::string::size_type cacheStart = 0;
45 // check for SET(VAR v1 v2 ... vn)
46 // and create
47 if(args.size() > 2)
49 if(args[1] != "CACHE" && args[2] != "CACHE")
51 value = args[1];
52 for(size_t i =2; i < args.size(); ++i)
54 value += ";";
55 value += args[i];
57 m_Makefile->AddDefinition(variable, value.c_str());
58 return true;
63 if(args.size() == 2)
65 // SET (VAR value )
66 value= args[1];
68 else if(args.size() == 4)
70 // SET (VAR CACHE TYPE "doc String")
71 cache = true;
72 cacheStart = 1;
74 else if(args.size() == 5)
76 // SET (VAR value CACHE TYPE "doc string")
77 cache = true;
78 value = args[1];
79 cacheStart = 2;
81 else
83 std::string message;
84 message += "Syntax error in SET:\n";
85 message += "CACHE requires TYPE and document string SET command:\n";
86 message += "SET (";
87 for(std::vector<std::string>::const_iterator i = args.begin();
88 i != args.end(); ++i)
90 message += *i;
92 message += ")\n";
93 this->SetError(message.c_str());
94 return false;
96 if(cache)
98 if(args[cacheStart] != "CACHE")
100 std::string error = "Error in arguments to cache, expected CACHE found:";
101 error += args[cacheStart];
102 error += "\n";
103 this->SetError(error.c_str());
104 return false;
106 type = cmCacheManager::StringToType(args[cacheStart+1].c_str());
107 docstring = args[cacheStart+2].c_str();
109 // get the current cache value for the variable
110 const char* cacheValue =
111 m_Makefile->GetDefinition(variable);
112 if(cacheValue)
114 // if it is not a cached value, or it is a cached
115 // value that is not internal keep the value found
116 // in the cache
117 if(cache && type != cmCacheManager::INTERNAL)
119 return true;
122 // if it is meant to be in the cache then define it in the cache
123 if(cache)
125 m_Makefile->AddCacheDefinition(variable,
126 value.c_str(),
127 docstring,
128 type);
130 else
132 // add the definition
133 m_Makefile->AddDefinition(variable, value.c_str());
135 return true;