cmLocalVisualStudio7Generator.cxx 79 KB

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