cmLocalVisualStudio7Generator.cxx 75 KB

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