cmLocalVisualStudio7Generator.cxx 82 KB

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