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(VSVersion v, cmGlobalGenerator* gg,
  49. cmLocalGenerator* parent):
  50. cmLocalVisualStudioGenerator(v, gg, parent)
  51. {
  52. this->ExtraFlagTable = 0;
  53. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  54. }
  55. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  56. {
  57. delete this->Internal;
  58. }
  59. void cmLocalVisualStudio7Generator::AddHelperCommands()
  60. {
  61. std::set<std::string> lang;
  62. lang.insert("C");
  63. lang.insert("CXX");
  64. lang.insert("RC");
  65. lang.insert("IDL");
  66. lang.insert("DEF");
  67. lang.insert("Fortran");
  68. this->CreateCustomTargetsAndCommands(lang);
  69. // Now create GUIDs for targets
  70. cmTargets &tgts = this->Makefile->GetTargets();
  71. cmGlobalVisualStudio7Generator* gg =
  72. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  73. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  74. {
  75. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  76. {
  77. continue;
  78. }
  79. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  80. if(path)
  81. {
  82. this->ReadAndStoreExternalGUID(
  83. l->second.GetName().c_str(), path);
  84. }
  85. else
  86. {
  87. gg->CreateGUID(l->first.c_str());
  88. }
  89. }
  90. this->FixGlobalTargets();
  91. }
  92. void cmLocalVisualStudio7Generator::Generate()
  93. {
  94. this->WriteProjectFiles();
  95. this->WriteStampFiles();
  96. }
  97. void cmLocalVisualStudio7Generator::AddCMakeListsRules()
  98. {
  99. cmTargets &tgts = this->Makefile->GetTargets();
  100. // Create the regeneration custom rule.
  101. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  102. {
  103. // Create a rule to regenerate the build system when the target
  104. // specification source changes.
  105. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  106. {
  107. // Add the rule to targets that need it.
  108. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  109. {
  110. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  111. {
  112. l->second.AddSource(sf->GetFullPath());
  113. }
  114. }
  115. }
  116. }
  117. }
  118. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  119. {
  120. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  121. // commands for targets in which no sources are built. Add dummy
  122. // rules to force these targets to build.
  123. cmTargets &tgts = this->Makefile->GetTargets();
  124. for(cmTargets::iterator l = tgts.begin();
  125. l != tgts.end(); l++)
  126. {
  127. cmTarget& tgt = l->second;
  128. if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
  129. {
  130. std::vector<std::string> no_depends;
  131. cmCustomCommandLine force_command;
  132. force_command.push_back("cd");
  133. force_command.push_back(".");
  134. cmCustomCommandLines force_commands;
  135. force_commands.push_back(force_command);
  136. std::string no_main_dependency = "";
  137. std::string force = this->Makefile->GetCurrentBinaryDirectory();
  138. force += cmake::GetCMakeFilesDirectory();
  139. force += "/";
  140. force += tgt.GetName();
  141. force += "_force";
  142. if(cmSourceFile* file =
  143. this->Makefile->AddCustomCommandToOutput(
  144. force.c_str(), no_depends, no_main_dependency,
  145. force_commands, " ", 0, true))
  146. {
  147. tgt.AddSource(file->GetFullPath());
  148. }
  149. }
  150. }
  151. }
  152. // TODO
  153. // for CommandLine= need to repleace quotes with &quot
  154. // write out configurations
  155. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  156. {
  157. // If not an in source build, then create the output directory
  158. if(strcmp(this->Makefile->GetCurrentBinaryDirectory(),
  159. this->Makefile->GetHomeDirectory()) != 0)
  160. {
  161. if(!cmSystemTools::MakeDirectory
  162. (this->Makefile->GetCurrentBinaryDirectory()))
  163. {
  164. cmSystemTools::Error("Error creating directory ",
  165. this->Makefile->GetCurrentBinaryDirectory());
  166. }
  167. }
  168. // Get the set of targets in this directory.
  169. cmTargets &tgts = this->Makefile->GetTargets();
  170. // Create the project file for each target.
  171. for(cmTargets::iterator l = tgts.begin();
  172. l != tgts.end(); l++)
  173. {
  174. if(l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  175. {
  176. continue;
  177. }
  178. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  179. // so don't build a projectfile for it
  180. if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
  181. {
  182. this->CreateSingleVCProj(l->first.c_str(),l->second);
  183. }
  184. }
  185. }
  186. //----------------------------------------------------------------------------
  187. void cmLocalVisualStudio7Generator::WriteStampFiles()
  188. {
  189. // Touch a timestamp file used to determine when the project file is
  190. // out of date.
  191. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  192. stampName += cmake::GetCMakeFilesDirectory();
  193. cmSystemTools::MakeDirectory(stampName.c_str());
  194. stampName += "/";
  195. stampName += "generate.stamp";
  196. cmsys::ofstream stamp(stampName.c_str());
  197. stamp << "# CMake generation timestamp file for this directory.\n";
  198. // Create a helper file so CMake can determine when it is run
  199. // through the rule created by CreateVCProjBuildRule whether it
  200. // really needs to regenerate the project. This file lists its own
  201. // dependencies. If any file listed in it is newer than itself then
  202. // CMake must rerun. Otherwise the project files are up to date and
  203. // the stamp file can just be touched.
  204. std::string depName = stampName;
  205. depName += ".depend";
  206. cmsys::ofstream depFile(depName.c_str());
  207. depFile << "# CMake generation dependency list for this directory.\n";
  208. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  209. for(std::vector<std::string>::const_iterator lf = listFiles.begin();
  210. lf != listFiles.end(); ++lf)
  211. {
  212. depFile << *lf << std::endl;
  213. }
  214. }
  215. //----------------------------------------------------------------------------
  216. void cmLocalVisualStudio7Generator
  217. ::CreateSingleVCProj(const std::string& lname, cmTarget &target)
  218. {
  219. this->FortranProject =
  220. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  221. ->TargetIsFortranOnly(target);
  222. this->WindowsCEProject =
  223. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  224. ->TargetsWindowsCE();
  225. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  226. VSVersion realVersion = this->Version;
  227. if(this->FortranProject && this->Version >= VS10)
  228. {
  229. this->Version = VS9;
  230. }
  231. // add to the list of projects
  232. target.SetProperty("GENERATOR_FILE_NAME",lname.c_str());
  233. // create the dsp.cmake file
  234. std::string fname;
  235. fname = this->Makefile->GetCurrentBinaryDirectory();
  236. fname += "/";
  237. fname += lname;
  238. if(this->FortranProject)
  239. {
  240. fname += ".vfproj";
  241. }
  242. else
  243. {
  244. fname += ".vcproj";
  245. }
  246. // Generate the project file and replace it atomically with
  247. // copy-if-different. We use a separate timestamp so that the IDE
  248. // does not reload project files unnecessarily.
  249. cmGeneratedFileStream fout(fname.c_str());
  250. fout.SetCopyIfDifferent(true);
  251. this->WriteVCProjFile(fout,lname,target);
  252. if (fout.Close())
  253. {
  254. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  255. }
  256. this->Version = realVersion;
  257. }
  258. //----------------------------------------------------------------------------
  259. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  260. {
  261. std::string stampName = this->Makefile->GetCurrentBinaryDirectory();
  262. stampName += "/";
  263. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  264. stampName += "generate.stamp";
  265. const char* dsprule =
  266. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  267. cmCustomCommandLine commandLine;
  268. commandLine.push_back(dsprule);
  269. std::string makefileIn = this->Makefile->GetCurrentSourceDirectory();
  270. makefileIn += "/";
  271. makefileIn += "CMakeLists.txt";
  272. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  273. if(!cmSystemTools::FileExists(makefileIn.c_str()))
  274. {
  275. return 0;
  276. }
  277. std::string comment = "Building Custom Rule ";
  278. comment += makefileIn;
  279. std::string args;
  280. args = "-H";
  281. args += this->Convert(this->Makefile->GetHomeDirectory(),
  282. START_OUTPUT, UNCHANGED, true);
  283. commandLine.push_back(args);
  284. args = "-B";
  285. args +=
  286. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  287. START_OUTPUT, UNCHANGED, true);
  288. commandLine.push_back(args);
  289. commandLine.push_back("--check-stamp-file");
  290. std::string stampFilename = this->Convert(stampName.c_str(), FULL,
  291. SHELL);
  292. commandLine.push_back(stampFilename.c_str());
  293. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  294. cmCustomCommandLines commandLines;
  295. commandLines.push_back(commandLine);
  296. const char* no_working_directory = 0;
  297. std::string fullpathStampName = this->Convert(stampName.c_str(), FULL,
  298. UNCHANGED);
  299. this->Makefile->AddCustomCommandToOutput(fullpathStampName.c_str(),
  300. listFiles, makefileIn.c_str(),
  301. commandLines, comment.c_str(),
  302. no_working_directory, true);
  303. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  304. {
  305. return file;
  306. }
  307. else
  308. {
  309. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  310. return 0;
  311. }
  312. }
  313. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  314. const std::string& libName,
  315. cmTarget &target)
  316. {
  317. std::vector<std::string> *configs =
  318. static_cast<cmGlobalVisualStudio7Generator *>
  319. (this->GlobalGenerator)->GetConfigurations();
  320. fout << "\t<Configurations>\n";
  321. for( std::vector<std::string>::iterator i = configs->begin();
  322. i != configs->end(); ++i)
  323. {
  324. this->WriteConfiguration(fout, i->c_str(), libName, target);
  325. }
  326. fout << "\t</Configurations>\n";
  327. }
  328. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] =
  329. {
  330. {"Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0},
  331. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  332. {"SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0},
  333. {"SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0},
  334. {"DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0},
  335. {"DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0},
  336. {"DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0},
  337. {"DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0},
  338. {"Optimization", "Od", "disable optimization", "optimizeDisabled", 0},
  339. {"Optimization", "O1", "min space", "optimizeMinSpace", 0},
  340. {"Optimization", "O3", "full optimize", "optimizeFull", 0},
  341. {"GlobalOptimizations", "Og", "global optimize", "true", 0},
  342. {"InlineFunctionExpansion", "Ob0", "", "expandDisable", 0},
  343. {"InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0},
  344. {"FavorSizeOrSpeed", "Os", "", "favorSize", 0},
  345. {"OmitFramePointers", "Oy-", "", "false", 0},
  346. {"OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0},
  347. {"OptimizeForProcessor", "G5", "", "procOptimizePentium", 0},
  348. {"OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0},
  349. {"UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0},
  350. {"OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0},
  351. {"OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0},
  352. {"OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0},
  353. {"OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0},
  354. {"OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0},
  355. {"OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0},
  356. {"OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0},
  357. {"OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0},
  358. {"OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0},
  359. {"OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD", 0},
  360. {"OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4", 0},
  361. {"OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0},
  362. {"OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0},
  363. {"Traceback", "traceback", "", "true", 0},
  364. {"Traceback", "notraceback", "", "false", 0},
  365. {"FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0},
  366. {"FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0},
  367. {"FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0},
  368. {"ModulePath", "module:", "", "",
  369. cmVS7FlagTable::UserValueRequired},
  370. {"LoopUnrolling", "Qunroll:", "", "",
  371. cmVS7FlagTable::UserValueRequired},
  372. {"AutoParallelThreshold", "Qpar-threshold:", "", "",
  373. cmVS7FlagTable::UserValueRequired},
  374. {"HeapArrays", "heap-arrays:", "", "",
  375. cmVS7FlagTable::UserValueRequired},
  376. {"ObjectText", "bintext:", "", "",
  377. cmVS7FlagTable::UserValueRequired},
  378. {"Parallelization", "Qparallel", "", "true", 0},
  379. {"PrefetchInsertion", "Qprefetch-", "", "false", 0},
  380. {"BufferedIO", "assume:buffered_io", "", "true", 0},
  381. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  382. {"CallingConvention", "iface:cref", "", "callConventionCRef", 0},
  383. {"CallingConvention", "iface:stdref", "", "callConventionStdRef", 0},
  384. {"CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0},
  385. {"CallingConvention", "iface:cvf", "", "callConventionCVF", 0},
  386. {"EnableRecursion", "recursive", "", "true", 0},
  387. {"ReentrantCode", "reentrancy", "", "true", 0},
  388. // done up to Language
  389. {0,0,0,0,0}
  390. };
  391. // fill the table here currently the comment field is not used for
  392. // anything other than documentation NOTE: Make sure the longer
  393. // commandFlag comes FIRST!
  394. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  395. {
  396. // option flags (some flags map to the same option)
  397. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  398. {"BasicRuntimeChecks", "RTCsu",
  399. "Both stack and uninitialized checks", "3", 0},
  400. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  401. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  402. {"BasicRuntimeChecks", "RTC1",
  403. "Both stack and uninitialized checks", "3", 0},
  404. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  405. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  406. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  407. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  408. {"EnableEnhancedInstructionSet", "arch:SSE2",
  409. "Use sse2 instructions", "2", 0},
  410. {"EnableEnhancedInstructionSet", "arch:SSE",
  411. "Use sse instructions", "1", 0},
  412. {"FloatingPointModel", "fp:precise",
  413. "Use precise floating point model", "0", 0},
  414. {"FloatingPointModel", "fp:strict",
  415. "Use strict floating point model", "1", 0},
  416. {"FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0},
  417. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  418. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  419. {"CompileAs", "TC", "Compile as c code", "1", 0},
  420. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  421. {"Optimization", "Od", "Non Debug", "0", 0},
  422. {"Optimization", "O1", "Min Size", "1", 0},
  423. {"Optimization", "O2", "Max Speed", "2", 0},
  424. {"Optimization", "Ox", "Max Optimization", "3", 0},
  425. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  426. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  427. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  428. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  429. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  430. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  431. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  432. {"RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0},
  433. {"RuntimeLibrary", "MT", "Multithreaded", "0", 0},
  434. {"RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0},
  435. {"RuntimeLibrary", "MD", "Multithreaded dll", "2", 0},
  436. {"RuntimeLibrary", "MLd", "Single Thread debug", "5", 0},
  437. {"RuntimeLibrary", "ML", "Single Thread", "4", 0},
  438. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  439. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  440. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  441. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  442. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  443. {"WarningLevel", "W0", "Warning level", "0", 0},
  444. {"WarningLevel", "W1", "Warning level", "1", 0},
  445. {"WarningLevel", "W2", "Warning level", "2", 0},
  446. {"WarningLevel", "W3", "Warning level", "3", 0},
  447. {"WarningLevel", "W4", "Warning level", "4", 0},
  448. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  449. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  450. // Precompiled header and related options. Note that the
  451. // UsePrecompiledHeader entries are marked as "Continue" so that the
  452. // corresponding PrecompiledHeaderThrough entry can be found.
  453. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  454. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  455. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  456. cmVS7FlagTable::UserValueRequired},
  457. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  458. cmVS7FlagTable::UserValue},
  459. // The YX and Yu options are in a per-global-generator table because
  460. // their values differ based on the VS IDE version.
  461. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  462. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable},
  463. {"AssemblerListingLocation", "Fa", "ASM List Location", "",
  464. cmVS7FlagTable::UserValue},
  465. {"ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  466. cmVS7FlagTable::UserValue},
  467. // boolean flags
  468. {"BufferSecurityCheck", "GS", "Buffer security check", "true", 0},
  469. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false", 0},
  470. {"Detect64BitPortabilityProblems", "Wp64",
  471. "Detect 64-bit Portability Problems", "true", 0},
  472. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  473. "true", 0},
  474. {"EnableFunctionLevelLinking", "Gy",
  475. "EnableFunctionLevelLinking", "true", 0},
  476. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0},
  477. {"GlobalOptimizations", "Og", "Global Optimize", "true", 0},
  478. {"ImproveFloatingPointConsistency", "Op",
  479. "ImproveFloatingPointConsistency", "true", 0},
  480. {"MinimalRebuild", "Gm", "minimal rebuild", "true", 0},
  481. {"OmitFramePointers", "Oy", "OmitFramePointers", "true", 0},
  482. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0},
  483. {"RuntimeTypeInfo", "GR",
  484. "Turn on Run time type information for c++", "true", 0},
  485. {"RuntimeTypeInfo", "GR-",
  486. "Turn off Run time type information for c++", "false", 0},
  487. {"SmallerTypeCheck", "RTCc", "smaller type check", "true", 0},
  488. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0},
  489. {"WholeProgramOptimization", "GL",
  490. "Enables whole program optimization", "true", 0},
  491. {"WholeProgramOptimization", "GL-",
  492. "Disables whole program optimization", "false", 0},
  493. {"WarnAsError", "WX", "Treat warnings as errors", "true", 0},
  494. {"BrowseInformation", "FR", "Generate browse information", "1", 0},
  495. {"StringPooling", "GF", "Enable StringPooling", "true", 0},
  496. {0,0,0,0,0}
  497. };
  498. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  499. {
  500. // option flags (some flags map to the same option)
  501. {"GenerateManifest", "MANIFEST:NO",
  502. "disable manifest generation", "false", 0},
  503. {"GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0},
  504. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  505. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  506. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0},
  507. {"CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0},
  508. {"DataExecutionPrevention", "NXCOMPAT:NO",
  509. "Not known to work with Windows Data Execution Prevention", "1", 0},
  510. {"DataExecutionPrevention", "NXCOMPAT",
  511. "Known to work with Windows Data Execution Prevention", "2", 0},
  512. {"DelaySign", "DELAYSIGN:NO", "", "false", 0},
  513. {"DelaySign", "DELAYSIGN", "", "true", 0},
  514. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  515. cmVS7FlagTable::UserValue},
  516. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  517. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  518. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  519. "true", 0},
  520. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  521. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  522. "2", 0},
  523. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  524. "1", 0},
  525. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  526. {"ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true", 0},
  527. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  528. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  529. {"Profile", "PROFILE", "", "true", 0},
  530. {"RandomizedBaseAddress", "DYNAMICBASE:NO",
  531. "Image may not be rebased at load-time", "1", 0},
  532. {"RandomizedBaseAddress", "DYNAMICBASE",
  533. "Image may be rebased at load-time", "2", 0},
  534. {"SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0},
  535. {"SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0},
  536. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  537. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  538. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  539. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  540. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  541. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  542. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  543. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  544. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  545. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  546. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  547. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  548. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  549. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  550. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  551. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  552. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  553. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  554. {"TurnOffAssemblyGeneration", "NOASSEMBLY",
  555. "No assembly even if CLR information is present in objects.", "true", 0},
  556. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  557. cmVS7FlagTable::UserValue},
  558. {"GenerateMapFile", "MAP", "enable generation of map file", "true", 0},
  559. {0,0,0,0,0}
  560. };
  561. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] =
  562. {
  563. {"LinkIncremental", "INCREMENTAL:NO", "link incremental",
  564. "linkIncrementalNo", 0},
  565. {"LinkIncremental", "INCREMENTAL:YES", "link incremental",
  566. "linkIncrementalYes", 0},
  567. {0,0,0,0,0}
  568. };
  569. //----------------------------------------------------------------------------
  570. // Helper class to write build event <Tool .../> elements.
  571. class cmLocalVisualStudio7Generator::EventWriter
  572. {
  573. public:
  574. EventWriter(cmLocalVisualStudio7Generator* lg,
  575. const std::string& config, std::ostream& os):
  576. LG(lg), Config(config), Stream(os), First(true) {}
  577. void Start(const char* tool)
  578. {
  579. this->First = true;
  580. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  581. }
  582. void Finish()
  583. {
  584. this->Stream << (this->First? "" : "\"") << "/>\n";
  585. }
  586. void Write(std::vector<cmCustomCommand> const& ccs)
  587. {
  588. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  589. ci != ccs.end(); ++ci)
  590. {
  591. this->Write(*ci);
  592. }
  593. }
  594. void Write(cmCustomCommand const& cc)
  595. {
  596. cmCustomCommandGenerator ccg(cc, this->Config, this->LG->GetMakefile());
  597. if(this->First)
  598. {
  599. const char* comment = ccg.GetComment();
  600. if(comment && *comment)
  601. {
  602. this->Stream << "\nDescription=\""
  603. << this->LG->EscapeForXML(comment) << "\"";
  604. }
  605. this->Stream << "\nCommandLine=\"";
  606. this->First = false;
  607. }
  608. else
  609. {
  610. this->Stream << this->LG->EscapeForXML("\n");
  611. }
  612. std::string script = this->LG->ConstructScript(ccg);
  613. this->Stream << this->LG->EscapeForXML(script.c_str());
  614. }
  615. private:
  616. cmLocalVisualStudio7Generator* LG;
  617. std::string Config;
  618. std::ostream& Stream;
  619. bool First;
  620. };
  621. //----------------------------------------------------------------------------
  622. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  623. const std::string& configName,
  624. const std::string& libName,
  625. cmTarget &target)
  626. {
  627. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  628. if(!mfcFlag)
  629. {
  630. mfcFlag = "0";
  631. }
  632. cmGlobalVisualStudio7Generator* gg =
  633. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  634. fout << "\t\t<Configuration\n"
  635. << "\t\t\tName=\"" << configName
  636. << "|" << gg->GetPlatformName() << "\"\n";
  637. // This is an internal type to Visual Studio, it seems that:
  638. // 4 == static library
  639. // 2 == dll
  640. // 1 == executable
  641. // 10 == utility
  642. const char* configType = "10";
  643. const char* projectType = 0;
  644. bool targetBuilds = true;
  645. switch(target.GetType())
  646. {
  647. case cmTarget::OBJECT_LIBRARY:
  648. targetBuilds = false; // no manifest tool for object library
  649. case cmTarget::STATIC_LIBRARY:
  650. projectType = "typeStaticLibrary";
  651. configType = "4";
  652. break;
  653. case cmTarget::SHARED_LIBRARY:
  654. case cmTarget::MODULE_LIBRARY:
  655. projectType = "typeDynamicLibrary";
  656. configType = "2";
  657. break;
  658. case cmTarget::EXECUTABLE:
  659. configType = "1";
  660. break;
  661. case cmTarget::UTILITY:
  662. case cmTarget::GLOBAL_TARGET:
  663. configType = "10";
  664. default:
  665. targetBuilds = false;
  666. break;
  667. }
  668. if(this->FortranProject && projectType)
  669. {
  670. configType = projectType;
  671. }
  672. std::string flags;
  673. if(strcmp(configType, "10") != 0)
  674. {
  675. const std::string& linkLanguage = (this->FortranProject?
  676. std::string("Fortran"):
  677. target.GetLinkerLanguage(configName));
  678. if(linkLanguage.empty())
  679. {
  680. cmSystemTools::Error
  681. ("CMake can not determine linker language for target: ",
  682. target.GetName().c_str());
  683. return;
  684. }
  685. if(linkLanguage == "C" || linkLanguage == "CXX"
  686. || linkLanguage == "Fortran")
  687. {
  688. std::string baseFlagVar = "CMAKE_";
  689. baseFlagVar += linkLanguage;
  690. baseFlagVar += "_FLAGS";
  691. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  692. std::string flagVar = baseFlagVar + std::string("_") +
  693. cmSystemTools::UpperCase(configName);
  694. flags += " ";
  695. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  696. }
  697. // set the correct language
  698. if(linkLanguage == "C")
  699. {
  700. flags += " /TC ";
  701. }
  702. if(linkLanguage == "CXX")
  703. {
  704. flags += " /TP ";
  705. }
  706. // Add the target-specific flags.
  707. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  708. }
  709. if(this->FortranProject)
  710. {
  711. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  712. {
  713. case FortranFormatFixed: flags += " -fixed"; break;
  714. case FortranFormatFree: flags += " -free"; break;
  715. default: break;
  716. }
  717. }
  718. // Get preprocessor definitions for this directory.
  719. std::string defineFlags = this->Makefile->GetDefineFlags();
  720. Options::Tool t = Options::Compiler;
  721. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  722. if(this->FortranProject)
  723. {
  724. t = Options::FortranCompiler;
  725. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  726. }
  727. Options targetOptions(this, t,
  728. table,
  729. this->ExtraFlagTable);
  730. targetOptions.FixExceptionHandlingDefault();
  731. std::string asmLocation = configName + "/";
  732. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  733. targetOptions.Parse(flags.c_str());
  734. targetOptions.Parse(defineFlags.c_str());
  735. targetOptions.ParseFinish();
  736. cmGeneratorTarget* gt =
  737. this->GlobalGenerator->GetGeneratorTarget(&target);
  738. std::vector<std::string> targetDefines;
  739. target.GetCompileDefinitions(targetDefines, configName, "CXX");
  740. targetOptions.AddDefines(targetDefines);
  741. targetOptions.SetVerboseMakefile(
  742. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  743. // Add a definition for the configuration name.
  744. std::string configDefine = "CMAKE_INTDIR=\"";
  745. configDefine += configName;
  746. configDefine += "\"";
  747. targetOptions.AddDefine(configDefine);
  748. // Add the export symbol definition for shared library objects.
  749. if(const char* exportMacro = target.GetExportMacro())
  750. {
  751. targetOptions.AddDefine(exportMacro);
  752. }
  753. // The intermediate directory name consists of a directory for the
  754. // target and a subdirectory for the configuration name.
  755. std::string intermediateDir = this->GetTargetDirectory(target);
  756. intermediateDir += "/";
  757. intermediateDir += configName;
  758. if (target.GetType() < cmTarget::UTILITY)
  759. {
  760. std::string const& outDir =
  761. target.GetType() == cmTarget::OBJECT_LIBRARY?
  762. intermediateDir : target.GetDirectory(configName);
  763. fout << "\t\t\tOutputDirectory=\""
  764. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  765. }
  766. fout << "\t\t\tIntermediateDirectory=\""
  767. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  768. << "\"\n"
  769. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  770. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  771. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  772. if (this->FortranProject)
  773. {
  774. // Intel Fortran >= 15.0 uses TargetName property.
  775. std::string targetNameFull = target.GetFullName(configName);
  776. std::string targetName =
  777. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  778. std::string targetExt =
  779. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  780. fout <<
  781. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  782. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  783. ;
  784. }
  785. // If unicode is enabled change the character set to unicode, if not
  786. // then default to MBCS.
  787. if(targetOptions.UsingUnicode())
  788. {
  789. fout << "\t\t\tCharacterSet=\"1\">\n";
  790. }
  791. else if(targetOptions.UsingSBCS())
  792. {
  793. fout << "\t\t\tCharacterSet=\"0\">\n";
  794. }
  795. else
  796. {
  797. fout << "\t\t\tCharacterSet=\"2\">\n";
  798. }
  799. const char* tool = "VCCLCompilerTool";
  800. if(this->FortranProject)
  801. {
  802. tool = "VFFortranCompilerTool";
  803. }
  804. fout << "\t\t\t<Tool\n"
  805. << "\t\t\t\tName=\"" << tool << "\"\n";
  806. if(this->FortranProject)
  807. {
  808. const char* target_mod_dir =
  809. target.GetProperty("Fortran_MODULE_DIRECTORY");
  810. std::string modDir;
  811. if(target_mod_dir)
  812. {
  813. modDir = this->Convert(target_mod_dir,
  814. cmLocalGenerator::START_OUTPUT,
  815. cmLocalGenerator::UNCHANGED);
  816. }
  817. else
  818. {
  819. modDir = ".";
  820. }
  821. fout << "\t\t\t\tModulePath=\""
  822. << this->ConvertToXMLOutputPath(modDir.c_str())
  823. << "\\$(ConfigurationName)\"\n";
  824. }
  825. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  826. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  827. std::vector<std::string> includes;
  828. this->GetIncludeDirectories(includes, gt, "C", configName);
  829. std::vector<std::string>::iterator i = includes.begin();
  830. for(;i != includes.end(); ++i)
  831. {
  832. // output the include path
  833. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  834. fout << ipath << ";";
  835. // if this is fortran then output the include with
  836. // a ConfigurationName on the end of it.
  837. if(this->FortranProject)
  838. {
  839. ipath = i->c_str();
  840. ipath += "/$(ConfigurationName)";
  841. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  842. fout << ipath << ";";
  843. }
  844. }
  845. fout << "\"\n";
  846. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  847. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  848. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  849. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  850. {
  851. // Specify the compiler program database file if configured.
  852. std::string pdb = target.GetCompilePDBPath(configName);
  853. if(!pdb.empty())
  854. {
  855. fout << "\t\t\t\tProgramDataBaseFileName=\""
  856. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  857. << "\"\n";
  858. }
  859. }
  860. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  861. if(gg->IsMasmEnabled() && !this->FortranProject)
  862. {
  863. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  864. fout <<
  865. "\t\t\t<Tool\n"
  866. "\t\t\t\tName=\"MASM\"\n"
  867. "\t\t\t\tIncludePaths=\""
  868. ;
  869. const char* sep = "";
  870. for(i = includes.begin(); i != includes.end(); ++i)
  871. {
  872. std::string inc = *i;
  873. cmConvertToWindowsSlash(inc);
  874. fout << sep << this->EscapeForXML(inc);
  875. sep = ";";
  876. }
  877. fout << "\"\n";
  878. // Use same preprocessor definitions as VCCLCompilerTool.
  879. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  880. "ASM_MASM");
  881. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  882. fout <<
  883. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  884. "\t\t\t/>\n";
  885. }
  886. tool = "VCCustomBuildTool";
  887. if(this->FortranProject)
  888. {
  889. tool = "VFCustomBuildTool";
  890. }
  891. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  892. tool = "VCResourceCompilerTool";
  893. if(this->FortranProject)
  894. {
  895. tool = "VFResourceCompilerTool";
  896. }
  897. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  898. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  899. for(i = includes.begin();i != includes.end(); ++i)
  900. {
  901. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  902. fout << ipath << ";";
  903. }
  904. // add the -D flags to the RC tool
  905. fout << "\"";
  906. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  907. fout << "/>\n";
  908. tool = "VCMIDLTool";
  909. if(this->FortranProject)
  910. {
  911. tool = "VFMIDLTool";
  912. }
  913. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  914. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  915. for(i = includes.begin(); i != includes.end(); ++i)
  916. {
  917. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  918. fout << ipath << ";";
  919. }
  920. fout << "\"\n";
  921. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  922. if( gg->GetPlatformName() == "x64" )
  923. {
  924. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  925. }
  926. else if( gg->GetPlatformName() == "ia64" )
  927. {
  928. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  929. }
  930. else
  931. {
  932. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  933. }
  934. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  935. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  936. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  937. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  938. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  939. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  940. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  941. // end of <Tool Name=VCMIDLTool
  942. // Check if we need the FAT32 workaround.
  943. if(targetBuilds && this->Version >= VS8)
  944. {
  945. // Check the filesystem type where the target will be written.
  946. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  947. {
  948. // Add a flag telling the manifest tool to use a workaround
  949. // for FAT32 file systems, which can cause an empty manifest
  950. // to be embedded into the resulting executable. See CMake
  951. // bug #2617.
  952. const char* manifestTool = "VCManifestTool";
  953. if(this->FortranProject)
  954. {
  955. manifestTool = "VFManifestTool";
  956. }
  957. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  958. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  959. << "\t\t\t/>\n";
  960. }
  961. }
  962. this->OutputTargetRules(fout, configName, target, libName);
  963. this->OutputBuildTool(fout, configName, target, targetOptions);
  964. fout << "\t\t</Configuration>\n";
  965. }
  966. //----------------------------------------------------------------------------
  967. std::string
  968. cmLocalVisualStudio7Generator
  969. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
  970. const std::string& configName)
  971. {
  972. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  973. std::string extraLinkOptionsBuildTypeDef =
  974. rootLinkerFlags + "_" + configTypeUpper;
  975. std::string extraLinkOptionsBuildType =
  976. this->Makefile->GetRequiredDefinition
  977. (extraLinkOptionsBuildTypeDef.c_str());
  978. return extraLinkOptionsBuildType;
  979. }
  980. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  981. const std::string& configName, cmTarget &target,
  982. const Options& targetOptions)
  983. {
  984. cmGlobalVisualStudio7Generator* gg =
  985. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  986. std::string temp;
  987. std::string extraLinkOptions;
  988. if(target.GetType() == cmTarget::EXECUTABLE)
  989. {
  990. extraLinkOptions =
  991. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  992. + std::string(" ")
  993. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  994. }
  995. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  996. {
  997. extraLinkOptions =
  998. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  999. + std::string(" ")
  1000. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  1001. }
  1002. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  1003. {
  1004. extraLinkOptions =
  1005. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  1006. + std::string(" ")
  1007. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  1008. }
  1009. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  1010. if(targetLinkFlags)
  1011. {
  1012. extraLinkOptions += " ";
  1013. extraLinkOptions += targetLinkFlags;
  1014. }
  1015. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  1016. std::string linkFlagsConfig = "LINK_FLAGS_";
  1017. linkFlagsConfig += configTypeUpper;
  1018. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  1019. if(targetLinkFlags)
  1020. {
  1021. extraLinkOptions += " ";
  1022. extraLinkOptions += targetLinkFlags;
  1023. }
  1024. Options linkOptions(this, Options::Linker);
  1025. if(this->FortranProject)
  1026. {
  1027. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  1028. }
  1029. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  1030. linkOptions.Parse(extraLinkOptions.c_str());
  1031. if(!this->ModuleDefinitionFile.empty())
  1032. {
  1033. std::string defFile =
  1034. this->ConvertToOptionallyRelativeOutputPath(this->ModuleDefinitionFile);
  1035. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  1036. }
  1037. switch(target.GetType())
  1038. {
  1039. case cmTarget::UNKNOWN_LIBRARY:
  1040. break;
  1041. case cmTarget::OBJECT_LIBRARY:
  1042. {
  1043. std::string libpath = this->GetTargetDirectory(target);
  1044. libpath += "/";
  1045. libpath += configName;
  1046. libpath += "/";
  1047. libpath += target.GetName();
  1048. libpath += ".lib";
  1049. const char* tool =
  1050. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  1051. fout << "\t\t\t<Tool\n"
  1052. << "\t\t\t\tName=\"" << tool << "\"\n";
  1053. fout << "\t\t\t\tOutputFile=\""
  1054. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1055. break;
  1056. }
  1057. case cmTarget::STATIC_LIBRARY:
  1058. {
  1059. std::string targetNameFull = target.GetFullName(configName);
  1060. std::string libpath = target.GetDirectory(configName);
  1061. libpath += "/";
  1062. libpath += targetNameFull;
  1063. const char* tool = "VCLibrarianTool";
  1064. if(this->FortranProject)
  1065. {
  1066. tool = "VFLibrarianTool";
  1067. }
  1068. fout << "\t\t\t<Tool\n"
  1069. << "\t\t\t\tName=\"" << tool << "\"\n";
  1070. if(this->GetVersion() < VS8 || this->FortranProject)
  1071. {
  1072. std::ostringstream libdeps;
  1073. this->Internal->OutputObjects(libdeps, &target);
  1074. if(!libdeps.str().empty())
  1075. {
  1076. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  1077. }
  1078. }
  1079. std::string libflags;
  1080. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1081. if(!libflags.empty())
  1082. {
  1083. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1084. }
  1085. fout << "\t\t\t\tOutputFile=\""
  1086. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1087. break;
  1088. }
  1089. case cmTarget::SHARED_LIBRARY:
  1090. case cmTarget::MODULE_LIBRARY:
  1091. {
  1092. std::string targetName;
  1093. std::string targetNameSO;
  1094. std::string targetNameFull;
  1095. std::string targetNameImport;
  1096. std::string targetNamePDB;
  1097. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1098. targetNameImport, targetNamePDB, configName);
  1099. // Compute the link library and directory information.
  1100. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1101. if(!pcli)
  1102. {
  1103. return;
  1104. }
  1105. cmComputeLinkInformation& cli = *pcli;
  1106. std::string linkLanguage = cli.GetLinkLanguage();
  1107. // Compute the variable name to lookup standard libraries for this
  1108. // language.
  1109. std::string standardLibsVar = "CMAKE_";
  1110. standardLibsVar += linkLanguage;
  1111. standardLibsVar += "_STANDARD_LIBRARIES";
  1112. const char* tool = "VCLinkerTool";
  1113. if(this->FortranProject)
  1114. {
  1115. tool = "VFLinkerTool";
  1116. }
  1117. fout << "\t\t\t<Tool\n"
  1118. << "\t\t\t\tName=\"" << tool << "\"\n";
  1119. if(!gg->NeedLinkLibraryDependencies(target))
  1120. {
  1121. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1122. }
  1123. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1124. // Use the NOINHERIT macro to avoid getting VS project default
  1125. // libraries which may be set by the user to something bad.
  1126. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1127. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1128. if(this->GetVersion() < VS8 || this->FortranProject)
  1129. {
  1130. this->Internal->OutputObjects(fout, &target, " ");
  1131. }
  1132. fout << " ";
  1133. this->Internal->OutputLibraries(fout, cli.GetItems());
  1134. fout << "\"\n";
  1135. temp = target.GetDirectory(configName);
  1136. temp += "/";
  1137. temp += targetNameFull;
  1138. fout << "\t\t\t\tOutputFile=\""
  1139. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1140. this->WriteTargetVersionAttribute(fout, target);
  1141. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1142. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1143. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1144. fout << "\"\n";
  1145. temp = target.GetPDBDirectory(configName);
  1146. temp += "/";
  1147. temp += targetNamePDB;
  1148. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1149. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1150. if(targetOptions.IsDebug())
  1151. {
  1152. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1153. }
  1154. if(this->WindowsCEProject)
  1155. {
  1156. if(this->GetVersion() < VS9)
  1157. {
  1158. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1159. }
  1160. else
  1161. {
  1162. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1163. }
  1164. }
  1165. std::string stackVar = "CMAKE_";
  1166. stackVar += linkLanguage;
  1167. stackVar += "_STACK_SIZE";
  1168. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1169. if(stackVal)
  1170. {
  1171. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1172. }
  1173. temp = target.GetDirectory(configName, true);
  1174. temp += "/";
  1175. temp += targetNameImport;
  1176. fout << "\t\t\t\tImportLibrary=\""
  1177. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1178. if(this->FortranProject)
  1179. {
  1180. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1181. }
  1182. fout << "/>\n";
  1183. }
  1184. break;
  1185. case cmTarget::EXECUTABLE:
  1186. {
  1187. std::string targetName;
  1188. std::string targetNameFull;
  1189. std::string targetNameImport;
  1190. std::string targetNamePDB;
  1191. target.GetExecutableNames(targetName, targetNameFull,
  1192. targetNameImport, targetNamePDB, configName);
  1193. // Compute the link library and directory information.
  1194. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1195. if(!pcli)
  1196. {
  1197. return;
  1198. }
  1199. cmComputeLinkInformation& cli = *pcli;
  1200. std::string linkLanguage = cli.GetLinkLanguage();
  1201. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1202. // Compute the variable name to lookup standard libraries for this
  1203. // language.
  1204. std::string standardLibsVar = "CMAKE_";
  1205. standardLibsVar += linkLanguage;
  1206. standardLibsVar += "_STANDARD_LIBRARIES";
  1207. const char* tool = "VCLinkerTool";
  1208. if(this->FortranProject)
  1209. {
  1210. tool = "VFLinkerTool";
  1211. }
  1212. fout << "\t\t\t<Tool\n"
  1213. << "\t\t\t\tName=\"" << tool << "\"\n";
  1214. if(!gg->NeedLinkLibraryDependencies(target))
  1215. {
  1216. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1217. }
  1218. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1219. // Use the NOINHERIT macro to avoid getting VS project default
  1220. // libraries which may be set by the user to something bad.
  1221. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1222. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1223. if(this->GetVersion() < VS8 || this->FortranProject)
  1224. {
  1225. this->Internal->OutputObjects(fout, &target, " ");
  1226. }
  1227. fout << " ";
  1228. this->Internal->OutputLibraries(fout, cli.GetItems());
  1229. fout << "\"\n";
  1230. temp = target.GetDirectory(configName);
  1231. temp += "/";
  1232. temp += targetNameFull;
  1233. fout << "\t\t\t\tOutputFile=\""
  1234. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1235. this->WriteTargetVersionAttribute(fout, target);
  1236. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1237. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1238. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1239. fout << "\"\n";
  1240. std::string path = this->ConvertToXMLOutputPathSingle(
  1241. target.GetPDBDirectory(configName).c_str());
  1242. fout << "\t\t\t\tProgramDatabaseFile=\""
  1243. << path << "/" << targetNamePDB
  1244. << "\"\n";
  1245. if(targetOptions.IsDebug())
  1246. {
  1247. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1248. }
  1249. if ( this->WindowsCEProject )
  1250. {
  1251. if(this->GetVersion() < VS9)
  1252. {
  1253. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1254. }
  1255. else
  1256. {
  1257. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1258. }
  1259. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1260. {
  1261. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1262. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1263. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1264. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1265. }
  1266. }
  1267. else if ( this->FortranProject )
  1268. {
  1269. fout << "\t\t\t\tSubSystem=\""
  1270. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1271. << "\"\n";
  1272. }
  1273. else
  1274. {
  1275. fout << "\t\t\t\tSubSystem=\""
  1276. << (isWin32Executable ? "2" : "1")
  1277. << "\"\n";
  1278. }
  1279. std::string stackVar = "CMAKE_";
  1280. stackVar += linkLanguage;
  1281. stackVar += "_STACK_SIZE";
  1282. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1283. if(stackVal)
  1284. {
  1285. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1286. }
  1287. temp = target.GetDirectory(configName, true);
  1288. temp += "/";
  1289. temp += targetNameImport;
  1290. fout << "\t\t\t\tImportLibrary=\""
  1291. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1292. break;
  1293. }
  1294. case cmTarget::UTILITY:
  1295. case cmTarget::GLOBAL_TARGET:
  1296. case cmTarget::INTERFACE_LIBRARY:
  1297. break;
  1298. }
  1299. }
  1300. //----------------------------------------------------------------------------
  1301. void
  1302. cmLocalVisualStudio7Generator
  1303. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1304. {
  1305. int major;
  1306. int minor;
  1307. target.GetTargetVersion(major, minor);
  1308. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1309. }
  1310. //----------------------------------------------------------------------------
  1311. void
  1312. cmLocalVisualStudio7GeneratorInternals
  1313. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1314. {
  1315. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1316. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1317. {
  1318. if(l->IsPath)
  1319. {
  1320. std::string rel = lg->Convert(l->Value.c_str(),
  1321. cmLocalGenerator::START_OUTPUT,
  1322. cmLocalGenerator::UNCHANGED);
  1323. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1324. }
  1325. else if (!l->Target
  1326. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1327. {
  1328. fout << l->Value << " ";
  1329. }
  1330. }
  1331. }
  1332. //----------------------------------------------------------------------------
  1333. void
  1334. cmLocalVisualStudio7GeneratorInternals
  1335. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1336. {
  1337. // VS < 8 does not support per-config source locations so we
  1338. // list object library content on the link line instead.
  1339. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1340. cmGeneratorTarget* gt =
  1341. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1342. std::vector<std::string> objs;
  1343. gt->UseObjectLibraries(objs, "");
  1344. const char* sep = isep? isep : "";
  1345. for(std::vector<std::string>::const_iterator
  1346. oi = objs.begin(); oi != objs.end(); ++oi)
  1347. {
  1348. std::string rel = lg->Convert(oi->c_str(),
  1349. cmLocalGenerator::START_OUTPUT,
  1350. cmLocalGenerator::UNCHANGED);
  1351. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1352. sep = " ";
  1353. }
  1354. }
  1355. //----------------------------------------------------------------------------
  1356. void
  1357. cmLocalVisualStudio7Generator
  1358. ::OutputLibraryDirectories(std::ostream& fout,
  1359. std::vector<std::string> const& dirs)
  1360. {
  1361. const char* comma = "";
  1362. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1363. d != dirs.end(); ++d)
  1364. {
  1365. // Remove any trailing slash and skip empty paths.
  1366. std::string dir = *d;
  1367. if(dir[dir.size()-1] == '/')
  1368. {
  1369. dir = dir.substr(0, dir.size()-1);
  1370. }
  1371. if(dir.empty())
  1372. {
  1373. continue;
  1374. }
  1375. // Switch to a relative path specification if it is shorter.
  1376. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1377. {
  1378. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1379. if(rel.size() < dir.size())
  1380. {
  1381. dir = rel;
  1382. }
  1383. }
  1384. // First search a configuration-specific subdirectory and then the
  1385. // original directory.
  1386. fout << comma
  1387. << this->ConvertToXMLOutputPath((dir+"/$(ConfigurationName)").c_str())
  1388. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1389. comma = ",";
  1390. }
  1391. }
  1392. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1393. const std::string& libName,
  1394. cmTarget &target)
  1395. {
  1396. // get the configurations
  1397. std::vector<std::string> *configs =
  1398. static_cast<cmGlobalVisualStudio7Generator *>
  1399. (this->GlobalGenerator)->GetConfigurations();
  1400. // We may be modifying the source groups temporarily, so make a copy.
  1401. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1402. // get the classes from the source lists then add them to the groups
  1403. this->ModuleDefinitionFile = "";
  1404. std::vector<cmSourceFile*> classes;
  1405. if (!target.GetConfigCommonSourceFiles(classes))
  1406. {
  1407. return;
  1408. }
  1409. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1410. i != classes.end(); i++)
  1411. {
  1412. if (!(*i)->GetObjectLibrary().empty())
  1413. {
  1414. continue;
  1415. }
  1416. // Add the file to the list of sources.
  1417. std::string source = (*i)->GetFullPath();
  1418. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1419. {
  1420. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1421. }
  1422. cmSourceGroup* sourceGroup =
  1423. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1424. sourceGroup->AssignSource(*i);
  1425. }
  1426. // open the project
  1427. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1428. // write the configuration information
  1429. this->WriteConfigurations(fout, libName, target);
  1430. fout << "\t<Files>\n";
  1431. // Loop through every source group.
  1432. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1433. {
  1434. cmSourceGroup sg = sourceGroups[i];
  1435. this->WriteGroup(&sg, target, fout, libName, configs);
  1436. }
  1437. if(this->GetVersion() >= VS8 && !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. this->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(this->Version == VS71)
  2028. {
  2029. fout << "\tVersion=\"7.10\"\n";
  2030. }
  2031. else
  2032. {
  2033. fout << "\tVersion=\"" << (this->Version/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(this->Version >= 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. }