cmLocalVisualStudio7Generator.cxx 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmGlobalVisualStudio7Generator.h"
  14. #include "cmLocalVisualStudio7Generator.h"
  15. #include "cmXMLParser.h"
  16. #include <cm_expat.h>
  17. #include "cmMakefile.h"
  18. #include "cmSystemTools.h"
  19. #include "cmSourceFile.h"
  20. #include "cmCacheManager.h"
  21. #include "cmake.h"
  22. #include "cmComputeLinkInformation.h"
  23. #include "cmGeneratedFileStream.h"
  24. #include <cmsys/System.h>
  25. #include <ctype.h> // for isspace
  26. // Package GUID of Intel Visual Fortran plugin to VS IDE
  27. #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
  28. static bool cmLVS6G_IsFAT(const char* dir);
  29. class cmLocalVisualStudio7GeneratorInternals
  30. {
  31. public:
  32. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e):
  33. LocalGenerator(e) {}
  34. typedef cmComputeLinkInformation::ItemVector ItemVector;
  35. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  36. private:
  37. cmLocalVisualStudio7Generator* LocalGenerator;
  38. };
  39. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  40. //----------------------------------------------------------------------------
  41. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator()
  42. {
  43. this->Version = 7;
  44. this->PlatformName = "Win32";
  45. this->ExtraFlagTable = 0;
  46. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  47. }
  48. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  49. {
  50. delete this->Internal;
  51. }
  52. void cmLocalVisualStudio7Generator::AddHelperCommands()
  53. {
  54. std::set<cmStdString> lang;
  55. lang.insert("C");
  56. lang.insert("CXX");
  57. lang.insert("RC");
  58. lang.insert("IDL");
  59. lang.insert("DEF");
  60. lang.insert("Fortran");
  61. this->CreateCustomTargetsAndCommands(lang);
  62. this->FixGlobalTargets();
  63. }
  64. void cmLocalVisualStudio7Generator::Generate()
  65. {
  66. this->WriteProjectFiles();
  67. this->WriteStampFiles();
  68. }
  69. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  70. {
  71. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  72. // commands for targets in which no sources are built. Add dummy
  73. // rules to force these targets to build.
  74. cmTargets &tgts = this->Makefile->GetTargets();
  75. for(cmTargets::iterator l = tgts.begin();
  76. l != tgts.end(); l++)
  77. {
  78. cmTarget& tgt = l->second;
  79. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  80. {
  81. std::vector<std::string> no_depends;
  82. cmCustomCommandLine force_command;
  83. force_command.push_back("cd");
  84. force_command.push_back(".");
  85. cmCustomCommandLines force_commands;
  86. force_commands.push_back(force_command);
  87. const char* no_main_dependency = 0;
  88. std::string force = this->Makefile->GetStartOutputDirectory();
  89. force += cmake::GetCMakeFilesDirectory();
  90. force += "/";
  91. force += tgt.GetName();
  92. force += "_force";
  93. this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends,
  94. no_main_dependency,
  95. force_commands, " ", 0, true);
  96. if(cmSourceFile* file =
  97. this->Makefile->GetSourceFileWithOutput(force.c_str()))
  98. {
  99. tgt.AddSourceFile(file);
  100. }
  101. }
  102. }
  103. }
  104. // TODO
  105. // for CommandLine= need to repleace quotes with &quot
  106. // write out configurations
  107. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  108. {
  109. // If not an in source build, then create the output directory
  110. if(strcmp(this->Makefile->GetStartOutputDirectory(),
  111. this->Makefile->GetHomeDirectory()) != 0)
  112. {
  113. if(!cmSystemTools::MakeDirectory
  114. (this->Makefile->GetStartOutputDirectory()))
  115. {
  116. cmSystemTools::Error("Error creating directory ",
  117. this->Makefile->GetStartOutputDirectory());
  118. }
  119. }
  120. // Get the set of targets in this directory.
  121. cmTargets &tgts = this->Makefile->GetTargets();
  122. // Create the regeneration custom rule.
  123. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  124. {
  125. // Create a rule to regenerate the build system when the target
  126. // specification source changes.
  127. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  128. {
  129. // Add the rule to targets that need it.
  130. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  131. {
  132. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  133. {
  134. l->second.AddSourceFile(sf);
  135. }
  136. }
  137. }
  138. }
  139. // Create the project file for each target.
  140. for(cmTargets::iterator l = tgts.begin();
  141. l != tgts.end(); l++)
  142. {
  143. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  144. // so don't build a projectfile for it
  145. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  146. {
  147. this->CreateSingleVCProj(l->first.c_str(),l->second);
  148. }
  149. }
  150. }
  151. //----------------------------------------------------------------------------
  152. void cmLocalVisualStudio7Generator::WriteStampFiles()
  153. {
  154. // Touch a timestamp file used to determine when the project file is
  155. // out of date.
  156. std::string stampName = this->Makefile->GetStartOutputDirectory();
  157. stampName += cmake::GetCMakeFilesDirectory();
  158. cmSystemTools::MakeDirectory(stampName.c_str());
  159. stampName += "/";
  160. stampName += "generate.stamp";
  161. std::ofstream stamp(stampName.c_str());
  162. stamp << "# CMake generation timestamp file this directory.\n";
  163. // Create a helper file so CMake can determine when it is run
  164. // through the rule created by CreateVCProjBuildRule whether it
  165. // really needs to regenerate the project. This file lists its own
  166. // dependencies. If any file listed in it is newer than itself then
  167. // CMake must rerun. Otherwise the project files are up to date and
  168. // the stamp file can just be touched.
  169. std::string depName = stampName;
  170. depName += ".depend";
  171. std::ofstream depFile(depName.c_str());
  172. depFile << "# CMake generation dependency list for this directory.\n";
  173. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  174. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  175. lf != listFiles.end(); ++lf)
  176. {
  177. depFile << *lf << std::endl;
  178. }
  179. }
  180. //----------------------------------------------------------------------------
  181. void cmLocalVisualStudio7Generator
  182. ::CreateSingleVCProj(const char *lname, cmTarget &target)
  183. {
  184. this->FortranProject =
  185. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  186. ->TargetIsFortranOnly(target);
  187. // add to the list of projects
  188. std::string pname = lname;
  189. target.SetProperty("GENERATOR_FILE_NAME",lname);
  190. // create the dsp.cmake file
  191. std::string fname;
  192. fname = this->Makefile->GetStartOutputDirectory();
  193. fname += "/";
  194. fname += lname;
  195. if(this->FortranProject)
  196. {
  197. fname += ".vfproj";
  198. }
  199. else
  200. {
  201. fname += ".vcproj";
  202. }
  203. // Generate the project file and replace it atomically with
  204. // copy-if-different. We use a separate timestamp so that the IDE
  205. // does not reload project files unnecessarily.
  206. cmGeneratedFileStream fout(fname.c_str());
  207. fout.SetCopyIfDifferent(true);
  208. this->WriteVCProjFile(fout,lname,target);
  209. if (fout.Close())
  210. {
  211. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  212. }
  213. }
  214. //----------------------------------------------------------------------------
  215. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  216. {
  217. std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
  218. stampName += "generate.stamp";
  219. const char* dsprule =
  220. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  221. cmCustomCommandLine commandLine;
  222. commandLine.push_back(dsprule);
  223. std::string makefileIn = this->Makefile->GetStartDirectory();
  224. makefileIn += "/";
  225. makefileIn += "CMakeLists.txt";
  226. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  227. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  228. {
  229. return 0;
  230. }
  231. std::string comment = "Building Custom Rule ";
  232. comment += makefileIn;
  233. std::string args;
  234. args = "-H";
  235. args += this->Convert(this->Makefile->GetHomeDirectory(),
  236. START_OUTPUT, UNCHANGED, true);
  237. commandLine.push_back(args);
  238. args = "-B";
  239. args +=
  240. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  241. START_OUTPUT, UNCHANGED, true);
  242. commandLine.push_back(args);
  243. commandLine.push_back("--check-stamp-file");
  244. commandLine.push_back(stampName.c_str());
  245. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  246. cmCustomCommandLines commandLines;
  247. commandLines.push_back(commandLine);
  248. const char* no_working_directory = 0;
  249. this->Makefile->AddCustomCommandToOutput(stampName.c_str(), listFiles,
  250. makefileIn.c_str(), commandLines,
  251. comment.c_str(),
  252. no_working_directory, true);
  253. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  254. {
  255. return file;
  256. }
  257. else
  258. {
  259. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  260. return 0;
  261. }
  262. }
  263. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  264. const char *libName,
  265. cmTarget &target)
  266. {
  267. std::vector<std::string> *configs =
  268. static_cast<cmGlobalVisualStudio7Generator *>
  269. (this->GlobalGenerator)->GetConfigurations();
  270. fout << "\t<Configurations>\n";
  271. for( std::vector<std::string>::iterator i = configs->begin();
  272. i != configs->end(); ++i)
  273. {
  274. this->WriteConfiguration(fout, i->c_str(), libName, target);
  275. }
  276. fout << "\t</Configurations>\n";
  277. }
  278. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  279. {
  280. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  281. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  282. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  283. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  284. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  285. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  286. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  287. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  288. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  289. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  290. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  291. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  292. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  293. {"OmitFramePointers", "Oy-", "", "false", 0},
  294. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  295. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  296. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  297. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  298. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  299. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  300. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  301. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  302. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  303. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  304. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  305. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  306. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  307. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  308. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  309. {"ModulePath", "module:", "", "",
  310. cmVS7FlagTable::UserValueRequired},
  311. {"LoopUnrolling", "Qunroll:", "", "",
  312. cmVS7FlagTable::UserValueRequired},
  313. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  314. cmVS7FlagTable::UserValueRequired},
  315. {"HeapArrays", "heap-arrays:", "", "",
  316. cmVS7FlagTable::UserValueRequired},
  317. {"ObjectText", "bintext:", "", "",
  318. cmVS7FlagTable::UserValueRequired},
  319. {"Parallelization", "Qparallel", "", "true", 0},
  320. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  321. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  322. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  323. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  324. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  325. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  326. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  327. {"EnableRecursion", "recursive", "", "true", 0},
  328. {"ReentrantCode", "reentrancy", "", "true", 0},
  329. // done up to Language
  330. {0,0,0,0,0}
  331. };
  332. // fill the table here currently the comment field is not used for
  333. // anything other than documentation NOTE: Make sure the longer
  334. // commandFlag comes FIRST!
  335. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  336. {
  337. // option flags (some flags map to the same option)
  338. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  339. {"BasicRuntimeChecks", "RTCsu",
  340. "Both stack and uninitialized checks", "3", 0},
  341. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  342. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  343. {"BasicRuntimeChecks", "RTC1",
  344. "Both stack and uninitialized checks", "3", 0},
  345. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  346. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  347. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  348. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  349. {"EnableEnhancedInstructionSet", "arch:SSE2",
  350. "Use sse2 instructions", "2", 0},
  351. {"EnableEnhancedInstructionSet", "arch:SSE",
  352. "Use sse instructions", "1", 0},
  353. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  354. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  355. {"CompileAs", "TC", "Compile as c code", "1", 0},
  356. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  357. {"Optimization", "Od", "Non Debug", "0", 0},
  358. {"Optimization", "O1", "Min Size", "1", 0},
  359. {"Optimization", "O2", "Max Speed", "2", 0},
  360. {"Optimization", "Ox", "Max Optimization", "3", 0},
  361. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  362. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  363. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  364. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  365. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  366. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  367. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  368. {"RuntimeLibrary", "MTd", "Multithreded debug", "1", 0},
  369. {"RuntimeLibrary", "MT", "Multithreded", "0", 0},
  370. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3", 0},
  371. {"RuntimeLibrary", "MD", "Multithreded dll", "2", 0},
  372. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5", 0},
  373. {"RuntimeLibrary", "ML", "Sinble Thread", "4", 0},
  374. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  375. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  376. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  377. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  378. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  379. {"WarningLevel", "W0", "Warning level", "0", 0},
  380. {"WarningLevel", "W1", "Warning level", "1", 0},
  381. {"WarningLevel", "W2", "Warning level", "2", 0},
  382. {"WarningLevel", "W3", "Warning level", "3", 0},
  383. {"WarningLevel", "W4", "Warning level", "4", 0},
  384. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  385. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  386. // Precompiled header and related options. Note that the
  387. // UsePrecompiledHeader entries are marked as "Continue" so that the
  388. // corresponding PrecompiledHeaderThrough entry can be found.
  389. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  390. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  391. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  392. cmVS7FlagTable::UserValueRequired},
  393. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  394. cmVS7FlagTable::UserValue},
  395. // The YX and Yu options are in a per-global-generator table because
  396. // their values differ based on the VS IDE version.
  397. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  398. cmVS7FlagTable::UserValueRequired},
  399. // boolean flags
  400. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
  401. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
  402. {"Detect64BitPortabilityProblems", "Wp64",
  403. "Detect 64-bit Portability Problems", "TRUE", 0},
  404. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  405. "TRUE", 0},
  406. {"EnableFunctionLevelLinking", "Gy",
  407. "EnableFunctionLevelLinking", "TRUE", 0},
  408. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
  409. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
  410. {"ImproveFloatingPointConsistency", "Op",
  411. "ImproveFloatingPointConsistency", "TRUE", 0},
  412. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
  413. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
  414. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
  415. {"RuntimeTypeInfo", "GR",
  416. "Turn on Run time type information for c++", "TRUE", 0},
  417. {"RuntimeTypeInfo", "GR-",
  418. "Turn off Run time type information for c++", "FALSE", 0},
  419. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
  420. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
  421. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
  422. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  423. {0,0,0,0,0}
  424. };
  425. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  426. {
  427. // option flags (some flags map to the same option)
  428. {"GenerateManifest", "MANIFEST:NO",
  429. "disable manifest generation", "FALSE", 0},
  430. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
  431. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  432. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  433. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  434. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  435. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  436. "TRUE", 0},
  437. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  438. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  439. "2", 0},
  440. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  441. "1", 0},
  442. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  443. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  444. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  445. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  446. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  447. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  448. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  449. cmVS7FlagTable::UserValue},
  450. {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
  451. {0,0,0,0,0}
  452. };
  453. //----------------------------------------------------------------------------
  454. // Helper class to write build event <Tool .../> elements.
  455. class cmLocalVisualStudio7Generator::EventWriter
  456. {
  457. public:
  458. EventWriter(cmLocalVisualStudio7Generator* lg,
  459. const char* config, std::ostream& os):
  460. LG(lg), Config(config), Stream(os), First(true) {}
  461. void Start(const char* tool)
  462. {
  463. this->First = true;
  464. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  465. }
  466. void Finish()
  467. {
  468. this->Stream << (this->First? "" : "\"") << "/>\n";
  469. }
  470. void Write(std::vector<cmCustomCommand> const& ccs)
  471. {
  472. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  473. ci != ccs.end(); ++ci)
  474. {
  475. this->Write(*ci);
  476. }
  477. }
  478. void Write(cmCustomCommand const& cc)
  479. {
  480. if(this->First)
  481. {
  482. const char* comment = cc.GetComment();
  483. if(comment && *comment)
  484. {
  485. this->Stream << "\nDescription=\""
  486. << this->LG->EscapeForXML(comment) << "\"";
  487. }
  488. this->Stream << "\nCommandLine=\"";
  489. this->First = false;
  490. }
  491. else
  492. {
  493. this->Stream << this->LG->EscapeForXML("\n");
  494. }
  495. std::string script =
  496. this->LG->ConstructScript(cc.GetCommandLines(),
  497. cc.GetWorkingDirectory(),
  498. this->Config,
  499. cc.GetEscapeOldStyle(),
  500. cc.GetEscapeAllowMakeVars());
  501. this->Stream << this->LG->EscapeForXML(script.c_str());
  502. }
  503. private:
  504. cmLocalVisualStudio7Generator* LG;
  505. const char* Config;
  506. std::ostream& Stream;
  507. bool First;
  508. };
  509. //----------------------------------------------------------------------------
  510. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  511. const char* configName,
  512. const char *libName,
  513. cmTarget &target)
  514. {
  515. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  516. if(!mfcFlag)
  517. {
  518. mfcFlag = "0";
  519. }
  520. fout << "\t\t<Configuration\n"
  521. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  522. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  523. // This is an internal type to Visual Studio, it seems that:
  524. // 4 == static library
  525. // 2 == dll
  526. // 1 == executable
  527. // 10 == utility
  528. const char* configType = "10";
  529. const char* projectType = 0;
  530. bool targetBuilds = true;
  531. switch(target.GetType())
  532. {
  533. case cmTarget::STATIC_LIBRARY:
  534. projectType = "typeStaticLibrary";
  535. configType = "4";
  536. break;
  537. case cmTarget::SHARED_LIBRARY:
  538. case cmTarget::MODULE_LIBRARY:
  539. projectType = "typeDynamicLibrary";
  540. configType = "2";
  541. break;
  542. case cmTarget::EXECUTABLE:
  543. configType = "1";
  544. break;
  545. case cmTarget::UTILITY:
  546. case cmTarget::GLOBAL_TARGET:
  547. configType = "10";
  548. default:
  549. targetBuilds = false;
  550. break;
  551. }
  552. if(this->FortranProject && projectType)
  553. {
  554. configType = projectType;
  555. }
  556. std::string flags;
  557. if(strcmp(configType, "10") != 0)
  558. {
  559. const char* linkLanguage = 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. << target.GetDirectory(configName) << "/"
  708. << target.GetPDBName(configName) << "\"\n";
  709. }
  710. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  711. tool = "VCCustomBuildTool";
  712. if(this->FortranProject)
  713. {
  714. tool = "VFCustomBuildTool";
  715. }
  716. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  717. tool = "VCResourceCompilerTool";
  718. if(this->FortranProject)
  719. {
  720. tool = "VFResourceCompilerTool";
  721. }
  722. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  723. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  724. for(i = includes.begin();i != includes.end(); ++i)
  725. {
  726. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  727. fout << ipath << ";";
  728. }
  729. // add the -D flags to the RC tool
  730. fout << "\"";
  731. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  732. fout << "/>\n";
  733. tool = "VCMIDLTool";
  734. if(this->FortranProject)
  735. {
  736. tool = "VFMIDLTool";
  737. }
  738. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  739. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  740. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  741. if( this->PlatformName == "x64" )
  742. {
  743. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  744. }
  745. else if( this->PlatformName == "ia64" )
  746. {
  747. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  748. }
  749. else
  750. {
  751. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  752. }
  753. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  754. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  755. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  756. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  757. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  758. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  759. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  760. // end of <Tool Name=VCMIDLTool
  761. // Check if we need the FAT32 workaround.
  762. if(targetBuilds && this->Version >= 8)
  763. {
  764. // Check the filesystem type where the target will be written.
  765. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  766. {
  767. // Add a flag telling the manifest tool to use a workaround
  768. // for FAT32 file systems, which can cause an empty manifest
  769. // to be embedded into the resulting executable. See CMake
  770. // bug #2617.
  771. const char* tool = "VCManifestTool";
  772. if(this->FortranProject)
  773. {
  774. tool = "VFManifestTool";
  775. }
  776. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  777. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  778. << "\t\t\t/>\n";
  779. }
  780. }
  781. this->OutputTargetRules(fout, configName, target, libName);
  782. this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
  783. fout << "\t\t</Configuration>\n";
  784. }
  785. //----------------------------------------------------------------------------
  786. std::string
  787. cmLocalVisualStudio7Generator
  788. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  789. {
  790. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  791. std::string extraLinkOptionsBuildTypeDef =
  792. rootLinkerFlags + "_" + configTypeUpper;
  793. std::string extraLinkOptionsBuildType =
  794. this->Makefile->GetRequiredDefinition
  795. (extraLinkOptionsBuildTypeDef.c_str());
  796. return extraLinkOptionsBuildType;
  797. }
  798. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  799. const char* configName,
  800. cmTarget &target,
  801. bool isDebug)
  802. {
  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. switch(target.GetType())
  845. {
  846. case cmTarget::STATIC_LIBRARY:
  847. {
  848. std::string targetNameFull = target.GetFullName(configName);
  849. std::string libpath = target.GetDirectory(configName);
  850. libpath += "/";
  851. libpath += targetNameFull;
  852. const char* tool = "VCLibrarianTool";
  853. if(this->FortranProject)
  854. {
  855. tool = "VFLibrarianTool";
  856. }
  857. fout << "\t\t\t<Tool\n"
  858. << "\t\t\t\tName=\"" << tool << "\"\n";
  859. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  860. {
  861. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  862. }
  863. fout << "\t\t\t\tOutputFile=\""
  864. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  865. break;
  866. }
  867. case cmTarget::SHARED_LIBRARY:
  868. case cmTarget::MODULE_LIBRARY:
  869. {
  870. std::string targetName;
  871. std::string targetNameSO;
  872. std::string targetNameFull;
  873. std::string targetNameImport;
  874. std::string targetNamePDB;
  875. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  876. targetNameImport, targetNamePDB, configName);
  877. // Compute the link library and directory information.
  878. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  879. if(!pcli)
  880. {
  881. return;
  882. }
  883. cmComputeLinkInformation& cli = *pcli;
  884. const char* linkLanguage = cli.GetLinkLanguage();
  885. // Compute the variable name to lookup standard libraries for this
  886. // language.
  887. std::string standardLibsVar = "CMAKE_";
  888. standardLibsVar += linkLanguage;
  889. standardLibsVar += "_STANDARD_LIBRARIES";
  890. const char* tool = "VCLinkerTool";
  891. if(this->FortranProject)
  892. {
  893. tool = "VFLinkerTool";
  894. }
  895. fout << "\t\t\t<Tool\n"
  896. << "\t\t\t\tName=\"" << tool << "\"\n";
  897. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  898. // Use the NOINHERIT macro to avoid getting VS project default
  899. // libraries which may be set by the user to something bad.
  900. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  901. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  902. << " ";
  903. this->Internal->OutputLibraries(fout, cli.GetItems());
  904. fout << "\"\n";
  905. temp = target.GetDirectory(configName);
  906. temp += "/";
  907. temp += targetNameFull;
  908. fout << "\t\t\t\tOutputFile=\""
  909. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  910. this->WriteTargetVersionAttribute(fout, target);
  911. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  912. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  913. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  914. fout << "\"\n";
  915. this->OutputModuleDefinitionFile(fout, target);
  916. temp = target.GetDirectory(configName);
  917. temp += "/";
  918. temp += targetNamePDB;
  919. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  920. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  921. if(isDebug)
  922. {
  923. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  924. }
  925. std::string stackVar = "CMAKE_";
  926. stackVar += linkLanguage;
  927. stackVar += "_STACK_SIZE";
  928. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  929. if(stackVal)
  930. {
  931. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  932. }
  933. temp = target.GetDirectory(configName, true);
  934. temp += "/";
  935. temp += targetNameImport;
  936. fout << "\t\t\t\tImportLibrary=\""
  937. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  938. }
  939. break;
  940. case cmTarget::EXECUTABLE:
  941. {
  942. std::string targetName;
  943. std::string targetNameFull;
  944. std::string targetNameImport;
  945. std::string targetNamePDB;
  946. target.GetExecutableNames(targetName, targetNameFull,
  947. targetNameImport, targetNamePDB, configName);
  948. // Compute the link library and directory information.
  949. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  950. if(!pcli)
  951. {
  952. return;
  953. }
  954. cmComputeLinkInformation& cli = *pcli;
  955. const char* linkLanguage = cli.GetLinkLanguage();
  956. // Compute the variable name to lookup standard libraries for this
  957. // language.
  958. std::string standardLibsVar = "CMAKE_";
  959. standardLibsVar += linkLanguage;
  960. standardLibsVar += "_STANDARD_LIBRARIES";
  961. const char* tool = "VCLinkerTool";
  962. if(this->FortranProject)
  963. {
  964. tool = "VFLinkerTool";
  965. }
  966. fout << "\t\t\t<Tool\n"
  967. << "\t\t\t\tName=\"" << tool << "\"\n";
  968. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  969. // Use the NOINHERIT macro to avoid getting VS project default
  970. // libraries which may be set by the user to something bad.
  971. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  972. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  973. << " ";
  974. this->Internal->OutputLibraries(fout, cli.GetItems());
  975. fout << "\"\n";
  976. temp = target.GetDirectory(configName);
  977. temp += "/";
  978. temp += targetNameFull;
  979. fout << "\t\t\t\tOutputFile=\""
  980. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  981. this->WriteTargetVersionAttribute(fout, target);
  982. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  983. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  984. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  985. fout << "\"\n";
  986. fout << "\t\t\t\tProgramDataBaseFile=\""
  987. << target.GetDirectory(configName) << "/" << targetNamePDB
  988. << "\"\n";
  989. if(isDebug)
  990. {
  991. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  992. }
  993. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  994. {
  995. fout << "\t\t\t\tSubSystem=\"2\"\n";
  996. }
  997. else
  998. {
  999. fout << "\t\t\t\tSubSystem=\"1\"\n";
  1000. }
  1001. std::string stackVar = "CMAKE_";
  1002. stackVar += linkLanguage;
  1003. stackVar += "_STACK_SIZE";
  1004. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1005. if(stackVal)
  1006. {
  1007. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1008. }
  1009. temp = target.GetDirectory(configName, true);
  1010. temp += "/";
  1011. temp += targetNameImport;
  1012. fout << "\t\t\t\tImportLibrary=\""
  1013. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1014. break;
  1015. }
  1016. case cmTarget::UTILITY:
  1017. case cmTarget::GLOBAL_TARGET:
  1018. break;
  1019. }
  1020. }
  1021. //----------------------------------------------------------------------------
  1022. void
  1023. cmLocalVisualStudio7Generator
  1024. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1025. {
  1026. int major;
  1027. int minor;
  1028. target.GetTargetVersion(major, minor);
  1029. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1030. }
  1031. void cmLocalVisualStudio7Generator
  1032. ::OutputModuleDefinitionFile(std::ostream& fout,
  1033. cmTarget &target)
  1034. {
  1035. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  1036. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1037. i != classes.end(); i++)
  1038. {
  1039. cmSourceFile* sf = *i;
  1040. if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
  1041. {
  1042. fout << "\t\t\t\tModuleDefinitionFile=\""
  1043. << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
  1044. << "\"\n";
  1045. return;
  1046. }
  1047. }
  1048. }
  1049. //----------------------------------------------------------------------------
  1050. void
  1051. cmLocalVisualStudio7GeneratorInternals
  1052. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1053. {
  1054. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1055. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1056. {
  1057. if(l->IsPath)
  1058. {
  1059. std::string rel = lg->Convert(l->Value.c_str(),
  1060. cmLocalGenerator::START_OUTPUT,
  1061. cmLocalGenerator::UNCHANGED);
  1062. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1063. }
  1064. else
  1065. {
  1066. fout << l->Value << " ";
  1067. }
  1068. }
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. void
  1072. cmLocalVisualStudio7Generator
  1073. ::OutputLibraryDirectories(std::ostream& fout,
  1074. std::vector<std::string> const& dirs)
  1075. {
  1076. const char* comma = "";
  1077. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1078. d != dirs.end(); ++d)
  1079. {
  1080. // Remove any trailing slash and skip empty paths.
  1081. std::string dir = *d;
  1082. if(dir[dir.size()-1] == '/')
  1083. {
  1084. dir = dir.substr(0, dir.size()-1);
  1085. }
  1086. if(dir.empty())
  1087. {
  1088. continue;
  1089. }
  1090. // Switch to a relative path specification if it is shorter.
  1091. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1092. {
  1093. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1094. if(rel.size() < dir.size())
  1095. {
  1096. dir = rel;
  1097. }
  1098. }
  1099. // First search a configuration-specific subdirectory and then the
  1100. // original directory.
  1101. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1102. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1103. comma = ",";
  1104. }
  1105. }
  1106. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1107. const char *libName,
  1108. cmTarget &target)
  1109. {
  1110. // get the configurations
  1111. std::vector<std::string> *configs =
  1112. static_cast<cmGlobalVisualStudio7Generator *>
  1113. (this->GlobalGenerator)->GetConfigurations();
  1114. // We may be modifying the source groups temporarily, so make a copy.
  1115. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1116. // get the classes from the source lists then add them to the groups
  1117. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  1118. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1119. i != classes.end(); i++)
  1120. {
  1121. // Add the file to the list of sources.
  1122. std::string source = (*i)->GetFullPath();
  1123. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1124. {
  1125. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1126. }
  1127. cmSourceGroup& sourceGroup =
  1128. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1129. sourceGroup.AssignSource(*i);
  1130. }
  1131. // Compute which sources need unique object computation.
  1132. this->ComputeObjectNameRequirements(sourceGroups);
  1133. // open the project
  1134. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1135. // write the configuration information
  1136. this->WriteConfigurations(fout, libName, target);
  1137. fout << "\t<Files>\n";
  1138. // Loop through every source group.
  1139. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1140. {
  1141. cmSourceGroup sg = sourceGroups[i];
  1142. this->WriteGroup(&sg, target, fout, libName, configs);
  1143. }
  1144. //}
  1145. fout << "\t</Files>\n";
  1146. // Write the VCProj file's footer.
  1147. this->WriteVCProjFooter(fout);
  1148. }
  1149. struct cmLVS7GFileConfig
  1150. {
  1151. std::string ObjectName;
  1152. std::string CompileFlags;
  1153. std::string CompileDefs;
  1154. std::string CompileDefsConfig;
  1155. std::string AdditionalDeps;
  1156. bool ExcludedFromBuild;
  1157. };
  1158. class cmLocalVisualStudio7GeneratorFCInfo
  1159. {
  1160. public:
  1161. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1162. cmTarget& target,
  1163. cmSourceFile const& sf,
  1164. std::vector<std::string>* configs,
  1165. std::string const& dir_max);
  1166. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1167. };
  1168. cmLocalVisualStudio7GeneratorFCInfo
  1169. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1170. cmTarget& target,
  1171. cmSourceFile const& sf,
  1172. std::vector<std::string>* configs,
  1173. std::string const& dir_max)
  1174. {
  1175. std::string objectName;
  1176. if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
  1177. {
  1178. objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max);
  1179. }
  1180. // Compute per-source, per-config information.
  1181. for(std::vector<std::string>::iterator i = configs->begin();
  1182. i != configs->end(); ++i)
  1183. {
  1184. std::string configUpper = cmSystemTools::UpperCase(*i);
  1185. cmLVS7GFileConfig fc;
  1186. bool needfc = false;
  1187. if(!objectName.empty())
  1188. {
  1189. fc.ObjectName = objectName;
  1190. needfc = true;
  1191. }
  1192. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1193. {
  1194. fc.CompileFlags = cflags;
  1195. needfc = true;
  1196. }
  1197. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1198. {
  1199. fc.CompileDefs = cdefs;
  1200. needfc = true;
  1201. }
  1202. std::string defPropName = "COMPILE_DEFINITIONS_";
  1203. defPropName += configUpper;
  1204. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1205. {
  1206. fc.CompileDefsConfig = ccdefs;
  1207. needfc = true;
  1208. }
  1209. // Check for extra object-file dependencies.
  1210. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1211. {
  1212. std::vector<std::string> depends;
  1213. cmSystemTools::ExpandListArgument(deps, depends);
  1214. const char* sep = "";
  1215. for(std::vector<std::string>::iterator j = depends.begin();
  1216. j != depends.end(); ++j)
  1217. {
  1218. fc.AdditionalDeps += sep;
  1219. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1220. sep = ";";
  1221. needfc = true;
  1222. }
  1223. }
  1224. const char* lang =
  1225. lg->GlobalGenerator->GetLanguageFromExtension
  1226. (sf.GetExtension().c_str());
  1227. const char* sourceLang = lg->GetSourceFileLanguage(sf);
  1228. const char* linkLanguage = target.GetLinkerLanguage(i->c_str());
  1229. bool needForceLang = false;
  1230. // source file does not match its extension language
  1231. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1232. {
  1233. needForceLang = true;
  1234. lang = sourceLang;
  1235. }
  1236. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1237. // the project file
  1238. fc.ExcludedFromBuild =
  1239. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1240. if(fc.ExcludedFromBuild)
  1241. {
  1242. needfc = true;
  1243. }
  1244. // if the source file does not match the linker language
  1245. // then force c or c++
  1246. if(needForceLang || (linkLanguage && lang
  1247. && strcmp(lang, linkLanguage) != 0))
  1248. {
  1249. if(strcmp(lang, "CXX") == 0)
  1250. {
  1251. // force a C++ file type
  1252. fc.CompileFlags += " /TP ";
  1253. needfc = true;
  1254. }
  1255. else if(strcmp(lang, "C") == 0)
  1256. {
  1257. // force to c
  1258. fc.CompileFlags += " /TC ";
  1259. needfc = true;
  1260. }
  1261. }
  1262. if(needfc)
  1263. {
  1264. this->FileConfigMap[*i] = fc;
  1265. }
  1266. }
  1267. }
  1268. void cmLocalVisualStudio7Generator
  1269. ::ComputeMaxDirectoryLength(std::string& maxdir,
  1270. cmTarget& target)
  1271. {
  1272. std::vector<std::string> *configs =
  1273. static_cast<cmGlobalVisualStudio7Generator *>
  1274. (this->GlobalGenerator)->GetConfigurations();
  1275. // Compute the maximum length configuration name.
  1276. std::string config_max;
  1277. for(std::vector<std::string>::iterator i = configs->begin();
  1278. i != configs->end(); ++i)
  1279. {
  1280. if(i->size() > config_max.size())
  1281. {
  1282. config_max = *i;
  1283. }
  1284. }
  1285. // Compute the maximum length full path to the intermediate
  1286. // files directory for any configuration. This is used to construct
  1287. // object file names that do not produce paths that are too long.
  1288. std::string dir_max;
  1289. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1290. dir_max += "/";
  1291. dir_max += this->GetTargetDirectory(target);
  1292. dir_max += "/";
  1293. dir_max += config_max;
  1294. dir_max += "/";
  1295. maxdir = dir_max;
  1296. }
  1297. void cmLocalVisualStudio7Generator
  1298. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1299. std::ostream &fout, const char *libName,
  1300. std::vector<std::string> *configs)
  1301. {
  1302. const std::vector<const cmSourceFile *> &sourceFiles =
  1303. sg->GetSourceFiles();
  1304. // If the group is empty, don't write it at all.
  1305. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1306. {
  1307. return;
  1308. }
  1309. // If the group has a name, write the header.
  1310. std::string name = sg->GetName();
  1311. if(name != "")
  1312. {
  1313. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1314. }
  1315. // Compute the maximum length full path to the intermediate
  1316. // files directory for any configuration. This is used to construct
  1317. // object file names that do not produce paths that are too long.
  1318. std::string dir_max;
  1319. this->ComputeMaxDirectoryLength(dir_max, target);
  1320. // Loop through each source in the source group.
  1321. std::string objectName;
  1322. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1323. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1324. {
  1325. std::string source = (*sf)->GetFullPath();
  1326. FCInfo fcinfo(this, target, *(*sf), configs, dir_max);
  1327. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1328. target.GetType() == cmTarget::GLOBAL_TARGET )
  1329. {
  1330. fout << "\t\t\t<File\n";
  1331. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1332. // Tell MS-Dev what the source is. If the compiler knows how to
  1333. // build it, then it will.
  1334. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1335. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1336. {
  1337. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1338. }
  1339. else if(!fcinfo.FileConfigMap.empty())
  1340. {
  1341. const char* aCompilerTool = "VCCLCompilerTool";
  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. }