cmLocalVisualStudio7Generator.cxx 79 KB

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