cmLocalVisualStudio7Generator.cxx 78 KB

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