cmLocalVisualStudio7Generator.cxx 82 KB

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