cmLocalVisualStudio7Generator.cxx 80 KB

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