cmLocalVisualStudio7Generator.cxx 81 KB

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