cmLocalVisualStudio7Generator.cxx 79 KB

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