cmLocalVisualStudio7Generator.cxx 81 KB

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