cmLocalVisualStudio7Generator.cxx 79 KB

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