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
)
9 cmSystemTools::ReplaceString(ret
, "&", "&");
10 cmSystemTools::ReplaceString(ret
, "<", "<");
11 cmSystemTools::ReplaceString(ret
, ">", ">");
15 inline std::string
cmVisualStudioGeneratorOptionsEscapeForXML(const char* s
)
18 cmSystemTools::ReplaceString(ret
, "&", "&");
19 cmSystemTools::ReplaceString(ret
, "\"", """);
20 cmSystemTools::ReplaceString(ret
, "<", "<");
21 cmSystemTools::ReplaceString(ret
, ">", ">");
22 cmSystemTools::ReplaceString(ret
, "\n", "
");
26 //----------------------------------------------------------------------------
27 cmVisualStudioGeneratorOptions
28 ::cmVisualStudioGeneratorOptions(cmLocalGenerator
* lg
,
31 cmVS7FlagTable
const* table
,
32 cmVS7FlagTable
const* extraTable
,
33 cmVisualStudio10TargetGenerator
* g
):
35 LocalGenerator(lg
), Version(version
), CurrentTool(tool
),
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
)
62 this->FlagMap
["ExceptionHandling"] = "FALSE";
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
69 this->FlagMap
["ExceptionHandling"] = "\n ";
72 this->FlagMap
["ExceptionHandling"] = "0";
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.
85 this->FlagMap
.find("SuppressStartupBanner") == this->FlagMap
.end())
87 if(this->Version
== 10)
89 this->FlagMap
["SuppressStartupBanner"] = "false";
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")
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
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
+= " ";
141 cmSystemTools::EscapeWindowsShellArgument(
143 cmsysSystem_Shell_Flag_AllowMakeVariables
|
144 cmsysSystem_Shell_Flag_VSIDE
);
147 //----------------------------------------------------------------------------
148 void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config
)
150 this->Configuration
= config
;
153 //----------------------------------------------------------------------------
155 cmVisualStudioGeneratorOptions
156 ::OutputPreprocessorDefinitions(std::ostream
& fout
,
160 if(this->Defines
.empty())
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())
171 this->TargetGenerator
->WritePlatformConfigTag(
172 "PreprocessorDefinitions",
173 this->Configuration
.c_str(),
179 fout
<< prefix
<< "<PreprocessorDefinitions>";
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.
192 if(this->Version
!= 10)
195 this->LocalGenerator
->EscapeForShell(di
->c_str(), true);
201 // Escape this flag for the IDE.
202 if(this->Version
== 10)
204 define
= cmVisualStudio10GeneratorOptionsEscapeForXML(define
.c_str());
208 define
= cmVisualStudioGeneratorOptionsEscapeForXML(define
.c_str());
210 // Store the flag in the project file.
211 fout
<< comma
<< define
;
212 if(this->Version
== 10)
221 if(this->Version
== 10)
223 fout
<< ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix
;
227 fout
<< "\"" << suffix
;
231 //----------------------------------------------------------------------------
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
)
242 if(this->Configuration
.size())
244 this->TargetGenerator
->WritePlatformConfigTag(
246 this->Configuration
.c_str(),
252 fout
<< "<" << m
->first
<< ">";
254 fout
<< m
->second
<< "</" << m
->first
<< ">\n";
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 //----------------------------------------------------------------------------
269 cmVisualStudioGeneratorOptions
270 ::OutputAdditionalOptions(std::ostream
& fout
,
274 if(!this->FlagString
.empty())
276 if(this->Version
== 10)
279 if(this->Configuration
.size())
281 this->TargetGenerator
->WritePlatformConfigTag(
283 this->Configuration
.c_str(),
289 fout
<< "<AdditionalOptions>";
291 fout
<< this->FlagString
.c_str()
292 << " %(AdditionalOptions)</AdditionalOptions>\n";
296 fout
<< prefix
<< "AdditionalOptions=\"";
298 cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString
.c_str());
299 fout
<< "\"" << suffix
;