cmLocalVisualStudio7Generator.cxx 75 KB

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