cmLocalVisualStudio7Generator.cxx 80 KB

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