cmLocalVisualStudio7Generator.cxx 80 KB

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