Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmIDEOptions.cxx
blob62852622c28dbc8162f33bbaae493f8872d1231a
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIDEOptions.cxx,v $
5 Language: C++
6 Date: $Date: 2009-07-29 15:29:03 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 "cmIDEOptions.h"
19 #include "cmSystemTools.h"
21 //----------------------------------------------------------------------------
22 cmIDEOptions::cmIDEOptions()
24 this->DoingDefine = false;
25 this->AllowDefine = true;
26 this->AllowSlash = false;
27 for(int i=0; i < FlagTableCount; ++i)
29 this->FlagTable[i] = 0;
33 //----------------------------------------------------------------------------
34 cmIDEOptions::~cmIDEOptions()
38 //----------------------------------------------------------------------------
39 void cmIDEOptions::HandleFlag(const char* flag)
41 // If the last option was -D then this option is the definition.
42 if(this->DoingDefine)
44 this->DoingDefine = false;
45 this->Defines.push_back(flag);
46 return;
49 // Look for known arguments.
50 if(flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))
52 // Look for preprocessor definitions.
53 if(this->AllowDefine && flag[1] == 'D')
55 if(flag[2] == '\0')
57 // The next argument will have the definition.
58 this->DoingDefine = true;
60 else
62 // Store this definition.
63 this->Defines.push_back(flag+2);
65 return;
68 // Look through the available flag tables.
69 bool flag_handled = false;
70 for(int i=0; i < FlagTableCount && this->FlagTable[i]; ++i)
72 if(this->CheckFlagTable(this->FlagTable[i], flag, flag_handled))
74 return;
78 // If any map entry handled the flag we are done.
79 if(flag_handled)
81 return;
85 // This option is not known. Store it in the output flags.
86 this->StoreUnknownFlag(flag);
89 //----------------------------------------------------------------------------
90 bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
91 const char* flag, bool& flag_handled)
93 // Look for an entry in the flag table matching this flag.
94 for(cmIDEFlagTable const* entry = table; entry->IDEName; ++entry)
96 bool entry_found = false;
97 if(entry->special & cmIDEFlagTable::UserValue)
99 // This flag table entry accepts a user-specified value. If
100 // the entry specifies UserRequired we must match only if a
101 // non-empty value is given.
102 int n = static_cast<int>(strlen(entry->commandFlag));
103 if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
104 (!(entry->special & cmIDEFlagTable::UserRequired) ||
105 static_cast<int>(strlen(flag+1)) > n))
107 if(entry->special & cmIDEFlagTable::UserIgnored)
109 // Ignore the user-specified value.
110 this->FlagMap[entry->IDEName] = entry->value;
112 else if(entry->special & cmIDEFlagTable::SemicolonAppendable)
114 const char *new_value = flag+1+n;
116 std::map<cmStdString,cmStdString>::iterator itr;
117 itr = this->FlagMap.find(entry->IDEName);
118 if(itr != this->FlagMap.end())
120 // Append to old value (if present) with semicolons;
121 itr->second += ";";
122 itr->second += new_value;
124 else
126 this->FlagMap[entry->IDEName] = new_value;
129 else
131 // Use the user-specified value.
132 this->FlagMap[entry->IDEName] = flag+1+n;
134 entry_found = true;
137 else if(strcmp(flag+1, entry->commandFlag) == 0)
139 // This flag table entry provides a fixed value.
140 this->FlagMap[entry->IDEName] = entry->value;
141 entry_found = true;
144 // If the flag has been handled by an entry not requesting a
145 // search continuation we are done.
146 if(entry_found && !(entry->special & cmIDEFlagTable::Continue))
148 return true;
151 // If the entry was found the flag has been handled.
152 flag_handled = flag_handled || entry_found;
155 return false;
158 //----------------------------------------------------------------------------
159 void cmIDEOptions::AddDefine(const std::string& def)
161 this->Defines.push_back(def);
164 //----------------------------------------------------------------------------
165 void cmIDEOptions::AddDefines(const char* defines)
167 if(defines)
169 // Expand the list of definitions.
170 cmSystemTools::ExpandListArgument(defines, this->Defines);
174 //----------------------------------------------------------------------------
175 void cmIDEOptions::AddFlag(const char* flag, const char* value)
177 this->FlagMap[flag] = value;