cmLocalVisualStudio7Generator.cxx 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  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 "cmake.h"
  12. #include <cm_expat.h>
  13. #include "cmComputeLinkInformation.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include <ctype.h> // for isspace
  16. static bool cmLVS7G_IsFAT(const char* dir);
  17. class cmLocalVisualStudio7GeneratorInternals
  18. {
  19. public:
  20. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e)
  21. : LocalGenerator(e)
  22. {
  23. }
  24. typedef cmComputeLinkInformation::ItemVector ItemVector;
  25. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  26. void OutputObjects(std::ostream& fout, cmGeneratorTarget* t,
  27. const char* isep = 0);
  28. private:
  29. cmLocalVisualStudio7Generator* LocalGenerator;
  30. };
  31. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  32. static void cmConvertToWindowsSlash(std::string& s)
  33. {
  34. std::string::size_type pos = 0;
  35. while ((pos = s.find('/', pos)) != std::string::npos) {
  36. s[pos] = '\\';
  37. pos++;
  38. }
  39. }
  40. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator(
  41. cmGlobalGenerator* gg, cmMakefile* mf)
  42. : cmLocalVisualStudioGenerator(gg, mf)
  43. {
  44. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  45. }
  46. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  47. {
  48. delete this->Internal;
  49. }
  50. void cmLocalVisualStudio7Generator::AddHelperCommands()
  51. {
  52. // Now create GUIDs for targets
  53. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  54. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  55. l != tgts.end(); ++l) {
  56. if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  57. continue;
  58. }
  59. const char* path = (*l)->GetProperty("EXTERNAL_MSPROJECT");
  60. if (path) {
  61. this->ReadAndStoreExternalGUID((*l)->GetName().c_str(), path);
  62. }
  63. }
  64. this->FixGlobalTargets();
  65. }
  66. void cmLocalVisualStudio7Generator::Generate()
  67. {
  68. this->WriteProjectFiles();
  69. this->WriteStampFiles();
  70. }
  71. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  72. {
  73. // Create the regeneration custom rule.
  74. if (!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) {
  75. // Create a rule to regenerate the build system when the target
  76. // specification source changes.
  77. if (cmSourceFile* sf = this->CreateVCProjBuildRule()) {
  78. // Add the rule to targets that need it.
  79. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  80. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  81. l != tgts.end(); ++l) {
  82. if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) {
  83. continue;
  84. }
  85. if ((*l)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  86. (*l)->AddSource(sf->GetFullPath());
  87. }
  88. }
  89. }
  90. }
  91. }
  92. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  93. {
  94. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  95. // commands for targets in which no sources are built. Add dummy
  96. // rules to force these targets to build.
  97. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  98. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  99. l != tgts.end(); l++) {
  100. if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) {
  101. std::vector<std::string> no_depends;
  102. cmCustomCommandLine force_command;
  103. force_command.push_back("cd");
  104. force_command.push_back(".");
  105. cmCustomCommandLines force_commands;
  106. force_commands.push_back(force_command);
  107. std::string no_main_dependency = "";
  108. std::string force = this->GetCurrentBinaryDirectory();
  109. force += cmake::GetCMakeFilesDirectory();
  110. force += "/";
  111. force += (*l)->GetName();
  112. force += "_force";
  113. if (cmSourceFile* file = this->Makefile->AddCustomCommandToOutput(
  114. force.c_str(), no_depends, no_main_dependency, force_commands, " ",
  115. 0, true)) {
  116. (*l)->AddSource(file->GetFullPath());
  117. }
  118. }
  119. }
  120. }
  121. // TODO
  122. // for CommandLine= need to repleace quotes with &quot
  123. // write out configurations
  124. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  125. {
  126. // If not an in source build, then create the output directory
  127. if (strcmp(this->GetCurrentBinaryDirectory(), this->GetSourceDirectory()) !=
  128. 0) {
  129. if (!cmSystemTools::MakeDirectory(this->GetCurrentBinaryDirectory())) {
  130. cmSystemTools::Error("Error creating directory ",
  131. this->GetCurrentBinaryDirectory());
  132. }
  133. }
  134. // Get the set of targets in this directory.
  135. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  136. // Create the project file for each target.
  137. for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  138. l != tgts.end(); l++) {
  139. if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  140. continue;
  141. }
  142. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  143. // so don't build a projectfile for it
  144. if (!(*l)->GetProperty("EXTERNAL_MSPROJECT")) {
  145. this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
  146. }
  147. }
  148. }
  149. void cmLocalVisualStudio7Generator::WriteStampFiles()
  150. {
  151. // Touch a timestamp file used to determine when the project file is
  152. // out of date.
  153. std::string stampName = this->GetCurrentBinaryDirectory();
  154. stampName += cmake::GetCMakeFilesDirectory();
  155. cmSystemTools::MakeDirectory(stampName.c_str());
  156. stampName += "/";
  157. stampName += "generate.stamp";
  158. cmsys::ofstream stamp(stampName.c_str());
  159. stamp << "# CMake generation timestamp file for this directory.\n";
  160. // Create a helper file so CMake can determine when it is run
  161. // through the rule created by CreateVCProjBuildRule whether it
  162. // really needs to regenerate the project. This file lists its own
  163. // dependencies. If any file listed in it is newer than itself then
  164. // CMake must rerun. Otherwise the project files are up to date and
  165. // the stamp file can just be touched.
  166. std::string depName = stampName;
  167. depName += ".depend";
  168. cmsys::ofstream depFile(depName.c_str());
  169. depFile << "# CMake generation dependency list for this directory.\n";
  170. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  171. for (std::vector<std::string>::const_iterator lf = listFiles.begin();
  172. lf != listFiles.end(); ++lf) {
  173. depFile << *lf << std::endl;
  174. }
  175. }
  176. void cmLocalVisualStudio7Generator::CreateSingleVCProj(
  177. const std::string& lname, cmGeneratorTarget* target)
  178. {
  179. cmGlobalVisualStudioGenerator* gg =
  180. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  181. this->FortranProject = gg->TargetIsFortranOnly(target);
  182. this->WindowsCEProject = gg->TargetsWindowsCE();
  183. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  184. cmGlobalVisualStudioGenerator::VSVersion realVersion = gg->GetVersion();
  185. if (this->FortranProject &&
  186. gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS10) {
  187. gg->SetVersion(cmGlobalVisualStudioGenerator::VS9);
  188. }
  189. // add to the list of projects
  190. target->Target->SetProperty("GENERATOR_FILE_NAME", lname.c_str());
  191. // create the dsp.cmake file
  192. std::string fname;
  193. fname = this->GetCurrentBinaryDirectory();
  194. fname += "/";
  195. fname += lname;
  196. if (this->FortranProject) {
  197. fname += ".vfproj";
  198. } else {
  199. fname += ".vcproj";
  200. }
  201. // Generate the project file and replace it atomically with
  202. // copy-if-different. We use a separate timestamp so that the IDE
  203. // does not reload project files unnecessarily.
  204. cmGeneratedFileStream fout(fname.c_str());
  205. fout.SetCopyIfDifferent(true);
  206. this->WriteVCProjFile(fout, lname, target);
  207. if (fout.Close()) {
  208. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  209. }
  210. gg->SetVersion(realVersion);
  211. }
  212. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  213. {
  214. std::string stampName = this->GetCurrentBinaryDirectory();
  215. stampName += "/";
  216. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  217. stampName += "generate.stamp";
  218. cmCustomCommandLine commandLine;
  219. commandLine.push_back(cmSystemTools::GetCMakeCommand());
  220. std::string makefileIn = this->GetCurrentSourceDirectory();
  221. makefileIn += "/";
  222. makefileIn += "CMakeLists.txt";
  223. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  224. if (!cmSystemTools::FileExists(makefileIn.c_str())) {
  225. return 0;
  226. }
  227. std::string comment = "Building Custom Rule ";
  228. comment += makefileIn;
  229. std::string args;
  230. args = "-H";
  231. args += this->GetSourceDirectory();
  232. commandLine.push_back(args);
  233. args = "-B";
  234. args += this->GetBinaryDirectory();
  235. commandLine.push_back(args);
  236. commandLine.push_back("--check-stamp-file");
  237. std::string stampFilename = this->ConvertToOutputFormat(
  238. cmSystemTools::CollapseFullPath(stampName), cmOutputConverter::SHELL);
  239. commandLine.push_back(stampFilename.c_str());
  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);
  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. }
  634. if (this->FortranProject) {
  635. switch (cmOutputConverter::GetFortranFormat(
  636. target->GetProperty("Fortran_FORMAT"))) {
  637. case cmOutputConverter::FortranFormatFixed:
  638. flags += " -fixed";
  639. break;
  640. case cmOutputConverter::FortranFormatFree:
  641. flags += " -free";
  642. break;
  643. default:
  644. break;
  645. }
  646. }
  647. // Get preprocessor definitions for this directory.
  648. std::string defineFlags = this->Makefile->GetDefineFlags();
  649. Options::Tool t = Options::Compiler;
  650. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  651. if (this->FortranProject) {
  652. t = Options::FortranCompiler;
  653. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  654. }
  655. Options targetOptions(this, t, table, gg->ExtraFlagTable);
  656. targetOptions.FixExceptionHandlingDefault();
  657. std::string asmLocation = configName + "/";
  658. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  659. targetOptions.Parse(flags.c_str());
  660. targetOptions.Parse(defineFlags.c_str());
  661. targetOptions.ParseFinish();
  662. std::vector<std::string> targetDefines;
  663. target->GetCompileDefinitions(targetDefines, configName, "CXX");
  664. targetOptions.AddDefines(targetDefines);
  665. targetOptions.SetVerboseMakefile(
  666. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  667. // Add a definition for the configuration name.
  668. std::string configDefine = "CMAKE_INTDIR=\"";
  669. configDefine += configName;
  670. configDefine += "\"";
  671. targetOptions.AddDefine(configDefine);
  672. // Add the export symbol definition for shared library objects.
  673. if (const char* exportMacro = target->GetExportMacro()) {
  674. targetOptions.AddDefine(exportMacro);
  675. }
  676. // The intermediate directory name consists of a directory for the
  677. // target and a subdirectory for the configuration name.
  678. std::string intermediateDir = this->GetTargetDirectory(target);
  679. intermediateDir += "/";
  680. intermediateDir += configName;
  681. if (target->GetType() < cmStateEnums::UTILITY) {
  682. std::string const& outDir =
  683. target->GetType() == cmStateEnums::OBJECT_LIBRARY
  684. ? intermediateDir
  685. : target->GetDirectory(configName);
  686. /* clang-format off */
  687. fout << "\t\t\tOutputDirectory=\""
  688. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  689. /* clang-format on */
  690. }
  691. /* clang-format off */
  692. fout << "\t\t\tIntermediateDirectory=\""
  693. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  694. << "\"\n"
  695. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  696. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  697. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  698. /* clang-format on */
  699. if (this->FortranProject) {
  700. // Intel Fortran >= 15.0 uses TargetName property.
  701. std::string targetNameFull = target->GetFullName(configName);
  702. std::string targetName =
  703. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  704. std::string targetExt =
  705. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  706. /* clang-format off */
  707. fout <<
  708. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  709. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  710. ;
  711. /* clang-format on */
  712. }
  713. // If unicode is enabled change the character set to unicode, if not
  714. // then default to MBCS.
  715. if (targetOptions.UsingUnicode()) {
  716. fout << "\t\t\tCharacterSet=\"1\">\n";
  717. } else if (targetOptions.UsingSBCS()) {
  718. fout << "\t\t\tCharacterSet=\"0\">\n";
  719. } else {
  720. fout << "\t\t\tCharacterSet=\"2\">\n";
  721. }
  722. const char* tool = "VCCLCompilerTool";
  723. if (this->FortranProject) {
  724. tool = "VFFortranCompilerTool";
  725. }
  726. fout << "\t\t\t<Tool\n"
  727. << "\t\t\t\tName=\"" << tool << "\"\n";
  728. if (this->FortranProject) {
  729. const char* target_mod_dir =
  730. target->GetProperty("Fortran_MODULE_DIRECTORY");
  731. std::string modDir;
  732. if (target_mod_dir) {
  733. modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
  734. target_mod_dir);
  735. } else {
  736. modDir = ".";
  737. }
  738. fout << "\t\t\t\tModulePath=\""
  739. << this->ConvertToXMLOutputPath(modDir.c_str())
  740. << "\\$(ConfigurationName)\"\n";
  741. }
  742. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  743. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  744. std::vector<std::string> includes;
  745. this->GetIncludeDirectories(includes, target, "C", configName);
  746. std::vector<std::string>::iterator i = includes.begin();
  747. for (; i != includes.end(); ++i) {
  748. // output the include path
  749. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  750. fout << ipath << ";";
  751. // if this is fortran then output the include with
  752. // a ConfigurationName on the end of it.
  753. if (this->FortranProject) {
  754. ipath = i->c_str();
  755. ipath += "/$(ConfigurationName)";
  756. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  757. fout << ipath << ";";
  758. }
  759. }
  760. fout << "\"\n";
  761. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  762. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  763. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  764. if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  765. // Specify the compiler program database file if configured.
  766. std::string pdb = target->GetCompilePDBPath(configName);
  767. if (!pdb.empty()) {
  768. fout << "\t\t\t\tProgramDataBaseFileName=\""
  769. << this->ConvertToXMLOutputPathSingle(pdb.c_str()) << "\"\n";
  770. }
  771. }
  772. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  773. if (gg->IsMasmEnabled() && !this->FortranProject) {
  774. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  775. /* clang-format off */
  776. fout <<
  777. "\t\t\t<Tool\n"
  778. "\t\t\t\tName=\"MASM\"\n"
  779. "\t\t\t\tIncludePaths=\""
  780. ;
  781. /* clang-format on */
  782. const char* sep = "";
  783. for (i = includes.begin(); i != includes.end(); ++i) {
  784. std::string inc = *i;
  785. cmConvertToWindowsSlash(inc);
  786. fout << sep << this->EscapeForXML(inc);
  787. sep = ";";
  788. }
  789. fout << "\"\n";
  790. // Use same preprocessor definitions as VCCLCompilerTool.
  791. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  792. "ASM_MASM");
  793. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  794. /* clang-format off */
  795. fout <<
  796. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  797. "\t\t\t/>\n";
  798. /* clang-format on */
  799. }
  800. tool = "VCCustomBuildTool";
  801. if (this->FortranProject) {
  802. tool = "VFCustomBuildTool";
  803. }
  804. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  805. tool = "VCResourceCompilerTool";
  806. if (this->FortranProject) {
  807. tool = "VFResourceCompilerTool";
  808. }
  809. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  810. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  811. for (i = includes.begin(); i != includes.end(); ++i) {
  812. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  813. fout << ipath << ";";
  814. }
  815. // add the -D flags to the RC tool
  816. fout << "\"";
  817. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  818. fout << "/>\n";
  819. tool = "VCMIDLTool";
  820. if (this->FortranProject) {
  821. tool = "VFMIDLTool";
  822. }
  823. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  824. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  825. for (i = includes.begin(); i != includes.end(); ++i) {
  826. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  827. fout << ipath << ";";
  828. }
  829. fout << "\"\n";
  830. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  831. if (gg->GetPlatformName() == "x64") {
  832. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  833. } else if (gg->GetPlatformName() == "ia64") {
  834. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  835. } else {
  836. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  837. }
  838. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  839. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  840. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  841. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  842. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  843. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  844. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  845. // end of <Tool Name=VCMIDLTool
  846. // Add manifest tool settings.
  847. if (targetBuilds &&
  848. this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) {
  849. const char* manifestTool = "VCManifestTool";
  850. if (this->FortranProject) {
  851. manifestTool = "VFManifestTool";
  852. }
  853. /* clang-format off */
  854. fout <<
  855. "\t\t\t<Tool\n"
  856. "\t\t\t\tName=\"" << manifestTool << "\"";
  857. /* clang-format on */
  858. std::vector<cmSourceFile const*> manifest_srcs;
  859. target->GetManifests(manifest_srcs, configName);
  860. if (!manifest_srcs.empty()) {
  861. fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
  862. for (std::vector<cmSourceFile const*>::const_iterator mi =
  863. manifest_srcs.begin();
  864. mi != manifest_srcs.end(); ++mi) {
  865. std::string m = (*mi)->GetFullPath();
  866. fout << this->ConvertToXMLOutputPath(m.c_str()) << ";";
  867. }
  868. fout << "\"";
  869. }
  870. // Check if we need the FAT32 workaround.
  871. // Check the filesystem type where the target will be written.
  872. if (cmLVS7G_IsFAT(target->GetDirectory(configName).c_str())) {
  873. // Add a flag telling the manifest tool to use a workaround
  874. // for FAT32 file systems, which can cause an empty manifest
  875. // to be embedded into the resulting executable. See CMake
  876. // bug #2617.
  877. fout << "\n\t\t\t\tUseFAT32Workaround=\"true\"";
  878. }
  879. fout << "/>\n";
  880. }
  881. this->OutputTargetRules(fout, configName, target, libName);
  882. this->OutputBuildTool(fout, configName, target, targetOptions);
  883. this->OutputDeploymentDebuggerTool(fout, configName, target);
  884. fout << "\t\t</Configuration>\n";
  885. }
  886. std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
  887. std::string rootLinkerFlags, const std::string& configName)
  888. {
  889. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  890. std::string extraLinkOptionsBuildTypeDef =
  891. rootLinkerFlags + "_" + configTypeUpper;
  892. std::string extraLinkOptionsBuildType =
  893. this->Makefile->GetRequiredDefinition(
  894. extraLinkOptionsBuildTypeDef.c_str());
  895. return extraLinkOptionsBuildType;
  896. }
  897. void cmLocalVisualStudio7Generator::OutputBuildTool(
  898. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  899. const Options& targetOptions)
  900. {
  901. cmGlobalVisualStudio7Generator* gg =
  902. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  903. std::string temp;
  904. std::string extraLinkOptions;
  905. if (target->GetType() == cmStateEnums::EXECUTABLE) {
  906. extraLinkOptions =
  907. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") +
  908. std::string(" ") +
  909. GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  910. }
  911. if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  912. extraLinkOptions =
  913. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") +
  914. std::string(" ") +
  915. GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  916. }
  917. if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  918. extraLinkOptions =
  919. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") +
  920. std::string(" ") +
  921. GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  922. }
  923. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  924. if (targetLinkFlags) {
  925. extraLinkOptions += " ";
  926. extraLinkOptions += targetLinkFlags;
  927. }
  928. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  929. std::string linkFlagsConfig = "LINK_FLAGS_";
  930. linkFlagsConfig += configTypeUpper;
  931. targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
  932. if (targetLinkFlags) {
  933. extraLinkOptions += " ";
  934. extraLinkOptions += targetLinkFlags;
  935. }
  936. Options linkOptions(this, Options::Linker);
  937. if (this->FortranProject) {
  938. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  939. }
  940. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  941. linkOptions.Parse(extraLinkOptions.c_str());
  942. if (!this->ModuleDefinitionFile.empty()) {
  943. std::string defFile = this->ConvertToOutputFormat(
  944. this->ModuleDefinitionFile, cmOutputConverter::SHELL);
  945. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  946. }
  947. if ((target->GetType() == cmStateEnums::SHARED_LIBRARY ||
  948. target->IsExecutableWithExports()) &&
  949. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
  950. if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) {
  951. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)/exportall.def");
  952. }
  953. }
  954. switch (target->GetType()) {
  955. case cmStateEnums::UNKNOWN_LIBRARY:
  956. break;
  957. case cmStateEnums::OBJECT_LIBRARY: {
  958. std::string libpath = this->GetTargetDirectory(target);
  959. libpath += "/";
  960. libpath += configName;
  961. libpath += "/";
  962. libpath += target->GetName();
  963. libpath += ".lib";
  964. const char* tool =
  965. this->FortranProject ? "VFLibrarianTool" : "VCLibrarianTool";
  966. fout << "\t\t\t<Tool\n"
  967. << "\t\t\t\tName=\"" << tool << "\"\n";
  968. fout << "\t\t\t\tOutputFile=\""
  969. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  970. break;
  971. }
  972. case cmStateEnums::STATIC_LIBRARY: {
  973. std::string targetNameFull = target->GetFullName(configName);
  974. std::string libpath = target->GetDirectory(configName);
  975. libpath += "/";
  976. libpath += targetNameFull;
  977. const char* tool = "VCLibrarianTool";
  978. if (this->FortranProject) {
  979. tool = "VFLibrarianTool";
  980. }
  981. fout << "\t\t\t<Tool\n"
  982. << "\t\t\t\tName=\"" << tool << "\"\n";
  983. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  984. this->FortranProject) {
  985. std::ostringstream libdeps;
  986. this->Internal->OutputObjects(libdeps, target);
  987. if (!libdeps.str().empty()) {
  988. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str()
  989. << "\"\n";
  990. }
  991. }
  992. std::string libflags;
  993. this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
  994. if (!libflags.empty()) {
  995. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  996. }
  997. fout << "\t\t\t\tOutputFile=\""
  998. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  999. break;
  1000. }
  1001. case cmStateEnums::SHARED_LIBRARY:
  1002. case cmStateEnums::MODULE_LIBRARY: {
  1003. std::string targetName;
  1004. std::string targetNameSO;
  1005. std::string targetNameFull;
  1006. std::string targetNameImport;
  1007. std::string targetNamePDB;
  1008. target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1009. targetNameImport, targetNamePDB, configName);
  1010. // Compute the link library and directory information.
  1011. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1012. if (!pcli) {
  1013. return;
  1014. }
  1015. cmComputeLinkInformation& cli = *pcli;
  1016. std::string linkLanguage = cli.GetLinkLanguage();
  1017. // Compute the variable name to lookup standard libraries for this
  1018. // language.
  1019. std::string standardLibsVar = "CMAKE_";
  1020. standardLibsVar += linkLanguage;
  1021. standardLibsVar += "_STANDARD_LIBRARIES";
  1022. const char* tool = "VCLinkerTool";
  1023. if (this->FortranProject) {
  1024. tool = "VFLinkerTool";
  1025. }
  1026. fout << "\t\t\t<Tool\n"
  1027. << "\t\t\t\tName=\"" << tool << "\"\n";
  1028. if (!gg->NeedLinkLibraryDependencies(target)) {
  1029. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1030. }
  1031. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1032. // Use the NOINHERIT macro to avoid getting VS project default
  1033. // libraries which may be set by the user to something bad.
  1034. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1035. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1036. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  1037. this->FortranProject) {
  1038. this->Internal->OutputObjects(fout, target, " ");
  1039. }
  1040. fout << " ";
  1041. this->Internal->OutputLibraries(fout, cli.GetItems());
  1042. fout << "\"\n";
  1043. temp = target->GetDirectory(configName);
  1044. temp += "/";
  1045. temp += targetNameFull;
  1046. fout << "\t\t\t\tOutputFile=\""
  1047. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1048. this->WriteTargetVersionAttribute(fout, target);
  1049. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1050. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1051. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1052. fout << "\"\n";
  1053. temp = target->GetPDBDirectory(configName);
  1054. temp += "/";
  1055. temp += targetNamePDB;
  1056. fout << "\t\t\t\tProgramDatabaseFile=\""
  1057. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1058. if (targetOptions.IsDebug()) {
  1059. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1060. }
  1061. if (this->WindowsCEProject) {
  1062. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1063. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1064. } else {
  1065. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1066. }
  1067. }
  1068. std::string stackVar = "CMAKE_";
  1069. stackVar += linkLanguage;
  1070. stackVar += "_STACK_SIZE";
  1071. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1072. if (stackVal) {
  1073. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1074. }
  1075. temp = target->GetDirectory(configName, true);
  1076. temp += "/";
  1077. temp += targetNameImport;
  1078. fout << "\t\t\t\tImportLibrary=\""
  1079. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1080. if (this->FortranProject) {
  1081. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1082. }
  1083. fout << "/>\n";
  1084. } break;
  1085. case cmStateEnums::EXECUTABLE: {
  1086. std::string targetName;
  1087. std::string targetNameFull;
  1088. std::string targetNameImport;
  1089. std::string targetNamePDB;
  1090. target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
  1091. targetNamePDB, configName);
  1092. // Compute the link library and directory information.
  1093. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1094. if (!pcli) {
  1095. return;
  1096. }
  1097. cmComputeLinkInformation& cli = *pcli;
  1098. std::string linkLanguage = cli.GetLinkLanguage();
  1099. bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
  1100. // Compute the variable name to lookup standard libraries for this
  1101. // language.
  1102. std::string standardLibsVar = "CMAKE_";
  1103. standardLibsVar += linkLanguage;
  1104. standardLibsVar += "_STANDARD_LIBRARIES";
  1105. const char* tool = "VCLinkerTool";
  1106. if (this->FortranProject) {
  1107. tool = "VFLinkerTool";
  1108. }
  1109. fout << "\t\t\t<Tool\n"
  1110. << "\t\t\t\tName=\"" << tool << "\"\n";
  1111. if (!gg->NeedLinkLibraryDependencies(target)) {
  1112. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1113. }
  1114. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1115. // Use the NOINHERIT macro to avoid getting VS project default
  1116. // libraries which may be set by the user to something bad.
  1117. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1118. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1119. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS8 ||
  1120. this->FortranProject) {
  1121. this->Internal->OutputObjects(fout, target, " ");
  1122. }
  1123. fout << " ";
  1124. this->Internal->OutputLibraries(fout, cli.GetItems());
  1125. fout << "\"\n";
  1126. temp = target->GetDirectory(configName);
  1127. temp += "/";
  1128. temp += targetNameFull;
  1129. fout << "\t\t\t\tOutputFile=\""
  1130. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1131. this->WriteTargetVersionAttribute(fout, target);
  1132. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1133. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1134. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1135. fout << "\"\n";
  1136. std::string path = this->ConvertToXMLOutputPathSingle(
  1137. target->GetPDBDirectory(configName).c_str());
  1138. fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB
  1139. << "\"\n";
  1140. if (targetOptions.IsDebug()) {
  1141. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1142. }
  1143. if (this->WindowsCEProject) {
  1144. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1145. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1146. } else {
  1147. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1148. }
  1149. if (!linkOptions.GetFlag("EntryPointSymbol")) {
  1150. const char* entryPointSymbol = targetOptions.UsingUnicode()
  1151. ? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
  1152. : (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1153. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1154. }
  1155. } else if (this->FortranProject) {
  1156. fout << "\t\t\t\tSubSystem=\""
  1157. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1158. << "\"\n";
  1159. } else {
  1160. fout << "\t\t\t\tSubSystem=\"" << (isWin32Executable ? "2" : "1")
  1161. << "\"\n";
  1162. }
  1163. std::string stackVar = "CMAKE_";
  1164. stackVar += linkLanguage;
  1165. stackVar += "_STACK_SIZE";
  1166. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1167. if (stackVal) {
  1168. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1169. }
  1170. temp = target->GetDirectory(configName, true);
  1171. temp += "/";
  1172. temp += targetNameImport;
  1173. fout << "\t\t\t\tImportLibrary=\""
  1174. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1175. break;
  1176. }
  1177. case cmStateEnums::UTILITY:
  1178. case cmStateEnums::GLOBAL_TARGET:
  1179. case cmStateEnums::INTERFACE_LIBRARY:
  1180. break;
  1181. }
  1182. }
  1183. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1184. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1185. {
  1186. if (this->WindowsCEProject) {
  1187. if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY")) {
  1188. /* clang-format off */
  1189. fout <<
  1190. "\t\t\t<DeploymentTool\n"
  1191. "\t\t\t\tForceDirty=\"-1\"\n"
  1192. "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
  1193. "\t\t\t\tRegisterOutput=\"0\"\n"
  1194. "\t\t\t\tAdditionalFiles=\"\"/>\n"
  1195. ;
  1196. /* clang-format on */
  1197. std::string const exe =
  1198. dir + std::string("\\") + target->GetFullName(config);
  1199. /* clang-format off */
  1200. fout <<
  1201. "\t\t\t<DebuggerTool\n"
  1202. "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
  1203. "\t\t\t\tArguments=\"\"\n"
  1204. "\t\t\t/>\n"
  1205. ;
  1206. /* clang-format on */
  1207. }
  1208. }
  1209. }
  1210. void cmLocalVisualStudio7Generator::WriteTargetVersionAttribute(
  1211. std::ostream& fout, cmGeneratorTarget* gt)
  1212. {
  1213. int major;
  1214. int minor;
  1215. gt->GetTargetVersion(major, minor);
  1216. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1217. }
  1218. void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
  1219. std::ostream& fout, ItemVector const& libs)
  1220. {
  1221. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1222. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1223. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  1224. if (l->IsPath) {
  1225. std::string rel =
  1226. lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
  1227. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1228. } else if (!l->Target ||
  1229. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1230. fout << l->Value << " ";
  1231. }
  1232. }
  1233. }
  1234. void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
  1235. std::ostream& fout, cmGeneratorTarget* gt, const char* isep)
  1236. {
  1237. // VS < 8 does not support per-config source locations so we
  1238. // list object library content on the link line instead.
  1239. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1240. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1241. std::vector<std::string> objs;
  1242. gt->UseObjectLibraries(objs, "");
  1243. const char* sep = isep ? isep : "";
  1244. for (std::vector<std::string>::const_iterator oi = objs.begin();
  1245. oi != objs.end(); ++oi) {
  1246. std::string rel = lg->ConvertToRelativePath(currentBinDir, oi->c_str());
  1247. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1248. sep = " ";
  1249. }
  1250. }
  1251. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
  1252. std::ostream& fout, std::vector<std::string> const& dirs)
  1253. {
  1254. const char* comma = "";
  1255. std::string currentBinDir = this->GetCurrentBinaryDirectory();
  1256. for (std::vector<std::string>::const_iterator d = dirs.begin();
  1257. d != dirs.end(); ++d) {
  1258. // Remove any trailing slash and skip empty paths.
  1259. std::string dir = *d;
  1260. if (dir[dir.size() - 1] == '/') {
  1261. dir = dir.substr(0, dir.size() - 1);
  1262. }
  1263. if (dir.empty()) {
  1264. continue;
  1265. }
  1266. // Switch to a relative path specification if it is shorter.
  1267. if (cmSystemTools::FileIsFullPath(dir.c_str())) {
  1268. std::string rel =
  1269. this->ConvertToRelativePath(currentBinDir, dir.c_str());
  1270. if (rel.size() < dir.size()) {
  1271. dir = rel;
  1272. }
  1273. }
  1274. // First search a configuration-specific subdirectory and then the
  1275. // original directory.
  1276. fout << comma
  1277. << this->ConvertToXMLOutputPath(
  1278. (dir + "/$(ConfigurationName)").c_str())
  1279. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1280. comma = ",";
  1281. }
  1282. }
  1283. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1284. const std::string& libName,
  1285. cmGeneratorTarget* target)
  1286. {
  1287. std::vector<std::string> configs;
  1288. this->Makefile->GetConfigurations(configs);
  1289. // We may be modifying the source groups temporarily, so make a copy.
  1290. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1291. // get the classes from the source lists then add them to the groups
  1292. this->ModuleDefinitionFile = "";
  1293. std::vector<cmSourceFile*> classes;
  1294. if (!target->GetConfigCommonSourceFiles(classes)) {
  1295. return;
  1296. }
  1297. for (std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1298. i != classes.end(); i++) {
  1299. if (!(*i)->GetObjectLibrary().empty()) {
  1300. continue;
  1301. }
  1302. // Add the file to the list of sources.
  1303. std::string source = (*i)->GetFullPath();
  1304. if (cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") {
  1305. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1306. }
  1307. cmSourceGroup* sourceGroup =
  1308. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1309. sourceGroup->AssignSource(*i);
  1310. }
  1311. // open the project
  1312. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1313. // write the configuration information
  1314. this->WriteConfigurations(fout, configs, libName, target);
  1315. fout << "\t<Files>\n";
  1316. // Loop through every source group.
  1317. for (unsigned int i = 0; i < sourceGroups.size(); ++i) {
  1318. cmSourceGroup sg = sourceGroups[i];
  1319. this->WriteGroup(&sg, target, fout, libName, configs);
  1320. }
  1321. if (this->GetVersion() >= cmGlobalVisualStudioGenerator::VS8 &&
  1322. !this->FortranProject) {
  1323. // VS >= 8 support per-config source locations so we
  1324. // list object library content as external objects.
  1325. std::vector<std::string> objs;
  1326. target->UseObjectLibraries(objs, "");
  1327. if (!objs.empty()) {
  1328. // TODO: Separate sub-filter for each object library used?
  1329. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1330. for (std::vector<std::string>::const_iterator oi = objs.begin();
  1331. oi != objs.end(); ++oi) {
  1332. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1333. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1334. }
  1335. fout << "\t\t</Filter>\n";
  1336. }
  1337. }
  1338. fout << "\t</Files>\n";
  1339. // Write the VCProj file's footer.
  1340. this->WriteVCProjFooter(fout, target);
  1341. }
  1342. struct cmLVS7GFileConfig
  1343. {
  1344. std::string ObjectName;
  1345. std::string CompileFlags;
  1346. std::string CompileDefs;
  1347. std::string CompileDefsConfig;
  1348. std::string AdditionalDeps;
  1349. bool ExcludedFromBuild;
  1350. };
  1351. class cmLocalVisualStudio7GeneratorFCInfo
  1352. {
  1353. public:
  1354. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1355. cmGeneratorTarget* target,
  1356. cmSourceFile const& sf,
  1357. std::vector<std::string> const& configs);
  1358. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1359. };
  1360. cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
  1361. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt,
  1362. cmSourceFile const& sf, std::vector<std::string> const& configs)
  1363. {
  1364. std::string objectName;
  1365. if (gt->HasExplicitObjectName(&sf)) {
  1366. objectName = gt->GetObjectName(&sf);
  1367. }
  1368. // Compute per-source, per-config information.
  1369. for (std::vector<std::string>::const_iterator i = configs.begin();
  1370. i != configs.end(); ++i) {
  1371. std::string configUpper = cmSystemTools::UpperCase(*i);
  1372. cmLVS7GFileConfig fc;
  1373. bool needfc = false;
  1374. if (!objectName.empty()) {
  1375. fc.ObjectName = objectName;
  1376. needfc = true;
  1377. }
  1378. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1379. fc.CompileFlags = cflags;
  1380. needfc = true;
  1381. }
  1382. if (lg->FortranProject) {
  1383. switch (cmOutputConverter::GetFortranFormat(
  1384. sf.GetProperty("Fortran_FORMAT"))) {
  1385. case cmOutputConverter::FortranFormatFixed:
  1386. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1387. needfc = true;
  1388. break;
  1389. case cmOutputConverter::FortranFormatFree:
  1390. fc.CompileFlags = "-free " + fc.CompileFlags;
  1391. needfc = true;
  1392. break;
  1393. default:
  1394. break;
  1395. }
  1396. }
  1397. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1398. fc.CompileDefs = cdefs;
  1399. needfc = true;
  1400. }
  1401. std::string defPropName = "COMPILE_DEFINITIONS_";
  1402. defPropName += configUpper;
  1403. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1404. fc.CompileDefsConfig = ccdefs;
  1405. needfc = true;
  1406. }
  1407. // Check for extra object-file dependencies.
  1408. if (const char* deps = sf.GetProperty("OBJECT_DEPENDS")) {
  1409. std::vector<std::string> depends;
  1410. cmSystemTools::ExpandListArgument(deps, depends);
  1411. const char* sep = "";
  1412. for (std::vector<std::string>::iterator j = depends.begin();
  1413. j != depends.end(); ++j) {
  1414. fc.AdditionalDeps += sep;
  1415. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1416. sep = ";";
  1417. needfc = true;
  1418. }
  1419. }
  1420. std::string lang =
  1421. lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1422. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1423. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1424. bool needForceLang = false;
  1425. // source file does not match its extension language
  1426. if (lang != sourceLang) {
  1427. needForceLang = true;
  1428. lang = sourceLang;
  1429. }
  1430. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1431. // the project file
  1432. fc.ExcludedFromBuild = (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1433. if (fc.ExcludedFromBuild) {
  1434. needfc = true;
  1435. }
  1436. // if the source file does not match the linker language
  1437. // then force c or c++
  1438. if (needForceLang || (linkLanguage != lang)) {
  1439. if (lang == "CXX") {
  1440. // force a C++ file type
  1441. fc.CompileFlags += " /TP ";
  1442. needfc = true;
  1443. } else if (lang == "C") {
  1444. // force to c
  1445. fc.CompileFlags += " /TC ";
  1446. needfc = true;
  1447. }
  1448. }
  1449. if (needfc) {
  1450. this->FileConfigMap[*i] = fc;
  1451. }
  1452. }
  1453. }
  1454. std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
  1455. cmGeneratorTarget const* target) const
  1456. {
  1457. std::vector<std::string> configs;
  1458. target->Target->GetMakefile()->GetConfigurations(configs);
  1459. // Compute the maximum length configuration name.
  1460. std::string config_max;
  1461. for (std::vector<std::string>::iterator i = configs.begin();
  1462. i != configs.end(); ++i) {
  1463. if (i->size() > config_max.size()) {
  1464. config_max = *i;
  1465. }
  1466. }
  1467. // Compute the maximum length full path to the intermediate
  1468. // files directory for any configuration. This is used to construct
  1469. // object file names that do not produce paths that are too long.
  1470. std::string dir_max;
  1471. dir_max += this->GetCurrentBinaryDirectory();
  1472. dir_max += "/";
  1473. dir_max += this->GetTargetDirectory(target);
  1474. dir_max += "/";
  1475. dir_max += config_max;
  1476. dir_max += "/";
  1477. return dir_max;
  1478. }
  1479. bool cmLocalVisualStudio7Generator::WriteGroup(
  1480. const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
  1481. const std::string& libName, std::vector<std::string> const& configs)
  1482. {
  1483. cmGlobalVisualStudio7Generator* gg =
  1484. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1485. const std::vector<const cmSourceFile*>& sourceFiles = sg->GetSourceFiles();
  1486. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1487. // Write the children to temporary output.
  1488. bool hasChildrenWithSources = false;
  1489. std::ostringstream tmpOut;
  1490. for (unsigned int i = 0; i < children.size(); ++i) {
  1491. if (this->WriteGroup(&children[i], target, tmpOut, libName, configs)) {
  1492. hasChildrenWithSources = true;
  1493. }
  1494. }
  1495. // If the group is empty, don't write it at all.
  1496. if (sourceFiles.empty() && !hasChildrenWithSources) {
  1497. return false;
  1498. }
  1499. // If the group has a name, write the header.
  1500. std::string name = sg->GetName();
  1501. if (name != "") {
  1502. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1503. }
  1504. // Loop through each source in the source group.
  1505. for (std::vector<const cmSourceFile*>::const_iterator sf =
  1506. sourceFiles.begin();
  1507. sf != sourceFiles.end(); ++sf) {
  1508. std::string source = (*sf)->GetFullPath();
  1509. FCInfo fcinfo(this, target, *(*sf), configs);
  1510. if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
  1511. target->GetType() == cmStateEnums::GLOBAL_TARGET) {
  1512. fout << "\t\t\t<File\n";
  1513. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1514. // Tell MS-Dev what the source is. If the compiler knows how to
  1515. // build it, then it will.
  1516. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1517. if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) {
  1518. this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
  1519. } else if (!fcinfo.FileConfigMap.empty()) {
  1520. const char* aCompilerTool = "VCCLCompilerTool";
  1521. const char* ppLang = "CXX";
  1522. if (this->FortranProject) {
  1523. aCompilerTool = "VFFortranCompilerTool";
  1524. }
  1525. std::string const& lang = (*sf)->GetLanguage();
  1526. std::string ext = (*sf)->GetExtension();
  1527. ext = cmSystemTools::LowerCase(ext);
  1528. if (ext == "idl") {
  1529. aCompilerTool = "VCMIDLTool";
  1530. if (this->FortranProject) {
  1531. aCompilerTool = "VFMIDLTool";
  1532. }
  1533. }
  1534. if (ext == "rc") {
  1535. aCompilerTool = "VCResourceCompilerTool";
  1536. ppLang = "RC";
  1537. if (this->FortranProject) {
  1538. aCompilerTool = "VFResourceCompilerTool";
  1539. }
  1540. }
  1541. if (ext == "def") {
  1542. aCompilerTool = "VCCustomBuildTool";
  1543. if (this->FortranProject) {
  1544. aCompilerTool = "VFCustomBuildTool";
  1545. }
  1546. }
  1547. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1548. lang == "ASM_MASM") {
  1549. aCompilerTool = "MASM";
  1550. }
  1551. for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
  1552. fcinfo.FileConfigMap.begin();
  1553. fci != fcinfo.FileConfigMap.end(); ++fci) {
  1554. cmLVS7GFileConfig const& fc = fci->second;
  1555. fout << "\t\t\t\t<FileConfiguration\n"
  1556. << "\t\t\t\t\tName=\"" << fci->first << "|"
  1557. << gg->GetPlatformName() << "\"";
  1558. if (fc.ExcludedFromBuild) {
  1559. fout << " ExcludedFromBuild=\"true\"";
  1560. }
  1561. fout << ">\n";
  1562. fout << "\t\t\t\t\t<Tool\n"
  1563. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1564. if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
  1565. !fc.CompileDefsConfig.empty()) {
  1566. Options::Tool tool = Options::Compiler;
  1567. cmVS7FlagTable const* table =
  1568. cmLocalVisualStudio7GeneratorFlagTable;
  1569. if (this->FortranProject) {
  1570. tool = Options::FortranCompiler;
  1571. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1572. }
  1573. Options fileOptions(this, tool, table, gg->ExtraFlagTable);
  1574. fileOptions.Parse(fc.CompileFlags.c_str());
  1575. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1576. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1577. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  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. if ((target->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1721. target->IsExecutableWithExports()) &&
  1722. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
  1723. if (target->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) {
  1724. addedPrelink = true;
  1725. std::vector<cmCustomCommand> commands = target->GetPreLinkCommands();
  1726. cmGlobalVisualStudioGenerator* gg =
  1727. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1728. gg->AddSymbolExportCommand(target, commands, configName);
  1729. event.Write(commands);
  1730. }
  1731. }
  1732. if (!addedPrelink) {
  1733. event.Write(target->GetPreLinkCommands());
  1734. }
  1735. CM_AUTO_PTR<cmCustomCommand> pcc(
  1736. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1737. if (pcc.get()) {
  1738. event.Write(*pcc);
  1739. }
  1740. event.Finish();
  1741. // Add post-build event.
  1742. tool =
  1743. this->FortranProject ? "VFPostBuildEventTool" : "VCPostBuildEventTool";
  1744. event.Start(tool);
  1745. event.Write(target->GetPostBuildCommands());
  1746. event.Finish();
  1747. }
  1748. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1749. cmGeneratorTarget* target)
  1750. {
  1751. // if we have all the required Source code control tags
  1752. // then add that to the project
  1753. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1754. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1755. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1756. if (vsProvider && vsLocalpath && vsProjectname) {
  1757. /* clang-format off */
  1758. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1759. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1760. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1761. /* clang-format on */
  1762. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1763. if (vsAuxPath) {
  1764. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1765. }
  1766. }
  1767. }
  1768. void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
  1769. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target)
  1770. {
  1771. cmGlobalVisualStudio7Generator* gg =
  1772. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1773. /* clang-format off */
  1774. fout << "<?xml version=\"1.0\" encoding = \""
  1775. << gg->Encoding() << "\"?>\n"
  1776. << "<VisualStudioProject\n"
  1777. << "\tProjectCreator=\"Intel Fortran\"\n"
  1778. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1779. /* clang-format on */
  1780. const char* keyword = target->GetProperty("VS_KEYWORD");
  1781. if (!keyword) {
  1782. keyword = "Console Application";
  1783. }
  1784. const char* projectType = 0;
  1785. switch (target->GetType()) {
  1786. case cmStateEnums::STATIC_LIBRARY:
  1787. projectType = "typeStaticLibrary";
  1788. if (keyword) {
  1789. keyword = "Static Library";
  1790. }
  1791. break;
  1792. case cmStateEnums::SHARED_LIBRARY:
  1793. case cmStateEnums::MODULE_LIBRARY:
  1794. projectType = "typeDynamicLibrary";
  1795. if (!keyword) {
  1796. keyword = "Dll";
  1797. }
  1798. break;
  1799. case cmStateEnums::EXECUTABLE:
  1800. if (!keyword) {
  1801. keyword = "Console Application";
  1802. }
  1803. projectType = 0;
  1804. break;
  1805. case cmStateEnums::UTILITY:
  1806. case cmStateEnums::GLOBAL_TARGET:
  1807. default:
  1808. break;
  1809. }
  1810. if (projectType) {
  1811. fout << "\tProjectType=\"" << projectType << "\"\n";
  1812. }
  1813. this->WriteProjectSCC(fout, target);
  1814. /* clang-format off */
  1815. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1816. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1817. << "\t<Platforms>\n"
  1818. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1819. << "\t</Platforms>\n";
  1820. /* clang-format on */
  1821. }
  1822. void cmLocalVisualStudio7Generator::WriteProjectStart(
  1823. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target,
  1824. std::vector<cmSourceGroup>&)
  1825. {
  1826. if (this->FortranProject) {
  1827. this->WriteProjectStartFortran(fout, libName, target);
  1828. return;
  1829. }
  1830. cmGlobalVisualStudio7Generator* gg =
  1831. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1832. /* clang-format off */
  1833. fout << "<?xml version=\"1.0\" encoding = \""
  1834. << gg->Encoding() << "\"?>\n"
  1835. << "<VisualStudioProject\n"
  1836. << "\tProjectType=\"Visual C++\"\n";
  1837. /* clang-format on */
  1838. if (gg->GetVersion() == cmGlobalVisualStudioGenerator::VS71) {
  1839. fout << "\tVersion=\"7.10\"\n";
  1840. } else {
  1841. fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n";
  1842. }
  1843. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  1844. if (!projLabel) {
  1845. projLabel = libName.c_str();
  1846. }
  1847. const char* keyword = target->GetProperty("VS_KEYWORD");
  1848. if (!keyword) {
  1849. keyword = "Win32Proj";
  1850. }
  1851. fout << "\tName=\"" << projLabel << "\"\n";
  1852. if (gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS8) {
  1853. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1854. }
  1855. this->WriteProjectSCC(fout, target);
  1856. if (const char* targetFrameworkVersion =
  1857. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  1858. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1859. }
  1860. /* clang-format off */
  1861. fout << "\tKeyword=\"" << keyword << "\">\n"
  1862. << "\t<Platforms>\n"
  1863. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1864. << "\t</Platforms>\n";
  1865. /* clang-format on */
  1866. if (gg->IsMasmEnabled()) {
  1867. /* clang-format off */
  1868. fout <<
  1869. "\t<ToolFiles>\n"
  1870. "\t\t<DefaultToolFile\n"
  1871. "\t\t\tFileName=\"masm.rules\"\n"
  1872. "\t\t/>\n"
  1873. "\t</ToolFiles>\n"
  1874. ;
  1875. /* clang-format on */
  1876. }
  1877. }
  1878. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  1879. std::ostream& fout, cmGeneratorTarget* target)
  1880. {
  1881. fout << "\t<Globals>\n";
  1882. std::vector<std::string> const& props = target->GetPropertyKeys();
  1883. for (std::vector<std::string>::const_iterator i = props.begin();
  1884. i != props.end(); ++i) {
  1885. if (i->find("VS_GLOBAL_") == 0) {
  1886. std::string name = i->substr(10);
  1887. if (name != "") {
  1888. /* clang-format off */
  1889. fout << "\t\t<Global\n"
  1890. << "\t\t\tName=\"" << name << "\"\n"
  1891. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  1892. << "\t\t/>\n";
  1893. /* clang-format on */
  1894. }
  1895. }
  1896. }
  1897. fout << "\t</Globals>\n"
  1898. << "</VisualStudioProject>\n";
  1899. }
  1900. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  1901. {
  1902. std::string ret = s;
  1903. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1904. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1905. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1906. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1907. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1908. return ret;
  1909. }
  1910. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  1911. {
  1912. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1913. }
  1914. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(
  1915. const char* path)
  1916. {
  1917. std::string ret =
  1918. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1919. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1920. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1921. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1922. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1923. return ret;
  1924. }
  1925. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
  1926. const char* path)
  1927. {
  1928. std::string ret =
  1929. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1930. cmSystemTools::ReplaceString(ret, "\"", "");
  1931. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1932. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1933. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1934. return ret;
  1935. }
  1936. // This class is used to parse an existing vs 7 project
  1937. // and extract the GUID
  1938. class cmVS7XMLParser : public cmXMLParser
  1939. {
  1940. public:
  1941. virtual void EndElement(const std::string& /* name */) {}
  1942. virtual void StartElement(const std::string& name, const char** atts)
  1943. {
  1944. // once the GUID is found do nothing
  1945. if (!this->GUID.empty()) {
  1946. return;
  1947. }
  1948. int i = 0;
  1949. if ("VisualStudioProject" == name) {
  1950. while (atts[i]) {
  1951. if (strcmp(atts[i], "ProjectGUID") == 0) {
  1952. if (atts[i + 1]) {
  1953. this->GUID = atts[i + 1];
  1954. this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
  1955. } else {
  1956. this->GUID = "";
  1957. }
  1958. return;
  1959. }
  1960. ++i;
  1961. }
  1962. }
  1963. }
  1964. int InitializeParser()
  1965. {
  1966. int ret = cmXMLParser::InitializeParser();
  1967. if (ret == 0) {
  1968. return ret;
  1969. }
  1970. // visual studio projects have a strange encoding, but it is
  1971. // really utf-8
  1972. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1973. return 1;
  1974. }
  1975. std::string GUID;
  1976. };
  1977. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1978. const std::string& name, const char* path)
  1979. {
  1980. cmVS7XMLParser parser;
  1981. parser.ParseFile(path);
  1982. // if we can not find a GUID then we will generate one later
  1983. if (parser.GUID.empty()) {
  1984. return;
  1985. }
  1986. std::string guidStoreName = name;
  1987. guidStoreName += "_GUID_CMAKE";
  1988. // save the GUID in the cache
  1989. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  1990. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  1991. cmStateEnums::INTERNAL);
  1992. }
  1993. std::string cmLocalVisualStudio7Generator::GetTargetDirectory(
  1994. cmGeneratorTarget const* target) const
  1995. {
  1996. std::string dir;
  1997. dir += target->GetName();
  1998. dir += ".dir";
  1999. return dir;
  2000. }
  2001. #include <windows.h>
  2002. static bool cmLVS7G_IsFAT(const char* dir)
  2003. {
  2004. if (dir[0] && dir[1] == ':') {
  2005. char volRoot[4] = "_:/";
  2006. volRoot[0] = dir[0];
  2007. char fsName[16];
  2008. if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2009. strstr(fsName, "FAT") != 0) {
  2010. return true;
  2011. }
  2012. }
  2013. return false;
  2014. }