PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/cmVisualStudioGeneratorOptions.cxx

https://github.com/LuaDist/cmake
C++ | 302 lines | 249 code | 16 blank | 37 comment | 40 complexity | f04755f55162562bc19c497e336ef1fc MD5 | raw file
  1. #include "cmVisualStudioGeneratorOptions.h"
  2. #include "cmSystemTools.h"
  3. #include <cmsys/System.h>
  4. #include "cmVisualStudio10TargetGenerator.h"
  5. inline std::string cmVisualStudio10GeneratorOptionsEscapeForXML(const char* s)
  6. {
  7. std::string ret = s;
  8. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  9. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  10. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  11. return ret;
  12. }
  13. inline std::string cmVisualStudioGeneratorOptionsEscapeForXML(const char* s)
  14. {
  15. std::string ret = s;
  16. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  17. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  18. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  19. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  20. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  21. return ret;
  22. }
  23. //----------------------------------------------------------------------------
  24. cmVisualStudioGeneratorOptions
  25. ::cmVisualStudioGeneratorOptions(cmLocalGenerator* lg,
  26. int version,
  27. Tool tool,
  28. cmVS7FlagTable const* table,
  29. cmVS7FlagTable const* extraTable,
  30. cmVisualStudio10TargetGenerator* g):
  31. cmIDEOptions(),
  32. LocalGenerator(lg), Version(version), CurrentTool(tool),
  33. TargetGenerator(g)
  34. {
  35. // Store the given flag tables.
  36. cmIDEFlagTable const** ft = this->FlagTable;
  37. if(table) { *ft++ = table; }
  38. if(extraTable) { *ft++ = extraTable; }
  39. // Preprocessor definitions are not allowed for linker tools.
  40. this->AllowDefine = (tool != Linker);
  41. // Slash options are allowed for VS.
  42. this->AllowSlash = true;
  43. }
  44. //----------------------------------------------------------------------------
  45. void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault()
  46. {
  47. // Exception handling is on by default because the platform file has
  48. // "/EHsc" in the flags. Normally, that will override this
  49. // initialization to off, but the user has the option of removing
  50. // the flag to disable exception handling. When the user does
  51. // remove the flag we need to override the IDE default of on.
  52. switch (this->Version)
  53. {
  54. case 7:
  55. case 71:
  56. this->FlagMap["ExceptionHandling"] = "FALSE";
  57. break;
  58. case 10:
  59. // by default VS puts <ExceptionHandling></ExceptionHandling> empty
  60. // for a project, to make our projects look the same put a new line
  61. // and space over for the closing </ExceptionHandling> as the default
  62. // value
  63. this->FlagMap["ExceptionHandling"] = "\n ";
  64. break;
  65. default:
  66. this->FlagMap["ExceptionHandling"] = "0";
  67. break;
  68. }
  69. }
  70. //----------------------------------------------------------------------------
  71. void cmVisualStudioGeneratorOptions::SetVerboseMakefile(bool verbose)
  72. {
  73. // If verbose makefiles have been requested and the /nologo option
  74. // was not given explicitly in the flags we want to add an attribute
  75. // to the generated project to disable logo suppression. Otherwise
  76. // the GUI default is to enable suppression.
  77. if(verbose &&
  78. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  79. {
  80. if(this->Version == 10)
  81. {
  82. this->FlagMap["SuppressStartupBanner"] = "false";
  83. }
  84. else
  85. {
  86. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  87. }
  88. }
  89. }
  90. bool cmVisualStudioGeneratorOptions::IsDebug()
  91. {
  92. return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
  93. }
  94. //----------------------------------------------------------------------------
  95. bool cmVisualStudioGeneratorOptions::UsingUnicode()
  96. {
  97. // Look for the a _UNICODE definition.
  98. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  99. di != this->Defines.end(); ++di)
  100. {
  101. if(*di == "_UNICODE")
  102. {
  103. return true;
  104. }
  105. }
  106. return false;
  107. }
  108. //----------------------------------------------------------------------------
  109. void cmVisualStudioGeneratorOptions::Parse(const char* flags)
  110. {
  111. // Parse the input string as a windows command line since the string
  112. // is intended for writing directly into the build files.
  113. std::vector<std::string> args;
  114. cmSystemTools::ParseWindowsCommandLine(flags, args);
  115. // Process flags that need to be represented specially in the IDE
  116. // project file.
  117. for(std::vector<std::string>::iterator ai = args.begin();
  118. ai != args.end(); ++ai)
  119. {
  120. this->HandleFlag(ai->c_str());
  121. }
  122. }
  123. //----------------------------------------------------------------------------
  124. void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
  125. {
  126. // This option is not known. Store it in the output flags.
  127. this->FlagString += " ";
  128. this->FlagString +=
  129. cmSystemTools::EscapeWindowsShellArgument(
  130. flag,
  131. cmsysSystem_Shell_Flag_AllowMakeVariables |
  132. cmsysSystem_Shell_Flag_VSIDE);
  133. }
  134. //----------------------------------------------------------------------------
  135. void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config)
  136. {
  137. this->Configuration = config;
  138. }
  139. //----------------------------------------------------------------------------
  140. void
  141. cmVisualStudioGeneratorOptions
  142. ::OutputPreprocessorDefinitions(std::ostream& fout,
  143. const char* prefix,
  144. const char* suffix)
  145. {
  146. if(this->Defines.empty())
  147. {
  148. return;
  149. }
  150. if(this->Version == 10)
  151. {
  152. // if there are configuration specifc flags, then
  153. // use the configuration specific tag for PreprocessorDefinitions
  154. if(this->Configuration.size())
  155. {
  156. fout << prefix;
  157. this->TargetGenerator->WritePlatformConfigTag(
  158. "PreprocessorDefinitions",
  159. this->Configuration.c_str(),
  160. 0,
  161. 0, 0, &fout);
  162. }
  163. else
  164. {
  165. fout << prefix << "<PreprocessorDefinitions>";
  166. }
  167. }
  168. else
  169. {
  170. fout << prefix << "PreprocessorDefinitions=\"";
  171. }
  172. const char* comma = "";
  173. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  174. di != this->Defines.end(); ++di)
  175. {
  176. // Escape the definition for the compiler.
  177. std::string define;
  178. if(this->Version != 10)
  179. {
  180. define =
  181. this->LocalGenerator->EscapeForShell(di->c_str(), true);
  182. }
  183. else
  184. {
  185. define = *di;
  186. }
  187. // Escape this flag for the IDE.
  188. if(this->Version == 10)
  189. {
  190. define = cmVisualStudio10GeneratorOptionsEscapeForXML(define.c_str());
  191. }
  192. else
  193. {
  194. define = cmVisualStudioGeneratorOptionsEscapeForXML(define.c_str());
  195. }
  196. // Store the flag in the project file.
  197. fout << comma << define;
  198. if(this->Version == 10)
  199. {
  200. comma = ";";
  201. }
  202. else
  203. {
  204. comma = ",";
  205. }
  206. }
  207. if(this->Version == 10)
  208. {
  209. fout << ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix;
  210. }
  211. else
  212. {
  213. fout << "\"" << suffix;
  214. }
  215. }
  216. //----------------------------------------------------------------------------
  217. void
  218. cmVisualStudioGeneratorOptions
  219. ::OutputFlagMap(std::ostream& fout, const char* indent)
  220. {
  221. if(this->Version == 10)
  222. {
  223. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  224. m != this->FlagMap.end(); ++m)
  225. {
  226. fout << indent;
  227. if(this->Configuration.size())
  228. {
  229. this->TargetGenerator->WritePlatformConfigTag(
  230. m->first.c_str(),
  231. this->Configuration.c_str(),
  232. 0,
  233. 0, 0, &fout);
  234. }
  235. else
  236. {
  237. fout << "<" << m->first << ">";
  238. }
  239. fout << m->second << "</" << m->first << ">\n";
  240. }
  241. }
  242. else
  243. {
  244. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  245. m != this->FlagMap.end(); ++m)
  246. {
  247. fout << indent << m->first << "=\"" << m->second << "\"\n";
  248. }
  249. }
  250. }
  251. //----------------------------------------------------------------------------
  252. void
  253. cmVisualStudioGeneratorOptions
  254. ::OutputAdditionalOptions(std::ostream& fout,
  255. const char* prefix,
  256. const char* suffix)
  257. {
  258. if(!this->FlagString.empty())
  259. {
  260. if(this->Version == 10)
  261. {
  262. fout << prefix;
  263. if(this->Configuration.size())
  264. {
  265. this->TargetGenerator->WritePlatformConfigTag(
  266. "AdditionalOptions",
  267. this->Configuration.c_str(),
  268. 0,
  269. 0, 0, &fout);
  270. }
  271. else
  272. {
  273. fout << "<AdditionalOptions>";
  274. }
  275. fout << this->FlagString.c_str()
  276. << " %(AdditionalOptions)</AdditionalOptions>\n";
  277. }
  278. else
  279. {
  280. fout << prefix << "AdditionalOptions=\"";
  281. fout <<
  282. cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString.c_str());
  283. fout << "\"" << suffix;
  284. }
  285. }
  286. }