1
0

cmLocalVisualStudio7Generator.cxx 81 KB

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