Skip implicit link info for multiple OS X archs
[cmake.git] / Source / cmVisualStudioGeneratorOptions.cxx
blob051cc1fbe75c357235c5a2aaf6dd99d71674dd4d
1 #include "cmVisualStudioGeneratorOptions.h"
2 #include "cmSystemTools.h"
3 #include <cmsys/System.h>
4 #include "cmVisualStudio10TargetGenerator.h"
6 inline std::string cmVisualStudio10GeneratorOptionsEscapeForXML(const char* s)
8 std::string ret = s;
9 cmSystemTools::ReplaceString(ret, "&", "&amp;");
10 cmSystemTools::ReplaceString(ret, "<", "&lt;");
11 cmSystemTools::ReplaceString(ret, ">", "&gt;");
12 return ret;
15 inline std::string cmVisualStudioGeneratorOptionsEscapeForXML(const char* s)
17 std::string ret = s;
18 cmSystemTools::ReplaceString(ret, "&", "&amp;");
19 cmSystemTools::ReplaceString(ret, "\"", "&quot;");
20 cmSystemTools::ReplaceString(ret, "<", "&lt;");
21 cmSystemTools::ReplaceString(ret, ">", "&gt;");
22 cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
23 return ret;
26 //----------------------------------------------------------------------------
27 cmVisualStudioGeneratorOptions
28 ::cmVisualStudioGeneratorOptions(cmLocalGenerator* lg,
29 int version,
30 Tool tool,
31 cmVS7FlagTable const* table,
32 cmVS7FlagTable const* extraTable,
33 cmVisualStudio10TargetGenerator* g):
34 cmIDEOptions(),
35 LocalGenerator(lg), Version(version), CurrentTool(tool),
36 TargetGenerator(g)
38 // Store the given flag tables.
39 cmIDEFlagTable const** ft = this->FlagTable;
40 if(table) { *ft++ = table; }
41 if(extraTable) { *ft++ = extraTable; }
43 // Preprocessor definitions are not allowed for linker tools.
44 this->AllowDefine = (tool != Linker);
46 // Slash options are allowed for VS.
47 this->AllowSlash = true;
50 //----------------------------------------------------------------------------
51 void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault()
53 // Exception handling is on by default because the platform file has
54 // "/EHsc" in the flags. Normally, that will override this
55 // initialization to off, but the user has the option of removing
56 // the flag to disable exception handling. When the user does
57 // remove the flag we need to override the IDE default of on.
58 switch (this->Version)
60 case 7:
61 case 71:
62 this->FlagMap["ExceptionHandling"] = "FALSE";
63 break;
64 case 10:
65 // by default VS puts <ExceptionHandling></ExceptionHandling> empty
66 // for a project, to make our projects look the same put a new line
67 // and space over for the closing </ExceptionHandling> as the default
68 // value
69 this->FlagMap["ExceptionHandling"] = "\n ";
70 break;
71 default:
72 this->FlagMap["ExceptionHandling"] = "0";
73 break;
77 //----------------------------------------------------------------------------
78 void cmVisualStudioGeneratorOptions::SetVerboseMakefile(bool verbose)
80 // If verbose makefiles have been requested and the /nologo option
81 // was not given explicitly in the flags we want to add an attribute
82 // to the generated project to disable logo suppression. Otherwise
83 // the GUI default is to enable suppression.
84 if(verbose &&
85 this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
87 if(this->Version == 10)
89 this->FlagMap["SuppressStartupBanner"] = "false";
91 else
93 this->FlagMap["SuppressStartupBanner"] = "FALSE";
98 bool cmVisualStudioGeneratorOptions::IsDebug()
100 return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
103 //----------------------------------------------------------------------------
104 bool cmVisualStudioGeneratorOptions::UsingUnicode()
106 // Look for the a _UNICODE definition.
107 for(std::vector<std::string>::const_iterator di = this->Defines.begin();
108 di != this->Defines.end(); ++di)
110 if(*di == "_UNICODE")
112 return true;
115 return false;
118 //----------------------------------------------------------------------------
119 void cmVisualStudioGeneratorOptions::Parse(const char* flags)
121 // Parse the input string as a windows command line since the string
122 // is intended for writing directly into the build files.
123 std::vector<std::string> args;
124 cmSystemTools::ParseWindowsCommandLine(flags, args);
126 // Process flags that need to be represented specially in the IDE
127 // project file.
128 for(std::vector<std::string>::iterator ai = args.begin();
129 ai != args.end(); ++ai)
131 this->HandleFlag(ai->c_str());
135 //----------------------------------------------------------------------------
136 void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
138 // This option is not known. Store it in the output flags.
139 this->FlagString += " ";
140 this->FlagString +=
141 cmSystemTools::EscapeWindowsShellArgument(
142 flag,
143 cmsysSystem_Shell_Flag_AllowMakeVariables |
144 cmsysSystem_Shell_Flag_VSIDE);
147 //----------------------------------------------------------------------------
148 void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config)
150 this->Configuration = config;
153 //----------------------------------------------------------------------------
154 void
155 cmVisualStudioGeneratorOptions
156 ::OutputPreprocessorDefinitions(std::ostream& fout,
157 const char* prefix,
158 const char* suffix)
160 if(this->Defines.empty())
162 return;
164 if(this->Version == 10)
166 // if there are configuration specifc flags, then
167 // use the configuration specific tag for PreprocessorDefinitions
168 if(this->Configuration.size())
170 fout << prefix;
171 this->TargetGenerator->WritePlatformConfigTag(
172 "PreprocessorDefinitions",
173 this->Configuration.c_str(),
175 0, 0, &fout);
177 else
179 fout << prefix << "<PreprocessorDefinitions>";
182 else
184 fout << prefix << "PreprocessorDefinitions=\"";
186 const char* comma = "";
187 for(std::vector<std::string>::const_iterator di = this->Defines.begin();
188 di != this->Defines.end(); ++di)
190 // Escape the definition for the compiler.
191 std::string define;
192 if(this->Version != 10)
194 define =
195 this->LocalGenerator->EscapeForShell(di->c_str(), true);
197 else
199 define = *di;
201 // Escape this flag for the IDE.
202 if(this->Version == 10)
204 define = cmVisualStudio10GeneratorOptionsEscapeForXML(define.c_str());
206 else
208 define = cmVisualStudioGeneratorOptionsEscapeForXML(define.c_str());
210 // Store the flag in the project file.
211 fout << comma << define;
212 if(this->Version == 10)
214 comma = ";";
216 else
218 comma = ",";
221 if(this->Version == 10)
223 fout << ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix;
225 else
227 fout << "\"" << suffix;
231 //----------------------------------------------------------------------------
232 void
233 cmVisualStudioGeneratorOptions
234 ::OutputFlagMap(std::ostream& fout, const char* indent)
236 if(this->Version == 10)
238 for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
239 m != this->FlagMap.end(); ++m)
241 fout << indent;
242 if(this->Configuration.size())
244 this->TargetGenerator->WritePlatformConfigTag(
245 m->first.c_str(),
246 this->Configuration.c_str(),
248 0, 0, &fout);
250 else
252 fout << "<" << m->first << ">";
254 fout << m->second << "</" << m->first << ">\n";
257 else
259 for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
260 m != this->FlagMap.end(); ++m)
262 fout << indent << m->first << "=\"" << m->second << "\"\n";
267 //----------------------------------------------------------------------------
268 void
269 cmVisualStudioGeneratorOptions
270 ::OutputAdditionalOptions(std::ostream& fout,
271 const char* prefix,
272 const char* suffix)
274 if(!this->FlagString.empty())
276 if(this->Version == 10)
278 fout << prefix;
279 if(this->Configuration.size())
281 this->TargetGenerator->WritePlatformConfigTag(
282 "AdditionalOptions",
283 this->Configuration.c_str(),
285 0, 0, &fout);
287 else
289 fout << "<AdditionalOptions>";
291 fout << this->FlagString.c_str()
292 << " %(AdditionalOptions)</AdditionalOptions>\n";
294 else
296 fout << prefix << "AdditionalOptions=\"";
297 fout <<
298 cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString.c_str());
299 fout << "\"" << suffix;