cmLocalVisualStudio7Generator.cxx 66 KB

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