cmLocalVisualStudio7Generator.cxx 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalVisualStudio7Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmXMLParser.h"
  16. #include <cm_expat.h>
  17. #include "cmMakefile.h"
  18. #include "cmSystemTools.h"
  19. #include "cmSourceFile.h"
  20. #include "cmCacheManager.h"
  21. #include "cmake.h"
  22. #include "cmGeneratedFileStream.h"
  23. #include <cmsys/System.h>
  24. #include <ctype.h> // for isspace
  25. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  26. //----------------------------------------------------------------------------
  27. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
  28. {
  29. this->Version = 7;
  30. this->PlatformName = "Win32";
  31. this->ExtraFlagTable = 0;
  32. }
  33. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  34. {
  35. }
  36. void cmLocalVisualStudio7Generator::AddHelperCommands()
  37. {
  38. std::set<cmStdString> lang;
  39. lang.insert("C");
  40. lang.insert("CXX");
  41. lang.insert("RC");
  42. lang.insert("IDL");
  43. lang.insert("DEF");
  44. this->CreateCustomTargetsAndCommands(lang);
  45. this->FixGlobalTargets();
  46. }
  47. void cmLocalVisualStudio7Generator::Generate()
  48. {
  49. this->OutputVCProjFile();
  50. }
  51. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  52. {
  53. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  54. // commands for targets in which no sources are built. Add dummy
  55. // rules to force these targets to build.
  56. cmTargets &tgts = this->Makefile->GetTargets();
  57. for(cmTargets::iterator l = tgts.begin();
  58. l != tgts.end(); l++)
  59. {
  60. cmTarget& tgt = l->second;
  61. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  62. {
  63. std::vector<std::string> no_depends;
  64. cmCustomCommandLine force_command;
  65. force_command.push_back(";");
  66. cmCustomCommandLines force_commands;
  67. force_commands.push_back(force_command);
  68. const char* no_main_dependency = 0;
  69. std::string force = this->Makefile->GetStartOutputDirectory();
  70. force += cmake::GetCMakeFilesDirectory();
  71. force += "/";
  72. force += tgt.GetName();
  73. force += "_force";
  74. this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends,
  75. no_main_dependency,
  76. force_commands, " ", 0, true);
  77. if(cmSourceFile* file =
  78. this->Makefile->GetSourceFileWithOutput(force.c_str()))
  79. {
  80. tgt.AddSourceFile(file);
  81. }
  82. }
  83. }
  84. }
  85. // TODO
  86. // for CommandLine= need to repleace quotes with &quot
  87. // write out configurations
  88. void cmLocalVisualStudio7Generator::OutputVCProjFile()
  89. {
  90. // If not an in source build, then create the output directory
  91. if(strcmp(this->Makefile->GetStartOutputDirectory(),
  92. this->Makefile->GetHomeDirectory()) != 0)
  93. {
  94. if(!cmSystemTools::MakeDirectory
  95. (this->Makefile->GetStartOutputDirectory()))
  96. {
  97. cmSystemTools::Error("Error creating directory ",
  98. this->Makefile->GetStartOutputDirectory());
  99. }
  100. }
  101. // Create the VCProj or set of VCProj's for libraries and executables
  102. cmTargets &tgts = this->Makefile->GetTargets();
  103. for(cmTargets::iterator l = tgts.begin();
  104. l != tgts.end(); l++)
  105. {
  106. // Add a rule to regenerate the build system when the target
  107. // specification source changes.
  108. const char* suppRegenRule =
  109. this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  110. if (!cmSystemTools::IsOn(suppRegenRule) &&
  111. (strcmp(l->first.c_str(), CMAKE_CHECK_BUILD_SYSTEM_TARGET) != 0))
  112. {
  113. this->AddVCProjBuildRule(l->second);
  114. }
  115. }
  116. for(cmTargets::iterator l = tgts.begin();
  117. l != tgts.end(); l++)
  118. {
  119. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  120. // so don't build a projectfile for it
  121. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
  122. {
  123. this->CreateSingleVCProj(l->first.c_str(),l->second);
  124. }
  125. }
  126. }
  127. void cmLocalVisualStudio7Generator
  128. ::CreateSingleVCProj(const char *lname, cmTarget &target)
  129. {
  130. // add to the list of projects
  131. std::string pname = lname;
  132. target.SetProperty("GENERATOR_FILE_NAME",lname);
  133. // create the dsp.cmake file
  134. std::string fname;
  135. fname = this->Makefile->GetStartOutputDirectory();
  136. fname += "/";
  137. fname += lname;
  138. fname += ".vcproj";
  139. // Generate the project file and replace it atomically with
  140. // copy-if-different. We use a separate timestamp so that the IDE
  141. // does not reload project files unnecessarily.
  142. {
  143. cmGeneratedFileStream fout(fname.c_str());
  144. fout.SetCopyIfDifferent(true);
  145. this->WriteVCProjFile(fout,lname,target);
  146. }
  147. // Touch a timestamp file used to determine when the project file is
  148. // out of date.
  149. std::string stampName;
  150. stampName = this->Makefile->GetStartOutputDirectory();
  151. stampName += cmake::GetCMakeFilesDirectory();
  152. cmSystemTools::MakeDirectory(stampName.c_str());
  153. stampName += "/";
  154. stampName += lname;
  155. stampName += ".vcproj.stamp";
  156. std::ofstream stamp(stampName.c_str());
  157. stamp << "# CMake timestamp for " << lname << ".vcproj" << std::endl;
  158. }
  159. void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmTarget& tgt)
  160. {
  161. std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
  162. stampName += tgt.GetName();
  163. stampName += ".vcproj.stamp";
  164. const char* dsprule =
  165. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  166. cmCustomCommandLine commandLine;
  167. commandLine.push_back(dsprule);
  168. std::string makefileIn = this->Makefile->GetStartDirectory();
  169. makefileIn += "/";
  170. makefileIn += "CMakeLists.txt";
  171. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  172. std::string comment = "Building Custom Rule ";
  173. comment += makefileIn;
  174. std::string args;
  175. args = "-H";
  176. args += this->Convert(this->Makefile->GetHomeDirectory(),
  177. START_OUTPUT, UNCHANGED, true);
  178. commandLine.push_back(args);
  179. args = "-B";
  180. args +=
  181. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  182. START_OUTPUT, UNCHANGED, true);
  183. commandLine.push_back(args);
  184. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  185. cmCustomCommandLines commandLines;
  186. commandLines.push_back(commandLine);
  187. const char* no_working_directory = 0;
  188. this->Makefile->AddCustomCommandToOutput(stampName.c_str(), listFiles,
  189. makefileIn.c_str(), commandLines,
  190. comment.c_str(),
  191. no_working_directory, true);
  192. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  193. {
  194. tgt.AddSourceFile(file);
  195. }
  196. else
  197. {
  198. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  199. }
  200. }
  201. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  202. const char *libName,
  203. cmTarget &target)
  204. {
  205. std::vector<std::string> *configs =
  206. static_cast<cmGlobalVisualStudio7Generator *>
  207. (this->GlobalGenerator)->GetConfigurations();
  208. fout << "\t<Configurations>\n";
  209. for( std::vector<std::string>::iterator i = configs->begin();
  210. i != configs->end(); ++i)
  211. {
  212. this->WriteConfiguration(fout, i->c_str(), libName, target);
  213. }
  214. fout << "\t</Configurations>\n";
  215. }
  216. // fill the table here currently the comment field is not used for
  217. // anything other than documentation NOTE: Make sure the longer
  218. // commandFlag comes FIRST!
  219. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  220. {
  221. // option flags (some flags map to the same option)
  222. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  223. {"BasicRuntimeChecks", "RTCsu",
  224. "Both stack and uninitialized checks", "3", 0},
  225. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  226. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  227. {"BasicRuntimeChecks", "RTC1",
  228. "Both stack and uninitialized checks", "3", 0},
  229. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  230. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  231. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  232. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  233. {"EnableEnhancedInstructionSet", "arch:SSE2",
  234. "Use sse2 instructions", "2", 0},
  235. {"EnableEnhancedInstructionSet", "arch:SSE",
  236. "Use sse instructions", "1", 0},
  237. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  238. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  239. {"CompileAs", "TC", "Compile as c code", "1", 0},
  240. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  241. {"Optimization", "Od", "Non Debug", "0", 0},
  242. {"Optimization", "O1", "Min Size", "1", 0},
  243. {"Optimization", "O2", "Max Speed", "2", 0},
  244. {"Optimization", "Ox", "Max Optimization", "3", 0},
  245. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  246. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  247. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  248. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  249. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  250. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  251. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  252. {"RuntimeLibrary", "MTd", "Multithreded debug", "1", 0},
  253. {"RuntimeLibrary", "MT", "Multithreded", "0", 0},
  254. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3", 0},
  255. {"RuntimeLibrary", "MD", "Multithreded dll", "2", 0},
  256. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5", 0},
  257. {"RuntimeLibrary", "ML", "Sinble Thread", "4", 0},
  258. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  259. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  260. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  261. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  262. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  263. {"WarningLevel", "W1", "Warning level", "1", 0},
  264. {"WarningLevel", "W2", "Warning level", "2", 0},
  265. {"WarningLevel", "W3", "Warning level", "3", 0},
  266. {"WarningLevel", "W4", "Warning level", "4", 0},
  267. // Precompiled header and related options. Note that the
  268. // UsePrecompiledHeader entries are marked as "Continue" so that the
  269. // corresponding PrecompiledHeaderThrough entry can be found.
  270. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  271. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  272. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  273. cmVS7FlagTable::UserValueRequired},
  274. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  275. cmVS7FlagTable::UserValue},
  276. // The YX and Yu options are in a per-global-generator table because
  277. // their values differ based on the VS IDE version.
  278. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  279. cmVS7FlagTable::UserValueRequired},
  280. // boolean flags
  281. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
  282. {"EnableFibreSafeOptimization", "GT", "OmitFramePointers", "TRUE", 0},
  283. {"EnableFunctionLevelLinking", "Gy",
  284. "EnableFunctionLevelLinking", "TRUE", 0},
  285. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
  286. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  287. {"ExceptionHandling", "EHa", "enable c++ exceptions", "2", 0},
  288. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  289. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
  290. {"ImproveFloatingPointConsistency", "Op",
  291. "ImproveFloatingPointConsistency", "TRUE", 0},
  292. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
  293. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
  294. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
  295. {"RuntimeTypeInfo", "GR",
  296. "Turn on Run time type information for c++", "TRUE", 0},
  297. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
  298. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
  299. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
  300. {0,0,0,0,0}
  301. };
  302. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  303. {
  304. // option flags (some flags map to the same option)
  305. {"GenerateManifest", "MANIFEST:NO",
  306. "disable manifest generation", "FALSE", 0},
  307. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
  308. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  309. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  310. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  311. cmVS7FlagTable::UserValue},
  312. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  313. "TRUE", 0},
  314. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  315. cmVS7FlagTable::UserValue},
  316. {0,0,0,0,0}
  317. };
  318. //----------------------------------------------------------------------------
  319. class cmLocalVisualStudio7GeneratorOptions
  320. {
  321. public:
  322. // Construct an options table for a given tool.
  323. enum Tool
  324. {
  325. Compiler,
  326. Linker
  327. };
  328. cmLocalVisualStudio7GeneratorOptions(Tool tool,
  329. cmVS7FlagTable const* extraTable = 0);
  330. // Store options from command line flags.
  331. void Parse(const char* flags);
  332. // Fix the ExceptionHandling option to default to off.
  333. void FixExceptionHandlingDefault();
  334. // Store options for verbose builds.
  335. void SetVerboseMakefile(bool verbose);
  336. // Store definitions and flags.
  337. void AddDefine(const std::string& define);
  338. void AddFlag(const char* flag, const char* value);
  339. // Check for specific options.
  340. bool UsingUnicode();
  341. // Write options to output.
  342. void OutputPreprocessorDefinitions(std::ostream& fout,
  343. const char* prefix,
  344. const char* suffix);
  345. void OutputFlagMap(std::ostream& fout, const char* indent);
  346. void OutputAdditionalOptions(std::ostream& fout,
  347. const char* prefix,
  348. const char* suffix);
  349. private:
  350. // create a map of xml tags to the values they should have in the output
  351. // for example, "BufferSecurityCheck" = "TRUE"
  352. // first fill this table with the values for the configuration
  353. // Debug, Release, etc,
  354. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  355. // and CMAKE_C_FLAGS
  356. // and overwrite or add new values to this map
  357. std::map<cmStdString, cmStdString> FlagMap;
  358. // Preprocessor definitions.
  359. std::vector<cmStdString> Defines;
  360. // Unrecognized flags that get no special handling.
  361. cmStdString FlagString;
  362. Tool CurrentTool;
  363. bool DoingDefine;
  364. cmVS7FlagTable const* FlagTable;
  365. cmVS7FlagTable const* ExtraFlagTable;
  366. void HandleFlag(const char* flag);
  367. bool CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  368. bool& flag_handled);
  369. };
  370. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  371. const char* configName,
  372. const char *libName,
  373. cmTarget &target)
  374. {
  375. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  376. if(!mfcFlag)
  377. {
  378. mfcFlag = "0";
  379. }
  380. fout << "\t\t<Configuration\n"
  381. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  382. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  383. // This is an internal type to Visual Studio, it seems that:
  384. // 4 == static library
  385. // 2 == dll
  386. // 1 == executable
  387. // 10 == utility
  388. const char* configType = "10";
  389. switch(target.GetType())
  390. {
  391. case cmTarget::STATIC_LIBRARY:
  392. configType = "4";
  393. break;
  394. case cmTarget::SHARED_LIBRARY:
  395. case cmTarget::MODULE_LIBRARY:
  396. configType = "2";
  397. break;
  398. case cmTarget::EXECUTABLE:
  399. configType = "1";
  400. break;
  401. case cmTarget::UTILITY:
  402. case cmTarget::GLOBAL_TARGET:
  403. configType = "10";
  404. default:
  405. break;
  406. }
  407. std::string flags;
  408. if(strcmp(configType, "10") != 0)
  409. {
  410. const char* linkLanguage =
  411. target.GetLinkerLanguage(this->GetGlobalGenerator());
  412. if(!linkLanguage)
  413. {
  414. cmSystemTools::Error
  415. ("CMake can not determine linker language for target:",
  416. target.GetName());
  417. return;
  418. }
  419. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
  420. {
  421. std::string baseFlagVar = "CMAKE_";
  422. baseFlagVar += linkLanguage;
  423. baseFlagVar += "_FLAGS";
  424. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  425. std::string flagVar = baseFlagVar + std::string("_") +
  426. cmSystemTools::UpperCase(configName);
  427. flags += " ";
  428. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  429. }
  430. // set the correct language
  431. if(strcmp(linkLanguage, "C") == 0)
  432. {
  433. flags += " /TC ";
  434. }
  435. if(strcmp(linkLanguage, "CXX") == 0)
  436. {
  437. flags += " /TP ";
  438. }
  439. }
  440. // Add the target-specific flags.
  441. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  442. {
  443. flags += " ";
  444. flags += targetFlags;
  445. }
  446. // Get preprocessor definitions for this directory.
  447. std::string defineFlags = this->Makefile->GetDefineFlags();
  448. // Construct a set of build options for this target.
  449. Options targetOptions(Options::Compiler, this->ExtraFlagTable);
  450. targetOptions.FixExceptionHandlingDefault();
  451. targetOptions.Parse(flags.c_str());
  452. targetOptions.Parse(defineFlags.c_str());
  453. targetOptions.SetVerboseMakefile(
  454. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  455. // Add a definition for the configuration name.
  456. std::string configDefine = "CMAKE_INTDIR=\"";
  457. configDefine += configName;
  458. configDefine += "\"";
  459. targetOptions.AddDefine(configDefine);
  460. // Add the export symbol definition for shared library objects.
  461. if(const char* exportMacro = target.GetExportMacro())
  462. {
  463. targetOptions.AddDefine(exportMacro);
  464. }
  465. // The intermediate directory name consists of a directory for the
  466. // target and a subdirectory for the configuration name.
  467. std::string intermediateDir = this->GetTargetDirectory(target);
  468. intermediateDir += "/";
  469. intermediateDir += configName;
  470. fout << "\t\t\tIntermediateDirectory=\""
  471. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  472. << "\"\n"
  473. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  474. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  475. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  476. // If unicode is enabled change the character set to unicode, if not
  477. // then default to MBCS.
  478. if(targetOptions.UsingUnicode())
  479. {
  480. fout << "\t\t\tCharacterSet=\"1\">\n";
  481. }
  482. else
  483. {
  484. fout << "\t\t\tCharacterSet=\"2\">\n";
  485. }
  486. fout << "\t\t\t<Tool\n"
  487. << "\t\t\t\tName=\"VCCLCompilerTool\"\n";
  488. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  489. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  490. std::vector<std::string> includes;
  491. this->GetIncludeDirectories(includes);
  492. std::vector<std::string>::iterator i = includes.begin();
  493. for(;i != includes.end(); ++i)
  494. {
  495. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  496. fout << ipath << ";";
  497. }
  498. fout << "\"\n";
  499. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  500. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  501. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  502. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  503. if(target.GetType() == cmTarget::EXECUTABLE ||
  504. target.GetType() == cmTarget::STATIC_LIBRARY ||
  505. target.GetType() == cmTarget::SHARED_LIBRARY ||
  506. target.GetType() == cmTarget::MODULE_LIBRARY)
  507. {
  508. // We need to specify a program database file name even for
  509. // non-debug configurations because VS still creates .idb files.
  510. fout << "\t\t\t\tProgramDataBaseFileName=\""
  511. << target.GetDirectory(configName) << "/"
  512. << target.GetPDBName(configName) << "\"\n";
  513. }
  514. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  515. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  516. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  517. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  518. for(i = includes.begin();i != includes.end(); ++i)
  519. {
  520. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  521. fout << ipath << ";";
  522. }
  523. // add the -D flags to the RC tool
  524. fout << "\"";
  525. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  526. fout << "/>\n";
  527. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  528. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  529. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  530. if( this->PlatformName == "x64" )
  531. {
  532. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  533. }
  534. else if( this->PlatformName == "ia64" )
  535. {
  536. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  537. }
  538. else
  539. {
  540. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  541. }
  542. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  543. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  544. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  545. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  546. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  547. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  548. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  549. // end of <Tool Name=VCMIDLTool
  550. // If we are building a version 8 project file, add a flag telling the
  551. // manifest tool to use a workaround for FAT32 file systems, which can cause
  552. // an empty manifest to be embedded into the resulting executable.
  553. // See CMake bug #2617.
  554. if ( this->Version >= 8 )
  555. {
  556. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  557. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  558. << "\t\t\t/>\n";
  559. }
  560. this->OutputTargetRules(fout, configName, target, libName);
  561. this->OutputBuildTool(fout, configName, target);
  562. fout << "\t\t</Configuration>\n";
  563. }
  564. //----------------------------------------------------------------------------
  565. std::string
  566. cmLocalVisualStudio7Generator
  567. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  568. {
  569. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  570. std::string extraLinkOptionsBuildTypeDef =
  571. rootLinkerFlags + "_" + configTypeUpper;
  572. std::string extraLinkOptionsBuildType =
  573. this->Makefile->GetRequiredDefinition
  574. (extraLinkOptionsBuildTypeDef.c_str());
  575. return extraLinkOptionsBuildType;
  576. }
  577. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  578. const char* configName,
  579. cmTarget &target)
  580. {
  581. std::string temp;
  582. std::string extraLinkOptions;
  583. if(target.GetType() == cmTarget::EXECUTABLE)
  584. {
  585. extraLinkOptions =
  586. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  587. + std::string(" ")
  588. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  589. }
  590. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  591. {
  592. extraLinkOptions =
  593. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  594. + std::string(" ")
  595. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  596. }
  597. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  598. {
  599. extraLinkOptions =
  600. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  601. + std::string(" ")
  602. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  603. }
  604. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  605. if(targetLinkFlags)
  606. {
  607. extraLinkOptions += " ";
  608. extraLinkOptions += targetLinkFlags;
  609. }
  610. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  611. std::string linkFlagsConfig = "LINK_FLAGS_";
  612. linkFlagsConfig += configTypeUpper;
  613. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  614. if(targetLinkFlags)
  615. {
  616. extraLinkOptions += " ";
  617. extraLinkOptions += targetLinkFlags;
  618. }
  619. Options linkOptions(Options::Linker);
  620. linkOptions.Parse(extraLinkOptions.c_str());
  621. switch(target.GetType())
  622. {
  623. case cmTarget::STATIC_LIBRARY:
  624. {
  625. std::string targetNameFull = target.GetFullName(configName);
  626. std::string libpath = target.GetDirectory(configName);
  627. libpath += "/";
  628. libpath += targetNameFull;
  629. fout << "\t\t\t<Tool\n"
  630. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  631. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  632. {
  633. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  634. }
  635. fout << "\t\t\t\tOutputFile=\""
  636. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  637. break;
  638. }
  639. case cmTarget::SHARED_LIBRARY:
  640. case cmTarget::MODULE_LIBRARY:
  641. {
  642. std::string targetName;
  643. std::string targetNameSO;
  644. std::string targetNameFull;
  645. std::string targetNameImport;
  646. std::string targetNamePDB;
  647. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  648. targetNameImport, targetNamePDB, configName);
  649. // Compute the link library and directory information.
  650. std::vector<cmStdString> linkLibs;
  651. std::vector<cmStdString> linkDirs;
  652. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  653. // Get the language to use for linking.
  654. const char* linkLanguage =
  655. target.GetLinkerLanguage(this->GetGlobalGenerator());
  656. if(!linkLanguage)
  657. {
  658. cmSystemTools::Error
  659. ("CMake can not determine linker language for target:",
  660. target.GetName());
  661. return;
  662. }
  663. // Compute the variable name to lookup standard libraries for this
  664. // language.
  665. std::string standardLibsVar = "CMAKE_";
  666. standardLibsVar += linkLanguage;
  667. standardLibsVar += "_STANDARD_LIBRARIES";
  668. fout << "\t\t\t<Tool\n"
  669. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  670. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  671. // Use the NOINHERIT macro to avoid getting VS project default
  672. // libraries which may be set by the user to something bad.
  673. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  674. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  675. << " ";
  676. this->OutputLibraries(fout, linkLibs);
  677. fout << "\"\n";
  678. temp = target.GetDirectory(configName);
  679. temp += "/";
  680. temp += targetNameFull;
  681. fout << "\t\t\t\tOutputFile=\""
  682. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  683. this->WriteTargetVersionAttribute(fout, target);
  684. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  685. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  686. this->OutputLibraryDirectories(fout, linkDirs);
  687. fout << "\"\n";
  688. this->OutputModuleDefinitionFile(fout, target);
  689. temp = target.GetDirectory(configName);
  690. temp += "/";
  691. temp += targetNamePDB;
  692. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  693. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  694. if(strcmp(configName, "Debug") == 0
  695. || strcmp(configName, "RelWithDebInfo") == 0)
  696. {
  697. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  698. }
  699. std::string stackVar = "CMAKE_";
  700. stackVar += linkLanguage;
  701. stackVar += "_STACK_SIZE";
  702. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  703. if(stackVal)
  704. {
  705. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  706. }
  707. temp = target.GetDirectory(configName, true);
  708. temp += "/";
  709. temp += targetNameImport;
  710. fout << "\t\t\t\tImportLibrary=\""
  711. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  712. }
  713. break;
  714. case cmTarget::EXECUTABLE:
  715. {
  716. std::string targetName;
  717. std::string targetNameFull;
  718. std::string targetNameImport;
  719. std::string targetNamePDB;
  720. target.GetExecutableNames(targetName, targetNameFull,
  721. targetNameImport, targetNamePDB, configName);
  722. // Compute the link library and directory information.
  723. std::vector<cmStdString> linkLibs;
  724. std::vector<cmStdString> linkDirs;
  725. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  726. // Get the language to use for linking.
  727. const char* linkLanguage =
  728. target.GetLinkerLanguage(this->GetGlobalGenerator());
  729. if(!linkLanguage)
  730. {
  731. cmSystemTools::Error
  732. ("CMake can not determine linker language for target:",
  733. target.GetName());
  734. return;
  735. }
  736. // Compute the variable name to lookup standard libraries for this
  737. // language.
  738. std::string standardLibsVar = "CMAKE_";
  739. standardLibsVar += linkLanguage;
  740. standardLibsVar += "_STANDARD_LIBRARIES";
  741. fout << "\t\t\t<Tool\n"
  742. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  743. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  744. // Use the NOINHERIT macro to avoid getting VS project default
  745. // libraries which may be set by the user to something bad.
  746. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  747. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  748. << " ";
  749. this->OutputLibraries(fout, linkLibs);
  750. fout << "\"\n";
  751. temp = target.GetDirectory(configName);
  752. temp += "/";
  753. temp += targetNameFull;
  754. fout << "\t\t\t\tOutputFile=\""
  755. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  756. this->WriteTargetVersionAttribute(fout, target);
  757. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  758. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  759. this->OutputLibraryDirectories(fout, linkDirs);
  760. fout << "\"\n";
  761. fout << "\t\t\t\tProgramDataBaseFile=\""
  762. << target.GetDirectory(configName) << "/" << targetNamePDB
  763. << "\"\n";
  764. if(strcmp(configName, "Debug") == 0
  765. || strcmp(configName, "RelWithDebInfo") == 0)
  766. {
  767. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  768. }
  769. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  770. {
  771. fout << "\t\t\t\tSubSystem=\"2\"\n";
  772. }
  773. else
  774. {
  775. fout << "\t\t\t\tSubSystem=\"1\"\n";
  776. }
  777. std::string stackVar = "CMAKE_";
  778. stackVar += linkLanguage;
  779. stackVar += "_STACK_SIZE";
  780. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  781. if(stackVal)
  782. {
  783. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  784. }
  785. temp = target.GetDirectory(configName, true);
  786. temp += "/";
  787. temp += targetNameImport;
  788. fout << "\t\t\t\tImportLibrary=\""
  789. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  790. break;
  791. }
  792. case cmTarget::UTILITY:
  793. case cmTarget::GLOBAL_TARGET:
  794. break;
  795. }
  796. }
  797. //----------------------------------------------------------------------------
  798. void
  799. cmLocalVisualStudio7Generator
  800. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  801. {
  802. int major;
  803. int minor;
  804. target.GetTargetVersion(major, minor);
  805. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  806. }
  807. void cmLocalVisualStudio7Generator
  808. ::OutputModuleDefinitionFile(std::ostream& fout,
  809. cmTarget &target)
  810. {
  811. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  812. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  813. i != classes.end(); i++)
  814. {
  815. cmSourceFile* sf = *i;
  816. if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
  817. {
  818. fout << "\t\t\t\tModuleDefinitionFile=\""
  819. << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
  820. << "\"\n";
  821. return;
  822. }
  823. }
  824. }
  825. //----------------------------------------------------------------------------
  826. void
  827. cmLocalVisualStudio7Generator
  828. ::OutputLibraries(std::ostream& fout,
  829. std::vector<cmStdString> const& libs)
  830. {
  831. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  832. l != libs.end(); ++l)
  833. {
  834. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  835. }
  836. }
  837. //----------------------------------------------------------------------------
  838. void
  839. cmLocalVisualStudio7Generator
  840. ::OutputLibraryDirectories(std::ostream& fout,
  841. std::vector<cmStdString> const& dirs)
  842. {
  843. const char* comma = "";
  844. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  845. d != dirs.end(); ++d)
  846. {
  847. // Remove any trailing slash and skip empty paths.
  848. std::string dir = *d;
  849. if(dir[dir.size()-1] == '/')
  850. {
  851. dir = dir.substr(0, dir.size()-1);
  852. }
  853. if(dir.empty())
  854. {
  855. continue;
  856. }
  857. // Switch to a relative path specification if it is shorter.
  858. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  859. {
  860. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  861. if(rel.size() < dir.size())
  862. {
  863. dir = rel;
  864. }
  865. }
  866. // First search a configuration-specific subdirectory and then the
  867. // original directory.
  868. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  869. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  870. comma = ",";
  871. }
  872. }
  873. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  874. const char *libName,
  875. cmTarget &target)
  876. {
  877. // get the configurations
  878. std::vector<std::string> *configs =
  879. static_cast<cmGlobalVisualStudio7Generator *>
  880. (this->GlobalGenerator)->GetConfigurations();
  881. // We may be modifying the source groups temporarily, so make a copy.
  882. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  883. // get the classes from the source lists then add them to the groups
  884. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  885. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  886. i != classes.end(); i++)
  887. {
  888. // Add the file to the list of sources.
  889. std::string source = (*i)->GetFullPath();
  890. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  891. {
  892. this->ModuleDefinitionFile = (*i)->GetFullPath();
  893. }
  894. cmSourceGroup& sourceGroup =
  895. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  896. sourceGroup.AssignSource(*i);
  897. }
  898. // Compute which sources need unique object computation.
  899. this->ComputeObjectNameRequirements(sourceGroups);
  900. // open the project
  901. this->WriteProjectStart(fout, libName, target, sourceGroups);
  902. // write the configuration information
  903. this->WriteConfigurations(fout, libName, target);
  904. fout << "\t<Files>\n";
  905. // Loop through every source group.
  906. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  907. {
  908. cmSourceGroup sg = sourceGroups[i];
  909. this->WriteGroup(&sg, target, fout, libName, configs);
  910. }
  911. //}
  912. fout << "\t</Files>\n";
  913. // Write the VCProj file's footer.
  914. this->WriteVCProjFooter(fout);
  915. }
  916. void cmLocalVisualStudio7Generator
  917. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  918. std::ostream &fout, const char *libName,
  919. std::vector<std::string> *configs)
  920. {
  921. const std::vector<const cmSourceFile *> &sourceFiles =
  922. sg->GetSourceFiles();
  923. // If the group is empty, don't write it at all.
  924. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  925. {
  926. return;
  927. }
  928. // If the group has a name, write the header.
  929. std::string name = sg->GetName();
  930. if(name != "")
  931. {
  932. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  933. }
  934. // Compute the maximum length of a configuration name.
  935. std::string::size_type config_len_max = 0;
  936. for(std::vector<std::string>::iterator i = configs->begin();
  937. i != configs->end(); ++i)
  938. {
  939. if(i->size() > config_len_max)
  940. {
  941. config_len_max = i->size();
  942. }
  943. }
  944. // Compute the maximum length of the full path to the intermediate
  945. // files directory for any configuration. This is used to construct
  946. // object file names that do not produce paths that are too long.
  947. std::string::size_type dir_len = 0;
  948. dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
  949. dir_len += 1;
  950. dir_len += this->GetTargetDirectory(target).size();
  951. dir_len += 1;
  952. dir_len += config_len_max;
  953. dir_len += 1;
  954. // Loop through each source in the source group.
  955. std::string objectName;
  956. for(std::vector<const cmSourceFile *>::const_iterator sf =
  957. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  958. {
  959. std::string source = (*sf)->GetFullPath();
  960. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  961. std::string compileFlags;
  962. std::string additionalDeps;
  963. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  964. {
  965. objectName = this->GetObjectFileNameWithoutTarget(*(*sf), dir_len);
  966. }
  967. else
  968. {
  969. objectName = "";
  970. }
  971. // Add per-source flags.
  972. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  973. if(cflags)
  974. {
  975. compileFlags += " ";
  976. compileFlags += cflags;
  977. }
  978. const char* lang =
  979. this->GlobalGenerator->GetLanguageFromExtension
  980. ((*sf)->GetExtension().c_str());
  981. const char* sourceLang = this->GetSourceFileLanguage(*(*sf));
  982. const char* linkLanguage = target.GetLinkerLanguage
  983. (this->GetGlobalGenerator());
  984. bool needForceLang = false;
  985. // source file does not match its extension language
  986. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  987. {
  988. needForceLang = true;
  989. lang = sourceLang;
  990. }
  991. // If lang is set, the compiler will generate code automatically.
  992. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  993. // the project file
  994. bool excludedFromBuild =
  995. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  996. // if the source file does not match the linker language
  997. // then force c or c++
  998. if(needForceLang || (linkLanguage && lang
  999. && strcmp(lang, linkLanguage) != 0))
  1000. {
  1001. if(strcmp(lang, "CXX") == 0)
  1002. {
  1003. // force a C++ file type
  1004. compileFlags += " /TP ";
  1005. }
  1006. else if(strcmp(lang, "C") == 0)
  1007. {
  1008. // force to c
  1009. compileFlags += " /TC ";
  1010. }
  1011. }
  1012. // Check for extra object-file dependencies.
  1013. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  1014. if(deps)
  1015. {
  1016. std::vector<std::string> depends;
  1017. cmSystemTools::ExpandListArgument(deps, depends);
  1018. if(!depends.empty())
  1019. {
  1020. std::vector<std::string>::iterator i = depends.begin();
  1021. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  1022. for(++i;i != depends.end(); ++i)
  1023. {
  1024. additionalDeps += ";";
  1025. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  1026. }
  1027. }
  1028. }
  1029. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1030. target.GetType() == cmTarget::GLOBAL_TARGET )
  1031. {
  1032. fout << "\t\t\t<File\n";
  1033. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1034. // Tell MS-Dev what the source is. If the compiler knows how to
  1035. // build it, then it will.
  1036. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1037. if (command)
  1038. {
  1039. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  1040. this->WriteCustomRule(fout, source.c_str(), *command, flags);
  1041. }
  1042. else if(compileFlags.size() || additionalDeps.length()
  1043. || objectName.size() || excludedFromBuild)
  1044. {
  1045. const char* aCompilerTool = "VCCLCompilerTool";
  1046. std::string ext = (*sf)->GetExtension();
  1047. ext = cmSystemTools::LowerCase(ext);
  1048. if(ext == "idl")
  1049. {
  1050. aCompilerTool = "VCMIDLTool";
  1051. }
  1052. if(ext == "rc")
  1053. {
  1054. aCompilerTool = "VCResourceCompilerTool";
  1055. }
  1056. if(ext == "def")
  1057. {
  1058. aCompilerTool = "VCCustomBuildTool";
  1059. }
  1060. for(std::vector<std::string>::iterator i = configs->begin();
  1061. i != configs->end(); ++i)
  1062. {
  1063. fout << "\t\t\t\t<FileConfiguration\n"
  1064. << "\t\t\t\t\tName=\"" << *i
  1065. << "|" << this->PlatformName << "\"";
  1066. if(excludedFromBuild)
  1067. {
  1068. fout << " ExcludedFromBuild=\"true\"";
  1069. }
  1070. fout << ">\n";
  1071. fout << "\t\t\t\t\t<Tool\n"
  1072. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1073. if(!compileFlags.empty())
  1074. {
  1075. Options fileOptions(Options::Compiler, this->ExtraFlagTable);
  1076. fileOptions.Parse(compileFlags.c_str());
  1077. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1078. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1079. fileOptions.OutputPreprocessorDefinitions(fout,
  1080. "\t\t\t\t\t", "\n");
  1081. }
  1082. if(additionalDeps.length())
  1083. {
  1084. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1085. << additionalDeps.c_str() << "\"\n";
  1086. }
  1087. if(objectName.size())
  1088. {
  1089. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1090. << objectName.c_str() << "\"\n";
  1091. }
  1092. fout << "\t\t\t\t\t/>\n"
  1093. << "\t\t\t\t</FileConfiguration>\n";
  1094. }
  1095. }
  1096. fout << "\t\t\t</File>\n";
  1097. }
  1098. }
  1099. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  1100. for(unsigned int i=0;i<children.size();++i)
  1101. {
  1102. this->WriteGroup(&children[i], target, fout, libName, configs);
  1103. }
  1104. // If the group has a name, write the footer.
  1105. if(name != "")
  1106. {
  1107. this->WriteVCProjEndGroup(fout);
  1108. }
  1109. }
  1110. void cmLocalVisualStudio7Generator::
  1111. WriteCustomRule(std::ostream& fout,
  1112. const char* source,
  1113. const cmCustomCommand& command,
  1114. const char* compileFlags)
  1115. {
  1116. std::string comment = this->ConstructComment(command);
  1117. // Write the rule for each configuration.
  1118. std::vector<std::string>::iterator i;
  1119. std::vector<std::string> *configs =
  1120. static_cast<cmGlobalVisualStudio7Generator *>
  1121. (this->GlobalGenerator)->GetConfigurations();
  1122. for(i = configs->begin(); i != configs->end(); ++i)
  1123. {
  1124. fout << "\t\t\t\t<FileConfiguration\n";
  1125. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1126. if(compileFlags)
  1127. {
  1128. fout << "\t\t\t\t\t<Tool\n"
  1129. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1130. << "\t\t\t\t\tAdditionalOptions=\""
  1131. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1132. }
  1133. std::string script =
  1134. this->ConstructScript(command.GetCommandLines(),
  1135. command.GetWorkingDirectory(),
  1136. i->c_str(),
  1137. command.GetEscapeOldStyle(),
  1138. command.GetEscapeAllowMakeVars());
  1139. fout << "\t\t\t\t\t<Tool\n"
  1140. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1141. << "\t\t\t\t\tDescription=\""
  1142. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1143. << "\t\t\t\t\tCommandLine=\""
  1144. << this->EscapeForXML(script.c_str()) << "\"\n"
  1145. << "\t\t\t\t\tAdditionalDependencies=\"";
  1146. if(command.GetDepends().empty())
  1147. {
  1148. // There are no real dependencies. Produce an artificial one to
  1149. // make sure the rule runs reliably.
  1150. if(!cmSystemTools::FileExists(source))
  1151. {
  1152. std::ofstream depout(source);
  1153. depout << "Artificial dependency for a custom command.\n";
  1154. }
  1155. fout << this->ConvertToXMLOutputPath(source);
  1156. }
  1157. else
  1158. {
  1159. // Write out the dependencies for the rule.
  1160. for(std::vector<std::string>::const_iterator d =
  1161. command.GetDepends().begin();
  1162. d != command.GetDepends().end();
  1163. ++d)
  1164. {
  1165. // Get the real name of the dependency in case it is a CMake target.
  1166. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1167. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1168. << ";";
  1169. }
  1170. }
  1171. fout << "\"\n";
  1172. fout << "\t\t\t\t\tOutputs=\"";
  1173. if(command.GetOutputs().empty())
  1174. {
  1175. fout << source << "_force";
  1176. }
  1177. else
  1178. {
  1179. // Write a rule for the output generated by this command.
  1180. const char* sep = "";
  1181. for(std::vector<std::string>::const_iterator o =
  1182. command.GetOutputs().begin();
  1183. o != command.GetOutputs().end();
  1184. ++o)
  1185. {
  1186. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1187. sep = ";";
  1188. }
  1189. }
  1190. fout << "\"/>\n";
  1191. fout << "\t\t\t\t</FileConfiguration>\n";
  1192. }
  1193. }
  1194. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1195. const char* group,
  1196. const char* )
  1197. {
  1198. fout << "\t\t<Filter\n"
  1199. << "\t\t\tName=\"" << group << "\"\n"
  1200. << "\t\t\tFilter=\"\">\n";
  1201. }
  1202. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1203. {
  1204. fout << "\t\t</Filter>\n";
  1205. }
  1206. // look for custom rules on a target and collect them together
  1207. void cmLocalVisualStudio7Generator
  1208. ::OutputTargetRules(std::ostream& fout,
  1209. const char* configName,
  1210. cmTarget &target,
  1211. const char * /*libName*/)
  1212. {
  1213. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1214. {
  1215. return;
  1216. }
  1217. // add the pre build rules
  1218. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1219. bool init = false;
  1220. for (std::vector<cmCustomCommand>::const_iterator cr =
  1221. target.GetPreBuildCommands().begin();
  1222. cr != target.GetPreBuildCommands().end(); ++cr)
  1223. {
  1224. if(!init)
  1225. {
  1226. fout << "\nCommandLine=\"";
  1227. init = true;
  1228. }
  1229. else
  1230. {
  1231. fout << this->EscapeForXML("\n");
  1232. }
  1233. std::string script =
  1234. this->ConstructScript(cr->GetCommandLines(),
  1235. cr->GetWorkingDirectory(),
  1236. configName,
  1237. cr->GetEscapeOldStyle(),
  1238. cr->GetEscapeAllowMakeVars());
  1239. fout << this->EscapeForXML(script.c_str()).c_str();
  1240. }
  1241. if (init)
  1242. {
  1243. fout << "\"";
  1244. }
  1245. fout << "/>\n";
  1246. // add the pre Link rules
  1247. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1248. init = false;
  1249. for (std::vector<cmCustomCommand>::const_iterator cr =
  1250. target.GetPreLinkCommands().begin();
  1251. cr != target.GetPreLinkCommands().end(); ++cr)
  1252. {
  1253. if(!init)
  1254. {
  1255. fout << "\nCommandLine=\"";
  1256. init = true;
  1257. }
  1258. else
  1259. {
  1260. fout << this->EscapeForXML("\n");
  1261. }
  1262. std::string script =
  1263. this->ConstructScript(cr->GetCommandLines(),
  1264. cr->GetWorkingDirectory(),
  1265. configName,
  1266. cr->GetEscapeOldStyle(),
  1267. cr->GetEscapeAllowMakeVars());
  1268. fout << this->EscapeForXML(script.c_str()).c_str();
  1269. }
  1270. if (init)
  1271. {
  1272. fout << "\"";
  1273. }
  1274. fout << "/>\n";
  1275. // add the PostBuild rules
  1276. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1277. init = false;
  1278. for (std::vector<cmCustomCommand>::const_iterator cr =
  1279. target.GetPostBuildCommands().begin();
  1280. cr != target.GetPostBuildCommands().end(); ++cr)
  1281. {
  1282. if(!init)
  1283. {
  1284. fout << "\nCommandLine=\"";
  1285. init = true;
  1286. }
  1287. else
  1288. {
  1289. fout << this->EscapeForXML("\n");
  1290. }
  1291. std::string script =
  1292. this->ConstructScript(cr->GetCommandLines(),
  1293. cr->GetWorkingDirectory(),
  1294. configName,
  1295. cr->GetEscapeOldStyle(),
  1296. cr->GetEscapeAllowMakeVars());
  1297. fout << this->EscapeForXML(script.c_str()).c_str();
  1298. }
  1299. if (init)
  1300. {
  1301. fout << "\"";
  1302. }
  1303. fout << "/>\n";
  1304. }
  1305. void
  1306. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1307. const char *libName,
  1308. cmTarget & target,
  1309. std::vector<cmSourceGroup> &)
  1310. {
  1311. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1312. << "<VisualStudioProject\n"
  1313. << "\tProjectType=\"Visual C++\"\n";
  1314. if(this->Version == 71)
  1315. {
  1316. fout << "\tVersion=\"7.10\"\n";
  1317. }
  1318. else
  1319. {
  1320. fout << "\tVersion=\"" << this->Version << ".00\"\n";
  1321. }
  1322. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1323. if(!projLabel)
  1324. {
  1325. projLabel = libName;
  1326. }
  1327. const char* keyword = target.GetProperty("VS_KEYWORD");
  1328. if(!keyword)
  1329. {
  1330. keyword = "Win32Proj";
  1331. }
  1332. cmGlobalVisualStudio7Generator* gg =
  1333. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1334. fout << "\tName=\"" << projLabel << "\"\n";
  1335. if(this->Version >= 8)
  1336. {
  1337. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1338. }
  1339. fout << "\tSccProjectName=\"\"\n"
  1340. << "\tSccLocalPath=\"\"\n"
  1341. << "\tKeyword=\"" << keyword << "\">\n"
  1342. << "\t<Platforms>\n"
  1343. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1344. << "\t</Platforms>\n";
  1345. }
  1346. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1347. {
  1348. fout << "\t<Globals>\n"
  1349. << "\t</Globals>\n"
  1350. << "</VisualStudioProject>\n";
  1351. }
  1352. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1353. {
  1354. std::string ret = s;
  1355. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1356. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1357. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1358. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1359. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1360. return ret;
  1361. }
  1362. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1363. {
  1364. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1365. }
  1366. std::string cmLocalVisualStudio7Generator
  1367. ::ConvertToXMLOutputPath(const char* path)
  1368. {
  1369. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1370. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1371. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1372. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1373. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1374. return ret;
  1375. }
  1376. std::string cmLocalVisualStudio7Generator
  1377. ::ConvertToXMLOutputPathSingle(const char* path)
  1378. {
  1379. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1380. cmSystemTools::ReplaceString(ret, "\"", "");
  1381. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1382. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1383. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1384. return ret;
  1385. }
  1386. // This class is used to parse an existing vs 7 project
  1387. // and extract the GUID
  1388. class cmVS7XMLParser : public cmXMLParser
  1389. {
  1390. public:
  1391. virtual void EndElement(const char* /* name */)
  1392. {
  1393. }
  1394. virtual void StartElement(const char* name, const char** atts)
  1395. {
  1396. // once the GUID is found do nothing
  1397. if(this->GUID.size())
  1398. {
  1399. return;
  1400. }
  1401. int i =0;
  1402. if(strcmp("VisualStudioProject", name) == 0)
  1403. {
  1404. while(atts[i])
  1405. {
  1406. if(strcmp(atts[i], "ProjectGUID") == 0)
  1407. {
  1408. if(atts[i+1])
  1409. {
  1410. this->GUID = atts[i+1];
  1411. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1412. }
  1413. else
  1414. {
  1415. this->GUID = "";
  1416. }
  1417. return;
  1418. }
  1419. ++i;
  1420. }
  1421. }
  1422. }
  1423. int InitializeParser()
  1424. {
  1425. int ret = cmXMLParser::InitializeParser();
  1426. if(ret == 0)
  1427. {
  1428. return ret;
  1429. }
  1430. // visual studio projects have a strange encoding, but it is
  1431. // really utf-8
  1432. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1433. return 1;
  1434. }
  1435. std::string GUID;
  1436. };
  1437. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1438. const char* name,
  1439. const char* path)
  1440. {
  1441. cmVS7XMLParser parser;
  1442. parser.ParseFile(path);
  1443. // if we can not find a GUID then create one
  1444. if(parser.GUID.size() == 0)
  1445. {
  1446. cmGlobalVisualStudio7Generator* gg =
  1447. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1448. gg->CreateGUID(name);
  1449. return;
  1450. }
  1451. std::string guidStoreName = name;
  1452. guidStoreName += "_GUID_CMAKE";
  1453. // save the GUID in the cache
  1454. this->GlobalGenerator->GetCMakeInstance()->
  1455. AddCacheEntry(guidStoreName.c_str(),
  1456. parser.GUID.c_str(),
  1457. "Stored GUID",
  1458. cmCacheManager::INTERNAL);
  1459. }
  1460. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1461. {
  1462. cmLocalGenerator::ConfigureFinalPass();
  1463. cmTargets &tgts = this->Makefile->GetTargets();
  1464. cmGlobalVisualStudio7Generator* gg =
  1465. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1466. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1467. {
  1468. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1469. {
  1470. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1471. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1472. std::string project_name = cmds[0][0];
  1473. this->ReadAndStoreExternalGUID(project_name.c_str(),
  1474. cmds[0][1].c_str());
  1475. }
  1476. else
  1477. {
  1478. gg->CreateGUID(l->first.c_str());
  1479. }
  1480. }
  1481. }
  1482. //----------------------------------------------------------------------------
  1483. std::string cmLocalVisualStudio7Generator
  1484. ::GetTargetDirectory(cmTarget const& target) const
  1485. {
  1486. std::string dir;
  1487. dir += target.GetName();
  1488. dir += ".dir";
  1489. return dir;
  1490. }
  1491. //----------------------------------------------------------------------------
  1492. cmLocalVisualStudio7GeneratorOptions
  1493. ::cmLocalVisualStudio7GeneratorOptions(Tool tool,
  1494. cmVS7FlagTable const* extraTable):
  1495. CurrentTool(tool),
  1496. DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable)
  1497. {
  1498. // Choose the flag table for the requested tool.
  1499. switch(tool)
  1500. {
  1501. case Compiler:
  1502. this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
  1503. case Linker:
  1504. this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
  1505. default: break;
  1506. }
  1507. }
  1508. //----------------------------------------------------------------------------
  1509. void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
  1510. {
  1511. // Exception handling is on by default because the platform file has
  1512. // "/EHsc" in the flags. Normally, that will override this
  1513. // initialization to off, but the user has the option of removing
  1514. // the flag to disable exception handling. When the user does
  1515. // remove the flag we need to override the IDE default of on.
  1516. this->FlagMap["ExceptionHandling"] = "FALSE";
  1517. }
  1518. //----------------------------------------------------------------------------
  1519. void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
  1520. {
  1521. // If verbose makefiles have been requested and the /nologo option
  1522. // was not given explicitly in the flags we want to add an attribute
  1523. // to the generated project to disable logo suppression. Otherwise
  1524. // the GUI default is to enable suppression.
  1525. if(verbose &&
  1526. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  1527. {
  1528. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  1529. }
  1530. }
  1531. //----------------------------------------------------------------------------
  1532. void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
  1533. {
  1534. this->Defines.push_back(def);
  1535. }
  1536. //----------------------------------------------------------------------------
  1537. void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
  1538. const char* value)
  1539. {
  1540. this->FlagMap[flag] = value;
  1541. }
  1542. //----------------------------------------------------------------------------
  1543. bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
  1544. {
  1545. // Look for the a _UNICODE definition.
  1546. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1547. di != this->Defines.end(); ++di)
  1548. {
  1549. if(*di == "_UNICODE")
  1550. {
  1551. return true;
  1552. }
  1553. }
  1554. return false;
  1555. }
  1556. //----------------------------------------------------------------------------
  1557. void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
  1558. {
  1559. // Parse the input string as a windows command line since the string
  1560. // is intended for writing directly into the build files.
  1561. std::vector<std::string> args;
  1562. cmSystemTools::ParseWindowsCommandLine(flags, args);
  1563. // Process flags that need to be represented specially in the IDE
  1564. // project file.
  1565. for(std::vector<std::string>::iterator ai = args.begin();
  1566. ai != args.end(); ++ai)
  1567. {
  1568. this->HandleFlag(ai->c_str());
  1569. }
  1570. }
  1571. //----------------------------------------------------------------------------
  1572. void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
  1573. {
  1574. // If the last option was -D then this option is the definition.
  1575. if(this->DoingDefine)
  1576. {
  1577. this->DoingDefine = false;
  1578. this->Defines.push_back(flag);
  1579. return;
  1580. }
  1581. // Look for known arguments.
  1582. if(flag[0] == '-' || flag[0] == '/')
  1583. {
  1584. // Look for preprocessor definitions.
  1585. if(this->CurrentTool == Compiler && flag[1] == 'D')
  1586. {
  1587. if(flag[2] == '\0')
  1588. {
  1589. // The next argument will have the definition.
  1590. this->DoingDefine = true;
  1591. }
  1592. else
  1593. {
  1594. // Store this definition.
  1595. this->Defines.push_back(flag+2);
  1596. }
  1597. return;
  1598. }
  1599. // Look through the available flag tables.
  1600. bool flag_handled = false;
  1601. if(this->FlagTable &&
  1602. this->CheckFlagTable(this->FlagTable, flag, flag_handled))
  1603. {
  1604. return;
  1605. }
  1606. if(this->ExtraFlagTable &&
  1607. this->CheckFlagTable(this->ExtraFlagTable, flag, flag_handled))
  1608. {
  1609. return;
  1610. }
  1611. // If any map entry handled the flag we are done.
  1612. if(flag_handled)
  1613. {
  1614. return;
  1615. }
  1616. }
  1617. // This option is not known. Store it in the output flags.
  1618. this->FlagString += " ";
  1619. this->FlagString +=
  1620. cmSystemTools::EscapeWindowsShellArgument(flag,
  1621. cmsysSystem_Shell_Flag_VSIDE);
  1622. }
  1623. //----------------------------------------------------------------------------
  1624. bool
  1625. cmLocalVisualStudio7GeneratorOptions
  1626. ::CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  1627. bool& flag_handled)
  1628. {
  1629. // Look for an entry in the flag table matching this flag.
  1630. for(cmVS7FlagTable const* entry = table; entry->IDEName; ++entry)
  1631. {
  1632. bool entry_found = false;
  1633. if(entry->special & cmVS7FlagTable::UserValue)
  1634. {
  1635. // This flag table entry accepts a user-specified value. If
  1636. // the entry specifies UserRequired we must match only if a
  1637. // non-empty value is given.
  1638. int n = static_cast<int>(strlen(entry->commandFlag));
  1639. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  1640. (!(entry->special & cmVS7FlagTable::UserRequired) ||
  1641. static_cast<int>(strlen(flag+1)) > n))
  1642. {
  1643. if(entry->special & cmVS7FlagTable::UserIgnored)
  1644. {
  1645. // Ignore the user-specified value.
  1646. this->FlagMap[entry->IDEName] = entry->value;
  1647. }
  1648. else
  1649. {
  1650. // Use the user-specified value.
  1651. this->FlagMap[entry->IDEName] = flag+1+n;
  1652. }
  1653. entry_found = true;
  1654. }
  1655. }
  1656. else if(strcmp(flag+1, entry->commandFlag) == 0)
  1657. {
  1658. // This flag table entry provides a fixed value.
  1659. this->FlagMap[entry->IDEName] = entry->value;
  1660. entry_found = true;
  1661. }
  1662. // If the flag has been handled by an entry not requesting a
  1663. // search continuation we are done.
  1664. if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
  1665. {
  1666. return true;
  1667. }
  1668. // If the entry was found the flag has been handled.
  1669. flag_handled = flag_handled || entry_found;
  1670. }
  1671. return false;
  1672. }
  1673. //----------------------------------------------------------------------------
  1674. void
  1675. cmLocalVisualStudio7GeneratorOptions
  1676. ::OutputPreprocessorDefinitions(std::ostream& fout,
  1677. const char* prefix,
  1678. const char* suffix)
  1679. {
  1680. if(this->Defines.empty())
  1681. {
  1682. return;
  1683. }
  1684. fout << prefix << "PreprocessorDefinitions=\"";
  1685. const char* comma = "";
  1686. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1687. di != this->Defines.end(); ++di)
  1688. {
  1689. // Double-quotes in the value of the definition must be escaped
  1690. // with a backslash.
  1691. std::string define = di->c_str();
  1692. cmSystemTools::ReplaceString(define, "\"", "\\\"");
  1693. // Escape this flag for the IDE.
  1694. define = cmLocalVisualStudio7GeneratorEscapeForXML(define.c_str());
  1695. // Write this flag. Quote it if the definition is not
  1696. // alphanumeric.
  1697. if(define.find_first_not_of(
  1698. "-_abcdefghigklmnopqrstuvwxyz1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZ")
  1699. != define.npos)
  1700. {
  1701. fout << comma << "&quot;" << define << "&quot;";
  1702. }
  1703. else
  1704. {
  1705. fout << comma << define;
  1706. }
  1707. comma = ",";
  1708. }
  1709. fout << "\"" << suffix;
  1710. }
  1711. //----------------------------------------------------------------------------
  1712. void
  1713. cmLocalVisualStudio7GeneratorOptions
  1714. ::OutputFlagMap(std::ostream& fout, const char* indent)
  1715. {
  1716. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  1717. m != this->FlagMap.end(); ++m)
  1718. {
  1719. fout << indent << m->first << "=\"" << m->second << "\"\n";
  1720. }
  1721. }
  1722. //----------------------------------------------------------------------------
  1723. void
  1724. cmLocalVisualStudio7GeneratorOptions
  1725. ::OutputAdditionalOptions(std::ostream& fout,
  1726. const char* prefix,
  1727. const char* suffix)
  1728. {
  1729. if(!this->FlagString.empty())
  1730. {
  1731. fout << prefix << "AdditionalOptions=\"";
  1732. fout <<
  1733. cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
  1734. fout << "\"" << suffix;
  1735. }
  1736. }
  1737. void cmLocalVisualStudio7Generator::
  1738. GetTargetObjectFileDirectories(cmTarget* target,
  1739. std::vector<std::string>&
  1740. dirs)
  1741. {
  1742. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1743. dir += "/";
  1744. dir += this->GetTargetDirectory(*target);
  1745. dir += "/";
  1746. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1747. dirs.push_back(dir);
  1748. }