1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmIDEOptions.h"
14 #include "cmSystemTools.h"
16 //----------------------------------------------------------------------------
17 cmIDEOptions::cmIDEOptions()
19 this->DoingDefine = false;
20 this->AllowDefine = true;
21 this->AllowSlash = false;
22 for(int i=0; i < FlagTableCount; ++i)
24 this->FlagTable[i] = 0;
28 //----------------------------------------------------------------------------
29 cmIDEOptions::~cmIDEOptions()
33 //----------------------------------------------------------------------------
34 void cmIDEOptions::HandleFlag(const char* flag)
36 // If the last option was -D then this option is the definition.
39 this->DoingDefine = false;
40 this->Defines.push_back(flag);
44 // Look for known arguments.
45 if(flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))
47 // Look for preprocessor definitions.
48 if(this->AllowDefine && flag[1] == 'D')
52 // The next argument will have the definition.
53 this->DoingDefine = true;
57 // Store this definition.
58 this->Defines.push_back(flag+2);
63 // Look through the available flag tables.
64 bool flag_handled = false;
65 for(int i=0; i < FlagTableCount && this->FlagTable[i]; ++i)
67 if(this->CheckFlagTable(this->FlagTable[i], flag, flag_handled))
73 // If any map entry handled the flag we are done.
80 // This option is not known. Store it in the output flags.
81 this->StoreUnknownFlag(flag);
84 //----------------------------------------------------------------------------
85 bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
86 const char* flag, bool& flag_handled)
88 // Look for an entry in the flag table matching this flag.
89 for(cmIDEFlagTable const* entry = table; entry->IDEName; ++entry)
91 bool entry_found = false;
92 if(entry->special & cmIDEFlagTable::UserValue)
94 // This flag table entry accepts a user-specified value. If
95 // the entry specifies UserRequired we must match only if a
96 // non-empty value is given.
97 int n = static_cast<int>(strlen(entry->commandFlag));
98 if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
99 (!(entry->special & cmIDEFlagTable::UserRequired) ||
100 static_cast<int>(strlen(flag+1)) > n))
102 if(entry->special & cmIDEFlagTable::UserIgnored)
104 // Ignore the user-specified value.
105 this->FlagMap[entry->IDEName] = entry->value;
107 else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
109 const char *new_value = flag+1+n;
111 std::map<cmStdString,cmStdString>::iterator itr;
112 itr = this->FlagMap.find(entry->IDEName);
113 if(itr != this->FlagMap.end())
115 // Append to old value (if present) with semicolons;
117 itr->second += new_value;
121 this->FlagMap[entry->IDEName] = new_value;
126 // Use the user-specified value.
127 this->FlagMap[entry->IDEName] = flag+1+n;
132 else if(strcmp(flag+1, entry->commandFlag) == 0)
134 // This flag table entry provides a fixed value.
135 this->FlagMap[entry->IDEName] = entry->value;
139 // If the flag has been handled by an entry not requesting a
140 // search continuation we are done.
141 if(entry_found && !(entry->special & cmIDEFlagTable::Continue))
146 // If the entry was found the flag has been handled.
147 flag_handled = flag_handled || entry_found;
153 //----------------------------------------------------------------------------
154 void cmIDEOptions::AddDefine(const std::string& def)
156 this->Defines.push_back(def);
159 //----------------------------------------------------------------------------
160 void cmIDEOptions::AddDefines(const char* defines)
164 // Expand the list of definitions.
165 cmSystemTools::ExpandListArgument(defines, this->Defines);
168 //----------------------------------------------------------------------------
169 void cmIDEOptions::AddDefines(const std::vector<std::string> &defines)
171 this->Defines.insert(this->Defines.end(), defines.begin(), defines.end());
174 //----------------------------------------------------------------------------
175 void cmIDEOptions::AddFlag(const char* flag, const char* value)
177 this->FlagMap[flag] = value;
180 //----------------------------------------------------------------------------
181 void cmIDEOptions::RemoveFlag(const char* flag)
183 this->FlagMap.erase(flag);
186 //----------------------------------------------------------------------------
187 const char* cmIDEOptions::GetFlag(const char* flag)
189 std::map<cmStdString, cmStdString>::iterator i = this->FlagMap.find(flag);
190 if(i != this->FlagMap.end())
192 return i->second.c_str();