cmLocalVisualStudio7Generator.cxx 79 KB

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