cmLocalVisualStudio7Generator.cxx 67 KB

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