cmLocalVisualStudio7Generator.cxx 80 KB

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