cmLocalVisualStudio7Generator.cxx 81 KB

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