cmLocalVisualStudio7Generator.cxx 79 KB

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