cmLocalVisualStudio7Generator.cxx 80 KB

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