cmLocalVisualStudio7Generator.cxx 79 KB

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