cmLocalVisualStudio7Generator.cxx 75 KB

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