cmLocalVisualStudio7Generator.cxx 78 KB

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