cmLocalVisualStudio7Generator.cxx 76 KB

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