cmLocalVisualStudio7Generator.cxx 66 KB

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