cmLocalVisualStudio7Generator.cxx 82 KB

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