cmLocalVisualStudio7Generator.cxx 82 KB

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