cmLocalVisualStudio7Generator.cxx 81 KB

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