cmLocalVisualStudio7Generator.cxx 80 KB

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