cmLocalVisualStudio7Generator.cxx 82 KB

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