cmLocalVisualStudio7Generator.cxx 79 KB

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