1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSetCommand.cxx,v $
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"
20 bool cmSetCommand::InitialPass(std::vector
<std::string
> const& args
)
24 this->SetError("called with incorrect number of arguments");
27 // SET (VAR ) // this is a no-op
32 // here are the options
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)
49 if(args
[1] != "CACHE" && args
[2] != "CACHE")
52 for(size_t i
=2; i
< args
.size(); ++i
)
57 m_Makefile
->AddDefinition(variable
, value
.c_str());
68 else if(args
.size() == 4)
70 // SET (VAR CACHE TYPE "doc String")
74 else if(args
.size() == 5)
76 // SET (VAR value CACHE TYPE "doc string")
84 message
+= "Syntax error in SET:\n";
85 message
+= "CACHE requires TYPE and document string SET command:\n";
87 for(std::vector
<std::string
>::const_iterator i
= args
.begin();
93 this->SetError(message
.c_str());
98 if(args
[cacheStart
] != "CACHE")
100 std::string error
= "Error in arguments to cache, expected CACHE found:";
101 error
+= args
[cacheStart
];
103 this->SetError(error
.c_str());
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
);
114 // if it is not a cached value, or it is a cached
115 // value that is not internal keep the value found
117 if(cache
&& type
!= cmCacheManager::INTERNAL
)
122 // if it is meant to be in the cache then define it in the cache
125 m_Makefile
->AddCacheDefinition(variable
,
132 // add the definition
133 m_Makefile
->AddDefinition(variable
, value
.c_str());