cmLocalVisualStudio7Generator.cxx 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  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 = (this->FortranProject? "Fortran":
  557. target.GetLinkerLanguage(configName));
  558. if(!linkLanguage)
  559. {
  560. cmSystemTools::Error
  561. ("CMake can not determine linker language for target:",
  562. target.GetName());
  563. return;
  564. }
  565. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  566. || strcmp(linkLanguage, "Fortran") == 0)
  567. {
  568. std::string baseFlagVar = "CMAKE_";
  569. baseFlagVar += linkLanguage;
  570. baseFlagVar += "_FLAGS";
  571. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  572. std::string flagVar = baseFlagVar + std::string("_") +
  573. cmSystemTools::UpperCase(configName);
  574. flags += " ";
  575. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  576. }
  577. // set the correct language
  578. if(strcmp(linkLanguage, "C") == 0)
  579. {
  580. flags += " /TC ";
  581. }
  582. if(strcmp(linkLanguage, "CXX") == 0)
  583. {
  584. flags += " /TP ";
  585. }
  586. }
  587. // Add the target-specific flags.
  588. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  589. {
  590. flags += " ";
  591. flags += targetFlags;
  592. }
  593. std::string configUpper = cmSystemTools::UpperCase(configName);
  594. std::string defPropName = "COMPILE_DEFINITIONS_";
  595. defPropName += configUpper;
  596. // Get preprocessor definitions for this directory.
  597. std::string defineFlags = this->Makefile->GetDefineFlags();
  598. Options::Tool t = Options::Compiler;
  599. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  600. if(this->FortranProject)
  601. {
  602. t = Options::FortranCompiler;
  603. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  604. }
  605. Options targetOptions(this, this->Version, t,
  606. table,
  607. this->ExtraFlagTable);
  608. targetOptions.FixExceptionHandlingDefault();
  609. targetOptions.Parse(flags.c_str());
  610. targetOptions.Parse(defineFlags.c_str());
  611. targetOptions.AddDefines
  612. (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
  613. targetOptions.AddDefines(target.GetProperty("COMPILE_DEFINITIONS"));
  614. targetOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
  615. targetOptions.AddDefines(target.GetProperty(defPropName.c_str()));
  616. targetOptions.SetVerboseMakefile(
  617. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  618. // Add a definition for the configuration name.
  619. std::string configDefine = "CMAKE_INTDIR=\"";
  620. configDefine += configName;
  621. configDefine += "\"";
  622. targetOptions.AddDefine(configDefine);
  623. // Add the export symbol definition for shared library objects.
  624. if(const char* exportMacro = target.GetExportMacro())
  625. {
  626. targetOptions.AddDefine(exportMacro);
  627. }
  628. // The intermediate directory name consists of a directory for the
  629. // target and a subdirectory for the configuration name.
  630. std::string intermediateDir = this->GetTargetDirectory(target);
  631. intermediateDir += "/";
  632. intermediateDir += configName;
  633. fout << "\t\t\tIntermediateDirectory=\""
  634. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  635. << "\"\n"
  636. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  637. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  638. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  639. // If unicode is enabled change the character set to unicode, if not
  640. // then default to MBCS.
  641. if(targetOptions.UsingUnicode())
  642. {
  643. fout << "\t\t\tCharacterSet=\"1\">\n";
  644. }
  645. else
  646. {
  647. fout << "\t\t\tCharacterSet=\"2\">\n";
  648. }
  649. const char* tool = "VCCLCompilerTool";
  650. if(this->FortranProject)
  651. {
  652. tool = "VFFortranCompilerTool";
  653. }
  654. fout << "\t\t\t<Tool\n"
  655. << "\t\t\t\tName=\"" << tool << "\"\n";
  656. if(this->FortranProject)
  657. {
  658. const char* target_mod_dir =
  659. target.GetProperty("Fortran_MODULE_DIRECTORY");
  660. std::string modDir;
  661. if(target_mod_dir)
  662. {
  663. modDir = this->Convert(target_mod_dir,
  664. cmLocalGenerator::START_OUTPUT,
  665. cmLocalGenerator::UNCHANGED);
  666. }
  667. else
  668. {
  669. modDir = ".";
  670. }
  671. fout << "\t\t\t\tModulePath=\""
  672. << this->ConvertToXMLOutputPath(modDir.c_str())
  673. << "\\$(ConfigurationName)\"\n";
  674. }
  675. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  676. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  677. std::vector<std::string> includes;
  678. this->GetIncludeDirectories(includes);
  679. std::vector<std::string>::iterator i = includes.begin();
  680. for(;i != includes.end(); ++i)
  681. {
  682. // output the include path
  683. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  684. fout << ipath << ";";
  685. // if this is fortran then output the include with
  686. // a ConfigurationName on the end of it.
  687. if(this->FortranProject)
  688. {
  689. ipath = i->c_str();
  690. ipath += "/$(ConfigurationName)";
  691. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  692. fout << ipath << ";";
  693. }
  694. }
  695. fout << "\"\n";
  696. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  697. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  698. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  699. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  700. if(targetBuilds)
  701. {
  702. // We need to specify a program database file name even for
  703. // non-debug configurations because VS still creates .idb files.
  704. fout << "\t\t\t\tProgramDataBaseFileName=\""
  705. << target.GetDirectory(configName) << "/"
  706. << target.GetPDBName(configName) << "\"\n";
  707. }
  708. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  709. tool = "VCCustomBuildTool";
  710. if(this->FortranProject)
  711. {
  712. tool = "VFCustomBuildTool";
  713. }
  714. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  715. tool = "VCResourceCompilerTool";
  716. if(this->FortranProject)
  717. {
  718. tool = "VFResourceCompilerTool";
  719. }
  720. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  721. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  722. for(i = includes.begin();i != includes.end(); ++i)
  723. {
  724. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  725. fout << ipath << ";";
  726. }
  727. // add the -D flags to the RC tool
  728. fout << "\"";
  729. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  730. fout << "/>\n";
  731. tool = "VCMIDLTool";
  732. if(this->FortranProject)
  733. {
  734. tool = "VFMIDLTool";
  735. }
  736. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  737. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  738. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  739. if( this->PlatformName == "x64" )
  740. {
  741. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  742. }
  743. else if( this->PlatformName == "ia64" )
  744. {
  745. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  746. }
  747. else
  748. {
  749. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  750. }
  751. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  752. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  753. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  754. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  755. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  756. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  757. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  758. // end of <Tool Name=VCMIDLTool
  759. // Check if we need the FAT32 workaround.
  760. if(targetBuilds && this->Version >= 8)
  761. {
  762. // Check the filesystem type where the target will be written.
  763. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  764. {
  765. // Add a flag telling the manifest tool to use a workaround
  766. // for FAT32 file systems, which can cause an empty manifest
  767. // to be embedded into the resulting executable. See CMake
  768. // bug #2617.
  769. const char* tool = "VCManifestTool";
  770. if(this->FortranProject)
  771. {
  772. tool = "VFManifestTool";
  773. }
  774. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  775. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  776. << "\t\t\t/>\n";
  777. }
  778. }
  779. this->OutputTargetRules(fout, configName, target, libName);
  780. this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
  781. fout << "\t\t</Configuration>\n";
  782. }
  783. //----------------------------------------------------------------------------
  784. std::string
  785. cmLocalVisualStudio7Generator
  786. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  787. {
  788. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  789. std::string extraLinkOptionsBuildTypeDef =
  790. rootLinkerFlags + "_" + configTypeUpper;
  791. std::string extraLinkOptionsBuildType =
  792. this->Makefile->GetRequiredDefinition
  793. (extraLinkOptionsBuildTypeDef.c_str());
  794. return extraLinkOptionsBuildType;
  795. }
  796. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  797. const char* configName,
  798. cmTarget &target,
  799. bool isDebug)
  800. {
  801. cmGlobalVisualStudio7Generator* gg =
  802. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  803. std::string temp;
  804. std::string extraLinkOptions;
  805. if(target.GetType() == cmTarget::EXECUTABLE)
  806. {
  807. extraLinkOptions =
  808. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  809. + std::string(" ")
  810. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  811. }
  812. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  813. {
  814. extraLinkOptions =
  815. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  816. + std::string(" ")
  817. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  818. }
  819. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  820. {
  821. extraLinkOptions =
  822. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  823. + std::string(" ")
  824. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  825. }
  826. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  827. if(targetLinkFlags)
  828. {
  829. extraLinkOptions += " ";
  830. extraLinkOptions += targetLinkFlags;
  831. }
  832. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  833. std::string linkFlagsConfig = "LINK_FLAGS_";
  834. linkFlagsConfig += configTypeUpper;
  835. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  836. if(targetLinkFlags)
  837. {
  838. extraLinkOptions += " ";
  839. extraLinkOptions += targetLinkFlags;
  840. }
  841. Options linkOptions(this, this->Version, Options::Linker,
  842. cmLocalVisualStudio7GeneratorLinkFlagTable);
  843. linkOptions.Parse(extraLinkOptions.c_str());
  844. if(!this->ModuleDefinitionFile.empty())
  845. {
  846. std::string defFile =
  847. this->ConvertToXMLOutputPath(this->ModuleDefinitionFile.c_str());
  848. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  849. }
  850. switch(target.GetType())
  851. {
  852. case cmTarget::STATIC_LIBRARY:
  853. {
  854. std::string targetNameFull = target.GetFullName(configName);
  855. std::string libpath = target.GetDirectory(configName);
  856. libpath += "/";
  857. libpath += targetNameFull;
  858. const char* tool = "VCLibrarianTool";
  859. if(this->FortranProject)
  860. {
  861. tool = "VFLibrarianTool";
  862. }
  863. fout << "\t\t\t<Tool\n"
  864. << "\t\t\t\tName=\"" << tool << "\"\n";
  865. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  866. {
  867. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  868. }
  869. fout << "\t\t\t\tOutputFile=\""
  870. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  871. break;
  872. }
  873. case cmTarget::SHARED_LIBRARY:
  874. case cmTarget::MODULE_LIBRARY:
  875. {
  876. std::string targetName;
  877. std::string targetNameSO;
  878. std::string targetNameFull;
  879. std::string targetNameImport;
  880. std::string targetNamePDB;
  881. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  882. targetNameImport, targetNamePDB, configName);
  883. // Compute the link library and directory information.
  884. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  885. if(!pcli)
  886. {
  887. return;
  888. }
  889. cmComputeLinkInformation& cli = *pcli;
  890. const char* linkLanguage = cli.GetLinkLanguage();
  891. // Compute the variable name to lookup standard libraries for this
  892. // language.
  893. std::string standardLibsVar = "CMAKE_";
  894. standardLibsVar += linkLanguage;
  895. standardLibsVar += "_STANDARD_LIBRARIES";
  896. const char* tool = "VCLinkerTool";
  897. if(this->FortranProject)
  898. {
  899. tool = "VFLinkerTool";
  900. }
  901. fout << "\t\t\t<Tool\n"
  902. << "\t\t\t\tName=\"" << tool << "\"\n";
  903. if(!gg->NeedLinkLibraryDependencies(target))
  904. {
  905. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  906. }
  907. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  908. // Use the NOINHERIT macro to avoid getting VS project default
  909. // libraries which may be set by the user to something bad.
  910. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  911. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  912. << " ";
  913. this->Internal->OutputLibraries(fout, cli.GetItems());
  914. fout << "\"\n";
  915. temp = target.GetDirectory(configName);
  916. temp += "/";
  917. temp += targetNameFull;
  918. fout << "\t\t\t\tOutputFile=\""
  919. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  920. this->WriteTargetVersionAttribute(fout, target);
  921. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  922. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  923. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  924. fout << "\"\n";
  925. temp = target.GetDirectory(configName);
  926. temp += "/";
  927. temp += targetNamePDB;
  928. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  929. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  930. if(isDebug)
  931. {
  932. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  933. }
  934. std::string stackVar = "CMAKE_";
  935. stackVar += linkLanguage;
  936. stackVar += "_STACK_SIZE";
  937. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  938. if(stackVal)
  939. {
  940. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  941. }
  942. temp = target.GetDirectory(configName, true);
  943. temp += "/";
  944. temp += targetNameImport;
  945. fout << "\t\t\t\tImportLibrary=\""
  946. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  947. }
  948. break;
  949. case cmTarget::EXECUTABLE:
  950. {
  951. std::string targetName;
  952. std::string targetNameFull;
  953. std::string targetNameImport;
  954. std::string targetNamePDB;
  955. target.GetExecutableNames(targetName, targetNameFull,
  956. targetNameImport, targetNamePDB, configName);
  957. // Compute the link library and directory information.
  958. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  959. if(!pcli)
  960. {
  961. return;
  962. }
  963. cmComputeLinkInformation& cli = *pcli;
  964. const char* linkLanguage = cli.GetLinkLanguage();
  965. // Compute the variable name to lookup standard libraries for this
  966. // language.
  967. std::string standardLibsVar = "CMAKE_";
  968. standardLibsVar += linkLanguage;
  969. standardLibsVar += "_STANDARD_LIBRARIES";
  970. const char* tool = "VCLinkerTool";
  971. if(this->FortranProject)
  972. {
  973. tool = "VFLinkerTool";
  974. }
  975. fout << "\t\t\t<Tool\n"
  976. << "\t\t\t\tName=\"" << tool << "\"\n";
  977. if(!gg->NeedLinkLibraryDependencies(target))
  978. {
  979. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  980. }
  981. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  982. // Use the NOINHERIT macro to avoid getting VS project default
  983. // libraries which may be set by the user to something bad.
  984. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  985. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  986. << " ";
  987. this->Internal->OutputLibraries(fout, cli.GetItems());
  988. fout << "\"\n";
  989. temp = target.GetDirectory(configName);
  990. temp += "/";
  991. temp += targetNameFull;
  992. fout << "\t\t\t\tOutputFile=\""
  993. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  994. this->WriteTargetVersionAttribute(fout, target);
  995. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  996. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  997. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  998. fout << "\"\n";
  999. fout << "\t\t\t\tProgramDataBaseFile=\""
  1000. << target.GetDirectory(configName) << "/" << targetNamePDB
  1001. << "\"\n";
  1002. if(isDebug)
  1003. {
  1004. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  1005. }
  1006. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1007. {
  1008. fout << "\t\t\t\tSubSystem=\"2\"\n";
  1009. }
  1010. else
  1011. {
  1012. fout << "\t\t\t\tSubSystem=\"1\"\n";
  1013. }
  1014. std::string stackVar = "CMAKE_";
  1015. stackVar += linkLanguage;
  1016. stackVar += "_STACK_SIZE";
  1017. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1018. if(stackVal)
  1019. {
  1020. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1021. }
  1022. temp = target.GetDirectory(configName, true);
  1023. temp += "/";
  1024. temp += targetNameImport;
  1025. fout << "\t\t\t\tImportLibrary=\""
  1026. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1027. break;
  1028. }
  1029. case cmTarget::UTILITY:
  1030. case cmTarget::GLOBAL_TARGET:
  1031. break;
  1032. }
  1033. }
  1034. //----------------------------------------------------------------------------
  1035. void
  1036. cmLocalVisualStudio7Generator
  1037. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1038. {
  1039. int major;
  1040. int minor;
  1041. target.GetTargetVersion(major, minor);
  1042. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1043. }
  1044. //----------------------------------------------------------------------------
  1045. void
  1046. cmLocalVisualStudio7GeneratorInternals
  1047. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1048. {
  1049. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1050. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1051. {
  1052. if(l->IsPath)
  1053. {
  1054. std::string rel = lg->Convert(l->Value.c_str(),
  1055. cmLocalGenerator::START_OUTPUT,
  1056. cmLocalGenerator::UNCHANGED);
  1057. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1058. }
  1059. else
  1060. {
  1061. fout << l->Value << " ";
  1062. }
  1063. }
  1064. }
  1065. //----------------------------------------------------------------------------
  1066. void
  1067. cmLocalVisualStudio7Generator
  1068. ::OutputLibraryDirectories(std::ostream& fout,
  1069. std::vector<std::string> const& dirs)
  1070. {
  1071. const char* comma = "";
  1072. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1073. d != dirs.end(); ++d)
  1074. {
  1075. // Remove any trailing slash and skip empty paths.
  1076. std::string dir = *d;
  1077. if(dir[dir.size()-1] == '/')
  1078. {
  1079. dir = dir.substr(0, dir.size()-1);
  1080. }
  1081. if(dir.empty())
  1082. {
  1083. continue;
  1084. }
  1085. // Switch to a relative path specification if it is shorter.
  1086. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1087. {
  1088. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1089. if(rel.size() < dir.size())
  1090. {
  1091. dir = rel;
  1092. }
  1093. }
  1094. // First search a configuration-specific subdirectory and then the
  1095. // original directory.
  1096. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1097. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1098. comma = ",";
  1099. }
  1100. }
  1101. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1102. const char *libName,
  1103. cmTarget &target)
  1104. {
  1105. // get the configurations
  1106. std::vector<std::string> *configs =
  1107. static_cast<cmGlobalVisualStudio7Generator *>
  1108. (this->GlobalGenerator)->GetConfigurations();
  1109. // We may be modifying the source groups temporarily, so make a copy.
  1110. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1111. // get the classes from the source lists then add them to the groups
  1112. this->ModuleDefinitionFile = "";
  1113. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  1114. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1115. i != classes.end(); i++)
  1116. {
  1117. // Add the file to the list of sources.
  1118. std::string source = (*i)->GetFullPath();
  1119. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1120. {
  1121. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1122. }
  1123. cmSourceGroup& sourceGroup =
  1124. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1125. sourceGroup.AssignSource(*i);
  1126. }
  1127. // Compute which sources need unique object computation.
  1128. this->ComputeObjectNameRequirements(sourceGroups);
  1129. // open the project
  1130. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1131. // write the configuration information
  1132. this->WriteConfigurations(fout, libName, target);
  1133. fout << "\t<Files>\n";
  1134. // Loop through every source group.
  1135. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1136. {
  1137. cmSourceGroup sg = sourceGroups[i];
  1138. this->WriteGroup(&sg, target, fout, libName, configs);
  1139. }
  1140. //}
  1141. fout << "\t</Files>\n";
  1142. // Write the VCProj file's footer.
  1143. this->WriteVCProjFooter(fout);
  1144. }
  1145. struct cmLVS7GFileConfig
  1146. {
  1147. std::string ObjectName;
  1148. std::string CompileFlags;
  1149. std::string CompileDefs;
  1150. std::string CompileDefsConfig;
  1151. std::string AdditionalDeps;
  1152. bool ExcludedFromBuild;
  1153. };
  1154. class cmLocalVisualStudio7GeneratorFCInfo
  1155. {
  1156. public:
  1157. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1158. cmTarget& target,
  1159. cmSourceFile const& sf,
  1160. std::vector<std::string>* configs,
  1161. std::string const& dir_max);
  1162. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1163. };
  1164. cmLocalVisualStudio7GeneratorFCInfo
  1165. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1166. cmTarget& target,
  1167. cmSourceFile const& sf,
  1168. std::vector<std::string>* configs,
  1169. std::string const& dir_max)
  1170. {
  1171. std::string objectName;
  1172. if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
  1173. {
  1174. objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max);
  1175. }
  1176. // Compute per-source, per-config information.
  1177. for(std::vector<std::string>::iterator i = configs->begin();
  1178. i != configs->end(); ++i)
  1179. {
  1180. std::string configUpper = cmSystemTools::UpperCase(*i);
  1181. cmLVS7GFileConfig fc;
  1182. bool needfc = false;
  1183. if(!objectName.empty())
  1184. {
  1185. fc.ObjectName = objectName;
  1186. needfc = true;
  1187. }
  1188. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1189. {
  1190. fc.CompileFlags = cflags;
  1191. needfc = true;
  1192. }
  1193. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1194. {
  1195. fc.CompileDefs = cdefs;
  1196. needfc = true;
  1197. }
  1198. std::string defPropName = "COMPILE_DEFINITIONS_";
  1199. defPropName += configUpper;
  1200. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1201. {
  1202. fc.CompileDefsConfig = ccdefs;
  1203. needfc = true;
  1204. }
  1205. // Check for extra object-file dependencies.
  1206. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1207. {
  1208. std::vector<std::string> depends;
  1209. cmSystemTools::ExpandListArgument(deps, depends);
  1210. const char* sep = "";
  1211. for(std::vector<std::string>::iterator j = depends.begin();
  1212. j != depends.end(); ++j)
  1213. {
  1214. fc.AdditionalDeps += sep;
  1215. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1216. sep = ";";
  1217. needfc = true;
  1218. }
  1219. }
  1220. const char* lang =
  1221. lg->GlobalGenerator->GetLanguageFromExtension
  1222. (sf.GetExtension().c_str());
  1223. const char* sourceLang = lg->GetSourceFileLanguage(sf);
  1224. const char* linkLanguage = target.GetLinkerLanguage(i->c_str());
  1225. bool needForceLang = false;
  1226. // source file does not match its extension language
  1227. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1228. {
  1229. needForceLang = true;
  1230. lang = sourceLang;
  1231. }
  1232. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1233. // the project file
  1234. fc.ExcludedFromBuild =
  1235. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1236. if(fc.ExcludedFromBuild)
  1237. {
  1238. needfc = true;
  1239. }
  1240. // if the source file does not match the linker language
  1241. // then force c or c++
  1242. if(needForceLang || (linkLanguage && lang
  1243. && strcmp(lang, linkLanguage) != 0))
  1244. {
  1245. if(strcmp(lang, "CXX") == 0)
  1246. {
  1247. // force a C++ file type
  1248. fc.CompileFlags += " /TP ";
  1249. needfc = true;
  1250. }
  1251. else if(strcmp(lang, "C") == 0)
  1252. {
  1253. // force to c
  1254. fc.CompileFlags += " /TC ";
  1255. needfc = true;
  1256. }
  1257. }
  1258. if(needfc)
  1259. {
  1260. this->FileConfigMap[*i] = fc;
  1261. }
  1262. }
  1263. }
  1264. void cmLocalVisualStudio7Generator
  1265. ::ComputeMaxDirectoryLength(std::string& maxdir,
  1266. cmTarget& target)
  1267. {
  1268. std::vector<std::string> *configs =
  1269. static_cast<cmGlobalVisualStudio7Generator *>
  1270. (this->GlobalGenerator)->GetConfigurations();
  1271. // Compute the maximum length configuration name.
  1272. std::string config_max;
  1273. for(std::vector<std::string>::iterator i = configs->begin();
  1274. i != configs->end(); ++i)
  1275. {
  1276. if(i->size() > config_max.size())
  1277. {
  1278. config_max = *i;
  1279. }
  1280. }
  1281. // Compute the maximum length full path to the intermediate
  1282. // files directory for any configuration. This is used to construct
  1283. // object file names that do not produce paths that are too long.
  1284. std::string dir_max;
  1285. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1286. dir_max += "/";
  1287. dir_max += this->GetTargetDirectory(target);
  1288. dir_max += "/";
  1289. dir_max += config_max;
  1290. dir_max += "/";
  1291. maxdir = dir_max;
  1292. }
  1293. void cmLocalVisualStudio7Generator
  1294. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1295. std::ostream &fout, const char *libName,
  1296. std::vector<std::string> *configs)
  1297. {
  1298. const std::vector<const cmSourceFile *> &sourceFiles =
  1299. sg->GetSourceFiles();
  1300. // If the group is empty, don't write it at all.
  1301. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1302. {
  1303. return;
  1304. }
  1305. // If the group has a name, write the header.
  1306. std::string name = sg->GetName();
  1307. if(name != "")
  1308. {
  1309. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1310. }
  1311. // Compute the maximum length full path to the intermediate
  1312. // files directory for any configuration. This is used to construct
  1313. // object file names that do not produce paths that are too long.
  1314. std::string dir_max;
  1315. this->ComputeMaxDirectoryLength(dir_max, target);
  1316. // Loop through each source in the source group.
  1317. std::string objectName;
  1318. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1319. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1320. {
  1321. std::string source = (*sf)->GetFullPath();
  1322. FCInfo fcinfo(this, target, *(*sf), configs, dir_max);
  1323. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1324. target.GetType() == cmTarget::GLOBAL_TARGET )
  1325. {
  1326. fout << "\t\t\t<File\n";
  1327. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1328. // Tell MS-Dev what the source is. If the compiler knows how to
  1329. // build it, then it will.
  1330. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1331. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1332. {
  1333. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1334. }
  1335. else if(!fcinfo.FileConfigMap.empty())
  1336. {
  1337. const char* aCompilerTool = "VCCLCompilerTool";
  1338. if(this->FortranProject)
  1339. {
  1340. aCompilerTool = "VFFortranCompilerTool";
  1341. }
  1342. std::string ext = (*sf)->GetExtension();
  1343. ext = cmSystemTools::LowerCase(ext);
  1344. if(ext == "idl")
  1345. {
  1346. aCompilerTool = "VCMIDLTool";
  1347. if(this->FortranProject)
  1348. {
  1349. aCompilerTool = "VFMIDLTool";
  1350. }
  1351. }
  1352. if(ext == "rc")
  1353. {
  1354. aCompilerTool = "VCResourceCompilerTool";
  1355. if(this->FortranProject)
  1356. {
  1357. aCompilerTool = "VFResourceCompilerTool";
  1358. }
  1359. }
  1360. if(ext == "def")
  1361. {
  1362. aCompilerTool = "VCCustomBuildTool";
  1363. if(this->FortranProject)
  1364. {
  1365. aCompilerTool = "VFCustomBuildTool";
  1366. }
  1367. }
  1368. for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
  1369. fci = fcinfo.FileConfigMap.begin();
  1370. fci != fcinfo.FileConfigMap.end(); ++fci)
  1371. {
  1372. cmLVS7GFileConfig const& fc = fci->second;
  1373. fout << "\t\t\t\t<FileConfiguration\n"
  1374. << "\t\t\t\t\tName=\"" << fci->first
  1375. << "|" << this->PlatformName << "\"";
  1376. if(fc.ExcludedFromBuild)
  1377. {
  1378. fout << " ExcludedFromBuild=\"true\"";
  1379. }
  1380. fout << ">\n";
  1381. fout << "\t\t\t\t\t<Tool\n"
  1382. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1383. if(!fc.CompileFlags.empty() ||
  1384. !fc.CompileDefs.empty() ||
  1385. !fc.CompileDefsConfig.empty())
  1386. {
  1387. Options fileOptions(this, this->Version, Options::Compiler,
  1388. cmLocalVisualStudio7GeneratorFlagTable,
  1389. this->ExtraFlagTable);
  1390. fileOptions.Parse(fc.CompileFlags.c_str());
  1391. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1392. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1393. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1394. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1395. fileOptions.OutputPreprocessorDefinitions(fout,
  1396. "\t\t\t\t\t", "\n");
  1397. }
  1398. if(!fc.AdditionalDeps.empty())
  1399. {
  1400. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1401. << fc.AdditionalDeps.c_str() << "\"\n";
  1402. }
  1403. if(!fc.ObjectName.empty())
  1404. {
  1405. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1406. << fc.ObjectName.c_str() << "\"\n";
  1407. }
  1408. fout << "\t\t\t\t\t/>\n"
  1409. << "\t\t\t\t</FileConfiguration>\n";
  1410. }
  1411. }
  1412. fout << "\t\t\t</File>\n";
  1413. }
  1414. }
  1415. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1416. for(unsigned int i=0;i<children.size();++i)
  1417. {
  1418. this->WriteGroup(&children[i], target, fout, libName, configs);
  1419. }
  1420. // If the group has a name, write the footer.
  1421. if(name != "")
  1422. {
  1423. this->WriteVCProjEndGroup(fout);
  1424. }
  1425. }
  1426. void cmLocalVisualStudio7Generator::
  1427. WriteCustomRule(std::ostream& fout,
  1428. const char* source,
  1429. const cmCustomCommand& command,
  1430. FCInfo& fcinfo)
  1431. {
  1432. std::string comment = this->ConstructComment(command);
  1433. // Write the rule for each configuration.
  1434. std::vector<std::string>::iterator i;
  1435. std::vector<std::string> *configs =
  1436. static_cast<cmGlobalVisualStudio7Generator *>
  1437. (this->GlobalGenerator)->GetConfigurations();
  1438. const char* compileTool = "VCCLCompilerTool";
  1439. if(this->FortranProject)
  1440. {
  1441. compileTool = "VFCLCompilerTool";
  1442. }
  1443. const char* customTool = "VCCustomBuildTool";
  1444. if(this->FortranProject)
  1445. {
  1446. customTool = "VFCustomBuildTool";
  1447. }
  1448. for(i = configs->begin(); i != configs->end(); ++i)
  1449. {
  1450. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1451. fout << "\t\t\t\t<FileConfiguration\n";
  1452. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1453. if(!fc.CompileFlags.empty())
  1454. {
  1455. fout << "\t\t\t\t\t<Tool\n"
  1456. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1457. << "\t\t\t\t\tAdditionalOptions=\""
  1458. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1459. }
  1460. std::string script =
  1461. this->ConstructScript(command.GetCommandLines(),
  1462. command.GetWorkingDirectory(),
  1463. i->c_str(),
  1464. command.GetEscapeOldStyle(),
  1465. command.GetEscapeAllowMakeVars());
  1466. fout << "\t\t\t\t\t<Tool\n"
  1467. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1468. << "\t\t\t\t\tDescription=\""
  1469. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1470. << "\t\t\t\t\tCommandLine=\""
  1471. << this->EscapeForXML(script.c_str()) << "\"\n"
  1472. << "\t\t\t\t\tAdditionalDependencies=\"";
  1473. if(command.GetDepends().empty())
  1474. {
  1475. // There are no real dependencies. Produce an artificial one to
  1476. // make sure the rule runs reliably.
  1477. if(!cmSystemTools::FileExists(source))
  1478. {
  1479. std::ofstream depout(source);
  1480. depout << "Artificial dependency for a custom command.\n";
  1481. }
  1482. fout << this->ConvertToXMLOutputPath(source);
  1483. }
  1484. else
  1485. {
  1486. // Write out the dependencies for the rule.
  1487. for(std::vector<std::string>::const_iterator d =
  1488. command.GetDepends().begin();
  1489. d != command.GetDepends().end();
  1490. ++d)
  1491. {
  1492. // Get the real name of the dependency in case it is a CMake target.
  1493. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1494. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1495. << ";";
  1496. }
  1497. }
  1498. fout << "\"\n";
  1499. fout << "\t\t\t\t\tOutputs=\"";
  1500. if(command.GetOutputs().empty())
  1501. {
  1502. fout << source << "_force";
  1503. }
  1504. else
  1505. {
  1506. // Write a rule for the output generated by this command.
  1507. const char* sep = "";
  1508. for(std::vector<std::string>::const_iterator o =
  1509. command.GetOutputs().begin();
  1510. o != command.GetOutputs().end();
  1511. ++o)
  1512. {
  1513. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1514. sep = ";";
  1515. }
  1516. }
  1517. fout << "\"/>\n";
  1518. fout << "\t\t\t\t</FileConfiguration>\n";
  1519. }
  1520. }
  1521. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1522. const char* group,
  1523. const char* )
  1524. {
  1525. fout << "\t\t<Filter\n"
  1526. << "\t\t\tName=\"" << group << "\"\n"
  1527. << "\t\t\tFilter=\"\">\n";
  1528. }
  1529. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1530. {
  1531. fout << "\t\t</Filter>\n";
  1532. }
  1533. // look for custom rules on a target and collect them together
  1534. void cmLocalVisualStudio7Generator
  1535. ::OutputTargetRules(std::ostream& fout,
  1536. const char* configName,
  1537. cmTarget &target,
  1538. const char * /*libName*/)
  1539. {
  1540. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1541. {
  1542. return;
  1543. }
  1544. EventWriter event(this, configName, fout);
  1545. // Add pre-build event.
  1546. const char* tool =
  1547. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1548. event.Start(tool);
  1549. event.Write(target.GetPreBuildCommands());
  1550. event.Finish();
  1551. // Add pre-link event.
  1552. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1553. event.Start(tool);
  1554. event.Write(target.GetPreLinkCommands());
  1555. cmsys::auto_ptr<cmCustomCommand> pcc(
  1556. this->MaybeCreateImplibDir(target, configName));
  1557. if(pcc.get())
  1558. {
  1559. event.Write(*pcc);
  1560. }
  1561. event.Finish();
  1562. // Add post-build event.
  1563. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1564. event.Start(tool);
  1565. event.Write(target.GetPostBuildCommands());
  1566. event.Finish();
  1567. }
  1568. void
  1569. cmLocalVisualStudio7Generator
  1570. ::WriteProjectStartFortran(std::ostream& fout,
  1571. const char *libName,
  1572. cmTarget & target)
  1573. {
  1574. cmGlobalVisualStudio7Generator* gg =
  1575. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1576. // Compute the version of the Intel plugin to the VS IDE.
  1577. // If the key does not exist then use a default guess.
  1578. std::string intelVersion = "9.10";
  1579. std::string vskey = gg->GetRegistryBase();
  1580. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  1581. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  1582. cmSystemTools::KeyWOW64_32);
  1583. // Version 10.1 actually uses 9.10 in project files!
  1584. if(intelVersion == "10.1")
  1585. {
  1586. intelVersion = "9.10";
  1587. }
  1588. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1589. << "<VisualStudioProject\n"
  1590. << "\tProjectCreator=\"Intel Fortran\"\n"
  1591. << "\tVersion=\"" << intelVersion << "\"\n";
  1592. const char* keyword = target.GetProperty("VS_KEYWORD");
  1593. if(!keyword)
  1594. {
  1595. keyword = "Console Application";
  1596. }
  1597. const char* projectType = 0;
  1598. switch(target.GetType())
  1599. {
  1600. case cmTarget::STATIC_LIBRARY:
  1601. projectType = "typeStaticLibrary";
  1602. if(keyword)
  1603. {
  1604. keyword = "Static Library";
  1605. }
  1606. break;
  1607. case cmTarget::SHARED_LIBRARY:
  1608. case cmTarget::MODULE_LIBRARY:
  1609. projectType = "typeDynamicLibrary";
  1610. if(!keyword)
  1611. {
  1612. keyword = "Dll";
  1613. }
  1614. break;
  1615. case cmTarget::EXECUTABLE:
  1616. if(!keyword)
  1617. {
  1618. keyword = "Console Application";
  1619. }
  1620. projectType = 0;
  1621. break;
  1622. case cmTarget::UTILITY:
  1623. case cmTarget::GLOBAL_TARGET:
  1624. default:
  1625. break;
  1626. }
  1627. if(projectType)
  1628. {
  1629. fout << "\tProjectType=\"" << projectType << "\"\n";
  1630. }
  1631. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1632. << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
  1633. << "\t<Platforms>\n"
  1634. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1635. << "\t</Platforms>\n";
  1636. }
  1637. void
  1638. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1639. const char *libName,
  1640. cmTarget & target,
  1641. std::vector<cmSourceGroup> &)
  1642. {
  1643. if(this->FortranProject)
  1644. {
  1645. this->WriteProjectStartFortran(fout, libName, target);
  1646. return;
  1647. }
  1648. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1649. << "<VisualStudioProject\n"
  1650. << "\tProjectType=\"Visual C++\"\n";
  1651. if(this->Version == 71)
  1652. {
  1653. fout << "\tVersion=\"7.10\"\n";
  1654. }
  1655. else
  1656. {
  1657. fout << "\tVersion=\"" << this->Version << ".00\"\n";
  1658. }
  1659. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1660. if(!projLabel)
  1661. {
  1662. projLabel = libName;
  1663. }
  1664. const char* keyword = target.GetProperty("VS_KEYWORD");
  1665. if(!keyword)
  1666. {
  1667. keyword = "Win32Proj";
  1668. }
  1669. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1670. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1671. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1672. cmGlobalVisualStudio7Generator* gg =
  1673. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1674. fout << "\tName=\"" << projLabel << "\"\n";
  1675. if(this->Version >= 8)
  1676. {
  1677. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1678. }
  1679. // if we have all the required Source code control tags
  1680. // then add that to the project
  1681. if(vsProvider && vsLocalpath && vsProjectname)
  1682. {
  1683. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1684. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1685. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1686. }
  1687. fout << "\tKeyword=\"" << keyword << "\">\n"
  1688. << "\t<Platforms>\n"
  1689. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1690. << "\t</Platforms>\n";
  1691. }
  1692. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1693. {
  1694. fout << "\t<Globals>\n"
  1695. << "\t</Globals>\n"
  1696. << "</VisualStudioProject>\n";
  1697. }
  1698. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1699. {
  1700. std::string ret = s;
  1701. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1702. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1703. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1704. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1705. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1706. return ret;
  1707. }
  1708. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1709. {
  1710. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1711. }
  1712. std::string cmLocalVisualStudio7Generator
  1713. ::ConvertToXMLOutputPath(const char* path)
  1714. {
  1715. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1716. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1717. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1718. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1719. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1720. return ret;
  1721. }
  1722. std::string cmLocalVisualStudio7Generator
  1723. ::ConvertToXMLOutputPathSingle(const char* path)
  1724. {
  1725. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1726. cmSystemTools::ReplaceString(ret, "\"", "");
  1727. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1728. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1729. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1730. return ret;
  1731. }
  1732. // This class is used to parse an existing vs 7 project
  1733. // and extract the GUID
  1734. class cmVS7XMLParser : public cmXMLParser
  1735. {
  1736. public:
  1737. virtual void EndElement(const char* /* name */)
  1738. {
  1739. }
  1740. virtual void StartElement(const char* name, const char** atts)
  1741. {
  1742. // once the GUID is found do nothing
  1743. if(this->GUID.size())
  1744. {
  1745. return;
  1746. }
  1747. int i =0;
  1748. if(strcmp("VisualStudioProject", name) == 0)
  1749. {
  1750. while(atts[i])
  1751. {
  1752. if(strcmp(atts[i], "ProjectGUID") == 0)
  1753. {
  1754. if(atts[i+1])
  1755. {
  1756. this->GUID = atts[i+1];
  1757. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1758. }
  1759. else
  1760. {
  1761. this->GUID = "";
  1762. }
  1763. return;
  1764. }
  1765. ++i;
  1766. }
  1767. }
  1768. }
  1769. int InitializeParser()
  1770. {
  1771. int ret = cmXMLParser::InitializeParser();
  1772. if(ret == 0)
  1773. {
  1774. return ret;
  1775. }
  1776. // visual studio projects have a strange encoding, but it is
  1777. // really utf-8
  1778. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1779. return 1;
  1780. }
  1781. std::string GUID;
  1782. };
  1783. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1784. const char* name,
  1785. const char* path)
  1786. {
  1787. cmVS7XMLParser parser;
  1788. parser.ParseFile(path);
  1789. // if we can not find a GUID then create one
  1790. if(parser.GUID.size() == 0)
  1791. {
  1792. cmGlobalVisualStudio7Generator* gg =
  1793. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1794. gg->CreateGUID(name);
  1795. return;
  1796. }
  1797. std::string guidStoreName = name;
  1798. guidStoreName += "_GUID_CMAKE";
  1799. // save the GUID in the cache
  1800. this->GlobalGenerator->GetCMakeInstance()->
  1801. AddCacheEntry(guidStoreName.c_str(),
  1802. parser.GUID.c_str(),
  1803. "Stored GUID",
  1804. cmCacheManager::INTERNAL);
  1805. }
  1806. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1807. {
  1808. cmLocalGenerator::ConfigureFinalPass();
  1809. cmTargets &tgts = this->Makefile->GetTargets();
  1810. cmGlobalVisualStudio7Generator* gg =
  1811. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1812. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1813. {
  1814. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  1815. if(path)
  1816. {
  1817. this->ReadAndStoreExternalGUID(
  1818. l->second.GetName(), path);
  1819. }
  1820. else
  1821. {
  1822. gg->CreateGUID(l->first.c_str());
  1823. }
  1824. }
  1825. }
  1826. //----------------------------------------------------------------------------
  1827. std::string cmLocalVisualStudio7Generator
  1828. ::GetTargetDirectory(cmTarget const& target) const
  1829. {
  1830. std::string dir;
  1831. dir += target.GetName();
  1832. dir += ".dir";
  1833. return dir;
  1834. }
  1835. void cmLocalVisualStudio7Generator::
  1836. GetTargetObjectFileDirectories(cmTarget* target,
  1837. std::vector<std::string>&
  1838. dirs)
  1839. {
  1840. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1841. dir += "/";
  1842. dir += this->GetTargetDirectory(*target);
  1843. dir += "/";
  1844. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1845. dirs.push_back(dir);
  1846. }
  1847. //----------------------------------------------------------------------------
  1848. #include <windows.h>
  1849. static bool cmLVS6G_IsFAT(const char* dir)
  1850. {
  1851. if(dir[0] && dir[1] == ':')
  1852. {
  1853. char volRoot[4] = "_:/";
  1854. volRoot[0] = dir[0];
  1855. char fsName[16];
  1856. if(GetVolumeInformation(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  1857. strstr(fsName, "FAT") != 0)
  1858. {
  1859. return true;
  1860. }
  1861. }
  1862. return false;
  1863. }