cmLocalVisualStudio7Generator.cxx 80 KB

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