cmLocalVisualStudio7Generator.cxx 79 KB

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