cmLocalVisualStudio7Generator.cxx 78 KB

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