cmLocalVisualStudio7Generator.cxx 80 KB

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