cmLocalVisualStudio7Generator.cxx 78 KB

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