cmLocalVisualStudio7Generator.cxx 75 KB

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