cmLocalVisualStudio7Generator.cxx 82 KB

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