cmLocalVisualStudio7Generator.cxx 82 KB

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