1
0

cmLocalVisualStudio7Generator.cxx 78 KB

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