cmLocalVisualStudio7Generator.cxx 78 KB

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