cmLocalVisualStudio7Generator.cxx 83 KB

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