cmLocalVisualStudio7Generator.cxx 79 KB

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