1
0

cmVisualStudioGeneratorOptions.cxx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. this->FortranRuntimeDebug = false;
  44. this->FortranRuntimeDLL = false;
  45. this->FortranRuntimeMT = false;
  46. }
  47. //----------------------------------------------------------------------------
  48. void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault()
  49. {
  50. // Exception handling is on by default because the platform file has
  51. // "/EHsc" in the flags. Normally, that will override this
  52. // initialization to off, but the user has the option of removing
  53. // the flag to disable exception handling. When the user does
  54. // remove the flag we need to override the IDE default of on.
  55. switch (this->Version)
  56. {
  57. case 7:
  58. case 71:
  59. this->FlagMap["ExceptionHandling"] = "FALSE";
  60. break;
  61. case 10:
  62. // by default VS puts <ExceptionHandling></ExceptionHandling> empty
  63. // for a project, to make our projects look the same put a new line
  64. // and space over for the closing </ExceptionHandling> as the default
  65. // value
  66. this->FlagMap["ExceptionHandling"] = "\n ";
  67. break;
  68. default:
  69. this->FlagMap["ExceptionHandling"] = "0";
  70. break;
  71. }
  72. }
  73. //----------------------------------------------------------------------------
  74. void cmVisualStudioGeneratorOptions::SetVerboseMakefile(bool verbose)
  75. {
  76. // If verbose makefiles have been requested and the /nologo option
  77. // was not given explicitly in the flags we want to add an attribute
  78. // to the generated project to disable logo suppression. Otherwise
  79. // the GUI default is to enable suppression.
  80. if(verbose &&
  81. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  82. {
  83. if(this->Version == 10)
  84. {
  85. this->FlagMap["SuppressStartupBanner"] = "false";
  86. }
  87. else
  88. {
  89. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  90. }
  91. }
  92. }
  93. bool cmVisualStudioGeneratorOptions::IsDebug()
  94. {
  95. return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
  96. }
  97. //----------------------------------------------------------------------------
  98. bool cmVisualStudioGeneratorOptions::UsingUnicode()
  99. {
  100. // Look for the a _UNICODE definition.
  101. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  102. di != this->Defines.end(); ++di)
  103. {
  104. if(*di == "_UNICODE")
  105. {
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111. //----------------------------------------------------------------------------
  112. void cmVisualStudioGeneratorOptions::Parse(const char* flags)
  113. {
  114. // Parse the input string as a windows command line since the string
  115. // is intended for writing directly into the build files.
  116. std::vector<std::string> args;
  117. cmSystemTools::ParseWindowsCommandLine(flags, args);
  118. // Process flags that need to be represented specially in the IDE
  119. // project file.
  120. for(std::vector<std::string>::iterator ai = args.begin();
  121. ai != args.end(); ++ai)
  122. {
  123. this->HandleFlag(ai->c_str());
  124. }
  125. }
  126. //----------------------------------------------------------------------------
  127. void cmVisualStudioGeneratorOptions::ParseFinish()
  128. {
  129. if(this->CurrentTool == FortranCompiler)
  130. {
  131. // "RuntimeLibrary" attribute values:
  132. // "rtMultiThreaded", "0", /threads /libs:static
  133. // "rtMultiThreadedDLL", "2", /threads /libs:dll
  134. // "rtMultiThreadedDebug", "1", /threads /dbglibs /libs:static
  135. // "rtMultiThreadedDebugDLL", "3", /threads /dbglibs /libs:dll
  136. // These seem unimplemented by the IDE:
  137. // "rtSingleThreaded", "4", /libs:static
  138. // "rtSingleThreadedDLL", "10", /libs:dll
  139. // "rtSingleThreadedDebug", "5", /dbglibs /libs:static
  140. // "rtSingleThreadedDebugDLL", "11", /dbglibs /libs:dll
  141. std::string rl = "rtMultiThreaded";
  142. rl += this->FortranRuntimeDebug? "Debug" : "";
  143. rl += this->FortranRuntimeDLL? "DLL" : "";
  144. this->FlagMap["RuntimeLibrary"] = rl;
  145. }
  146. }
  147. //----------------------------------------------------------------------------
  148. void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
  149. {
  150. // Look for Intel Fortran flags that do not map well in the flag table.
  151. if(this->CurrentTool == FortranCompiler)
  152. {
  153. if(strcmp(flag, "/dbglibs") == 0)
  154. {
  155. this->FortranRuntimeDebug = true;
  156. return;
  157. }
  158. if(strcmp(flag, "/threads") == 0)
  159. {
  160. this->FortranRuntimeMT = true;
  161. return;
  162. }
  163. if(strcmp(flag, "/libs:dll") == 0)
  164. {
  165. this->FortranRuntimeDLL = true;
  166. return;
  167. }
  168. if(strcmp(flag, "/libs:static") == 0)
  169. {
  170. this->FortranRuntimeDLL = false;
  171. return;
  172. }
  173. }
  174. // This option is not known. Store it in the output flags.
  175. this->FlagString += " ";
  176. this->FlagString +=
  177. cmSystemTools::EscapeWindowsShellArgument(
  178. flag,
  179. cmsysSystem_Shell_Flag_AllowMakeVariables |
  180. cmsysSystem_Shell_Flag_VSIDE);
  181. }
  182. //----------------------------------------------------------------------------
  183. void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config)
  184. {
  185. this->Configuration = config;
  186. }
  187. //----------------------------------------------------------------------------
  188. void
  189. cmVisualStudioGeneratorOptions
  190. ::OutputPreprocessorDefinitions(std::ostream& fout,
  191. const char* prefix,
  192. const char* suffix)
  193. {
  194. if(this->Defines.empty())
  195. {
  196. return;
  197. }
  198. if(this->Version == 10)
  199. {
  200. // if there are configuration specifc flags, then
  201. // use the configuration specific tag for PreprocessorDefinitions
  202. if(this->Configuration.size())
  203. {
  204. fout << prefix;
  205. this->TargetGenerator->WritePlatformConfigTag(
  206. "PreprocessorDefinitions",
  207. this->Configuration.c_str(),
  208. 0,
  209. 0, 0, &fout);
  210. }
  211. else
  212. {
  213. fout << prefix << "<PreprocessorDefinitions>";
  214. }
  215. }
  216. else
  217. {
  218. fout << prefix << "PreprocessorDefinitions=\"";
  219. }
  220. const char* sep = "";
  221. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  222. di != this->Defines.end(); ++di)
  223. {
  224. // Escape the definition for the compiler.
  225. std::string define;
  226. if(this->Version != 10)
  227. {
  228. define =
  229. this->LocalGenerator->EscapeForShell(di->c_str(), true);
  230. }
  231. else
  232. {
  233. define = *di;
  234. }
  235. // Escape this flag for the IDE.
  236. if(this->Version == 10)
  237. {
  238. define = cmVisualStudio10GeneratorOptionsEscapeForXML(define.c_str());
  239. }
  240. else
  241. {
  242. define = cmVisualStudioGeneratorOptionsEscapeForXML(define.c_str());
  243. }
  244. // Store the flag in the project file.
  245. fout << sep << define;
  246. sep = ";";
  247. }
  248. if(this->Version == 10)
  249. {
  250. fout << ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix;
  251. }
  252. else
  253. {
  254. fout << "\"" << suffix;
  255. }
  256. }
  257. //----------------------------------------------------------------------------
  258. void
  259. cmVisualStudioGeneratorOptions
  260. ::OutputFlagMap(std::ostream& fout, const char* indent)
  261. {
  262. if(this->Version == 10)
  263. {
  264. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  265. m != this->FlagMap.end(); ++m)
  266. {
  267. fout << indent;
  268. if(this->Configuration.size())
  269. {
  270. this->TargetGenerator->WritePlatformConfigTag(
  271. m->first.c_str(),
  272. this->Configuration.c_str(),
  273. 0,
  274. 0, 0, &fout);
  275. }
  276. else
  277. {
  278. fout << "<" << m->first << ">";
  279. }
  280. fout << m->second << "</" << m->first << ">\n";
  281. }
  282. }
  283. else
  284. {
  285. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  286. m != this->FlagMap.end(); ++m)
  287. {
  288. fout << indent << m->first << "=\"" << m->second << "\"\n";
  289. }
  290. }
  291. }
  292. //----------------------------------------------------------------------------
  293. void
  294. cmVisualStudioGeneratorOptions
  295. ::OutputAdditionalOptions(std::ostream& fout,
  296. const char* prefix,
  297. const char* suffix)
  298. {
  299. if(!this->FlagString.empty())
  300. {
  301. if(this->Version == 10)
  302. {
  303. fout << prefix;
  304. if(this->Configuration.size())
  305. {
  306. this->TargetGenerator->WritePlatformConfigTag(
  307. "AdditionalOptions",
  308. this->Configuration.c_str(),
  309. 0,
  310. 0, 0, &fout);
  311. }
  312. else
  313. {
  314. fout << "<AdditionalOptions>";
  315. }
  316. fout << this->FlagString.c_str()
  317. << " %(AdditionalOptions)</AdditionalOptions>\n";
  318. }
  319. else
  320. {
  321. fout << prefix << "AdditionalOptions=\"";
  322. fout <<
  323. cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString.c_str());
  324. fout << "\"" << suffix;
  325. }
  326. }
  327. }