cmLocalVisualStudio7Generator.cxx 76 KB

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