cmLocalVisualStudio7Generator.cxx 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  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().c_str(), 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. cmsys::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. cmsys::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 std::string& 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 std::string& 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; // no manifest tool 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 std::string& linkLanguage = (this->FortranProject?
  649. std::string("Fortran"):
  650. target.GetLinkerLanguage(configName));
  651. if(linkLanguage.empty())
  652. {
  653. cmSystemTools::Error
  654. ("CMake can not determine linker language for target: ",
  655. target.GetName().c_str());
  656. return;
  657. }
  658. if(linkLanguage == "C" || linkLanguage == "CXX"
  659. || linkLanguage == "Fortran")
  660. {
  661. std::string baseFlagVar = "CMAKE_";
  662. baseFlagVar += linkLanguage;
  663. baseFlagVar += "_FLAGS";
  664. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  665. std::string flagVar = baseFlagVar + std::string("_") +
  666. cmSystemTools::UpperCase(configName);
  667. flags += " ";
  668. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  669. }
  670. // set the correct language
  671. if(linkLanguage == "C")
  672. {
  673. flags += " /TC ";
  674. }
  675. if(linkLanguage == "CXX")
  676. {
  677. flags += " /TP ";
  678. }
  679. // Add the target-specific flags.
  680. this->AddCompileOptions(flags, &target, linkLanguage, configName);
  681. }
  682. if(this->FortranProject)
  683. {
  684. switch(this->GetFortranFormat(target.GetProperty("Fortran_FORMAT")))
  685. {
  686. case FortranFormatFixed: flags += " -fixed"; break;
  687. case FortranFormatFree: flags += " -free"; break;
  688. default: break;
  689. }
  690. }
  691. // Get preprocessor definitions for this directory.
  692. std::string defineFlags = this->Makefile->GetDefineFlags();
  693. Options::Tool t = Options::Compiler;
  694. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  695. if(this->FortranProject)
  696. {
  697. t = Options::FortranCompiler;
  698. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  699. }
  700. Options targetOptions(this, t,
  701. table,
  702. this->ExtraFlagTable);
  703. targetOptions.FixExceptionHandlingDefault();
  704. std::string asmLocation = std::string(configName) + "/";
  705. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  706. targetOptions.Parse(flags.c_str());
  707. targetOptions.Parse(defineFlags.c_str());
  708. targetOptions.ParseFinish();
  709. cmGeneratorTarget* gt =
  710. this->GlobalGenerator->GetGeneratorTarget(&target);
  711. std::vector<std::string> targetDefines;
  712. target.GetCompileDefinitions(targetDefines, configName);
  713. targetOptions.AddDefines(targetDefines);
  714. targetOptions.SetVerboseMakefile(
  715. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  716. // Add a definition for the configuration name.
  717. std::string configDefine = "CMAKE_INTDIR=\"";
  718. configDefine += configName;
  719. configDefine += "\"";
  720. targetOptions.AddDefine(configDefine);
  721. // Add the export symbol definition for shared library objects.
  722. if(const char* exportMacro = target.GetExportMacro())
  723. {
  724. targetOptions.AddDefine(exportMacro);
  725. }
  726. // The intermediate directory name consists of a directory for the
  727. // target and a subdirectory for the configuration name.
  728. std::string intermediateDir = this->GetTargetDirectory(target);
  729. intermediateDir += "/";
  730. intermediateDir += configName;
  731. fout << "\t\t\tIntermediateDirectory=\""
  732. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  733. << "\"\n"
  734. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  735. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  736. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  737. // If unicode is enabled change the character set to unicode, if not
  738. // then default to MBCS.
  739. if(targetOptions.UsingUnicode())
  740. {
  741. fout << "\t\t\tCharacterSet=\"1\">\n";
  742. }
  743. else if(targetOptions.UsingSBCS())
  744. {
  745. fout << "\t\t\tCharacterSet=\"0\">\n";
  746. }
  747. else
  748. {
  749. fout << "\t\t\tCharacterSet=\"2\">\n";
  750. }
  751. const char* tool = "VCCLCompilerTool";
  752. if(this->FortranProject)
  753. {
  754. tool = "VFFortranCompilerTool";
  755. }
  756. fout << "\t\t\t<Tool\n"
  757. << "\t\t\t\tName=\"" << tool << "\"\n";
  758. if(this->FortranProject)
  759. {
  760. const char* target_mod_dir =
  761. target.GetProperty("Fortran_MODULE_DIRECTORY");
  762. std::string modDir;
  763. if(target_mod_dir)
  764. {
  765. modDir = this->Convert(target_mod_dir,
  766. cmLocalGenerator::START_OUTPUT,
  767. cmLocalGenerator::UNCHANGED);
  768. }
  769. else
  770. {
  771. modDir = ".";
  772. }
  773. fout << "\t\t\t\tModulePath=\""
  774. << this->ConvertToXMLOutputPath(modDir.c_str())
  775. << "\\$(ConfigurationName)\"\n";
  776. }
  777. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  778. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  779. std::vector<std::string> includes;
  780. this->GetIncludeDirectories(includes, gt, "C", configName);
  781. std::vector<std::string>::iterator i = includes.begin();
  782. for(;i != includes.end(); ++i)
  783. {
  784. // output the include path
  785. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  786. fout << ipath << ";";
  787. // if this is fortran then output the include with
  788. // a ConfigurationName on the end of it.
  789. if(this->FortranProject)
  790. {
  791. ipath = i->c_str();
  792. ipath += "/$(ConfigurationName)";
  793. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  794. fout << ipath << ";";
  795. }
  796. }
  797. fout << "\"\n";
  798. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  799. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  800. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  801. if(target.GetType() <= cmTarget::OBJECT_LIBRARY)
  802. {
  803. // Specify the compiler program database file if configured.
  804. std::string pdb = target.GetCompilePDBPath(configName);
  805. if(!pdb.empty())
  806. {
  807. fout << "\t\t\t\tProgramDataBaseFileName=\""
  808. << this->ConvertToXMLOutputPathSingle(pdb.c_str())
  809. << "\"\n";
  810. }
  811. }
  812. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  813. tool = "VCCustomBuildTool";
  814. if(this->FortranProject)
  815. {
  816. tool = "VFCustomBuildTool";
  817. }
  818. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  819. tool = "VCResourceCompilerTool";
  820. if(this->FortranProject)
  821. {
  822. tool = "VFResourceCompilerTool";
  823. }
  824. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  825. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  826. for(i = includes.begin();i != includes.end(); ++i)
  827. {
  828. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  829. fout << ipath << ";";
  830. }
  831. // add the -D flags to the RC tool
  832. fout << "\"";
  833. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  834. fout << "/>\n";
  835. tool = "VCMIDLTool";
  836. if(this->FortranProject)
  837. {
  838. tool = "VFMIDLTool";
  839. }
  840. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  841. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  842. for(i = includes.begin(); i != includes.end(); ++i)
  843. {
  844. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  845. fout << ipath << ";";
  846. }
  847. fout << "\"\n";
  848. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  849. if( this->PlatformName == "x64" )
  850. {
  851. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  852. }
  853. else if( this->PlatformName == "ia64" )
  854. {
  855. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  856. }
  857. else
  858. {
  859. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  860. }
  861. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  862. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  863. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  864. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  865. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  866. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  867. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  868. // end of <Tool Name=VCMIDLTool
  869. // Check if we need the FAT32 workaround.
  870. if(targetBuilds && this->Version >= VS8)
  871. {
  872. // Check the filesystem type where the target will be written.
  873. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  874. {
  875. // Add a flag telling the manifest tool to use a workaround
  876. // for FAT32 file systems, which can cause an empty manifest
  877. // to be embedded into the resulting executable. See CMake
  878. // bug #2617.
  879. const char* manifestTool = "VCManifestTool";
  880. if(this->FortranProject)
  881. {
  882. manifestTool = "VFManifestTool";
  883. }
  884. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << manifestTool << "\"\n"
  885. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  886. << "\t\t\t/>\n";
  887. }
  888. }
  889. this->OutputTargetRules(fout, configName, target, libName);
  890. this->OutputBuildTool(fout, configName, target, targetOptions);
  891. fout << "\t\t</Configuration>\n";
  892. }
  893. //----------------------------------------------------------------------------
  894. std::string
  895. cmLocalVisualStudio7Generator
  896. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  897. {
  898. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  899. std::string extraLinkOptionsBuildTypeDef =
  900. rootLinkerFlags + "_" + configTypeUpper;
  901. std::string extraLinkOptionsBuildType =
  902. this->Makefile->GetRequiredDefinition
  903. (extraLinkOptionsBuildTypeDef.c_str());
  904. return extraLinkOptionsBuildType;
  905. }
  906. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  907. const char* configName, cmTarget &target, const Options& targetOptions)
  908. {
  909. cmGlobalVisualStudio7Generator* gg =
  910. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  911. std::string temp;
  912. std::string extraLinkOptions;
  913. if(target.GetType() == cmTarget::EXECUTABLE)
  914. {
  915. extraLinkOptions =
  916. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  917. + std::string(" ")
  918. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  919. }
  920. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  921. {
  922. extraLinkOptions =
  923. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  924. + std::string(" ")
  925. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  926. }
  927. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  928. {
  929. extraLinkOptions =
  930. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  931. + std::string(" ")
  932. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  933. }
  934. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  935. if(targetLinkFlags)
  936. {
  937. extraLinkOptions += " ";
  938. extraLinkOptions += targetLinkFlags;
  939. }
  940. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  941. std::string linkFlagsConfig = "LINK_FLAGS_";
  942. linkFlagsConfig += configTypeUpper;
  943. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  944. if(targetLinkFlags)
  945. {
  946. extraLinkOptions += " ";
  947. extraLinkOptions += targetLinkFlags;
  948. }
  949. Options linkOptions(this, Options::Linker,
  950. cmLocalVisualStudio7GeneratorLinkFlagTable);
  951. linkOptions.Parse(extraLinkOptions.c_str());
  952. if(!this->ModuleDefinitionFile.empty())
  953. {
  954. std::string defFile =
  955. this->ConvertToXMLOutputPath(this->ModuleDefinitionFile.c_str());
  956. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  957. }
  958. switch(target.GetType())
  959. {
  960. case cmTarget::UNKNOWN_LIBRARY:
  961. break;
  962. case cmTarget::OBJECT_LIBRARY:
  963. {
  964. std::string libpath = this->GetTargetDirectory(target);
  965. libpath += "/";
  966. libpath += configName;
  967. libpath += "/";
  968. libpath += target.GetName();
  969. libpath += ".lib";
  970. const char* tool =
  971. this->FortranProject? "VFLibrarianTool":"VCLibrarianTool";
  972. fout << "\t\t\t<Tool\n"
  973. << "\t\t\t\tName=\"" << tool << "\"\n";
  974. fout << "\t\t\t\tOutputFile=\""
  975. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  976. break;
  977. }
  978. case cmTarget::STATIC_LIBRARY:
  979. {
  980. std::string targetNameFull = target.GetFullName(configName);
  981. std::string libpath = target.GetDirectory(configName);
  982. libpath += "/";
  983. libpath += targetNameFull;
  984. const char* tool = "VCLibrarianTool";
  985. if(this->FortranProject)
  986. {
  987. tool = "VFLibrarianTool";
  988. }
  989. fout << "\t\t\t<Tool\n"
  990. << "\t\t\t\tName=\"" << tool << "\"\n";
  991. if(this->GetVersion() < VS8 || this->FortranProject)
  992. {
  993. cmOStringStream libdeps;
  994. this->Internal->OutputObjects(libdeps, &target);
  995. if(!libdeps.str().empty())
  996. {
  997. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n";
  998. }
  999. }
  1000. std::string libflags;
  1001. this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
  1002. if(!libflags.empty())
  1003. {
  1004. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  1005. }
  1006. fout << "\t\t\t\tOutputFile=\""
  1007. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  1008. break;
  1009. }
  1010. case cmTarget::SHARED_LIBRARY:
  1011. case cmTarget::MODULE_LIBRARY:
  1012. {
  1013. std::string targetName;
  1014. std::string targetNameSO;
  1015. std::string targetNameFull;
  1016. std::string targetNameImport;
  1017. std::string targetNamePDB;
  1018. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1019. targetNameImport, targetNamePDB, configName);
  1020. // Compute the link library and directory information.
  1021. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1022. if(!pcli)
  1023. {
  1024. return;
  1025. }
  1026. cmComputeLinkInformation& cli = *pcli;
  1027. std::string linkLanguage = cli.GetLinkLanguage();
  1028. // Compute the variable name to lookup standard libraries for this
  1029. // language.
  1030. std::string standardLibsVar = "CMAKE_";
  1031. standardLibsVar += linkLanguage;
  1032. standardLibsVar += "_STANDARD_LIBRARIES";
  1033. const char* tool = "VCLinkerTool";
  1034. if(this->FortranProject)
  1035. {
  1036. tool = "VFLinkerTool";
  1037. }
  1038. fout << "\t\t\t<Tool\n"
  1039. << "\t\t\t\tName=\"" << tool << "\"\n";
  1040. if(!gg->NeedLinkLibraryDependencies(target))
  1041. {
  1042. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1043. }
  1044. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1045. // Use the NOINHERIT macro to avoid getting VS project default
  1046. // libraries which may be set by the user to something bad.
  1047. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1048. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1049. if(this->GetVersion() < VS8 || this->FortranProject)
  1050. {
  1051. this->Internal->OutputObjects(fout, &target, " ");
  1052. }
  1053. fout << " ";
  1054. this->Internal->OutputLibraries(fout, cli.GetItems());
  1055. fout << "\"\n";
  1056. temp = target.GetDirectory(configName);
  1057. temp += "/";
  1058. temp += targetNameFull;
  1059. fout << "\t\t\t\tOutputFile=\""
  1060. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1061. this->WriteTargetVersionAttribute(fout, target);
  1062. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1063. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1064. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1065. fout << "\"\n";
  1066. temp = target.GetPDBDirectory(configName);
  1067. temp += "/";
  1068. temp += targetNamePDB;
  1069. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  1070. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1071. if(targetOptions.IsDebug())
  1072. {
  1073. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  1074. }
  1075. if(this->WindowsCEProject)
  1076. {
  1077. if(this->GetVersion() < VS9)
  1078. {
  1079. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1080. }
  1081. else
  1082. {
  1083. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1084. }
  1085. }
  1086. std::string stackVar = "CMAKE_";
  1087. stackVar += linkLanguage;
  1088. stackVar += "_STACK_SIZE";
  1089. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1090. if(stackVal)
  1091. {
  1092. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1093. }
  1094. temp = target.GetDirectory(configName, true);
  1095. temp += "/";
  1096. temp += targetNameImport;
  1097. fout << "\t\t\t\tImportLibrary=\""
  1098. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1099. if(this->FortranProject)
  1100. {
  1101. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1102. }
  1103. fout << "/>\n";
  1104. }
  1105. break;
  1106. case cmTarget::EXECUTABLE:
  1107. {
  1108. std::string targetName;
  1109. std::string targetNameFull;
  1110. std::string targetNameImport;
  1111. std::string targetNamePDB;
  1112. target.GetExecutableNames(targetName, targetNameFull,
  1113. targetNameImport, targetNamePDB, configName);
  1114. // Compute the link library and directory information.
  1115. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  1116. if(!pcli)
  1117. {
  1118. return;
  1119. }
  1120. cmComputeLinkInformation& cli = *pcli;
  1121. std::string linkLanguage = cli.GetLinkLanguage();
  1122. bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
  1123. // Compute the variable name to lookup standard libraries for this
  1124. // language.
  1125. std::string standardLibsVar = "CMAKE_";
  1126. standardLibsVar += linkLanguage;
  1127. standardLibsVar += "_STANDARD_LIBRARIES";
  1128. const char* tool = "VCLinkerTool";
  1129. if(this->FortranProject)
  1130. {
  1131. tool = "VFLinkerTool";
  1132. }
  1133. fout << "\t\t\t<Tool\n"
  1134. << "\t\t\t\tName=\"" << tool << "\"\n";
  1135. if(!gg->NeedLinkLibraryDependencies(target))
  1136. {
  1137. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1138. }
  1139. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1140. // Use the NOINHERIT macro to avoid getting VS project default
  1141. // libraries which may be set by the user to something bad.
  1142. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1143. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1144. if(this->GetVersion() < VS8 || this->FortranProject)
  1145. {
  1146. this->Internal->OutputObjects(fout, &target, " ");
  1147. }
  1148. fout << " ";
  1149. this->Internal->OutputLibraries(fout, cli.GetItems());
  1150. fout << "\"\n";
  1151. temp = target.GetDirectory(configName);
  1152. temp += "/";
  1153. temp += targetNameFull;
  1154. fout << "\t\t\t\tOutputFile=\""
  1155. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1156. this->WriteTargetVersionAttribute(fout, target);
  1157. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1158. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1159. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1160. fout << "\"\n";
  1161. std::string path = this->ConvertToXMLOutputPathSingle(
  1162. target.GetPDBDirectory(configName).c_str());
  1163. fout << "\t\t\t\tProgramDatabaseFile=\""
  1164. << path << "/" << targetNamePDB
  1165. << "\"\n";
  1166. if(targetOptions.IsDebug())
  1167. {
  1168. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  1169. }
  1170. if ( this->WindowsCEProject )
  1171. {
  1172. if(this->GetVersion() < VS9)
  1173. {
  1174. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1175. }
  1176. else
  1177. {
  1178. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1179. }
  1180. if(!linkOptions.GetFlag("EntryPointSymbol"))
  1181. {
  1182. const char* entryPointSymbol = targetOptions.UsingUnicode() ?
  1183. (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") :
  1184. (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1185. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1186. }
  1187. }
  1188. else if ( this->FortranProject )
  1189. {
  1190. fout << "\t\t\t\tSubSystem=\""
  1191. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1192. << "\"\n";
  1193. }
  1194. else
  1195. {
  1196. fout << "\t\t\t\tSubSystem=\""
  1197. << (isWin32Executable ? "2" : "1")
  1198. << "\"\n";
  1199. }
  1200. std::string stackVar = "CMAKE_";
  1201. stackVar += linkLanguage;
  1202. stackVar += "_STACK_SIZE";
  1203. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1204. if(stackVal)
  1205. {
  1206. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1207. }
  1208. temp = target.GetDirectory(configName, true);
  1209. temp += "/";
  1210. temp += targetNameImport;
  1211. fout << "\t\t\t\tImportLibrary=\""
  1212. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1213. break;
  1214. }
  1215. case cmTarget::UTILITY:
  1216. case cmTarget::GLOBAL_TARGET:
  1217. case cmTarget::INTERFACE_LIBRARY:
  1218. break;
  1219. }
  1220. }
  1221. //----------------------------------------------------------------------------
  1222. void
  1223. cmLocalVisualStudio7Generator
  1224. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1225. {
  1226. int major;
  1227. int minor;
  1228. target.GetTargetVersion(major, minor);
  1229. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1230. }
  1231. //----------------------------------------------------------------------------
  1232. void
  1233. cmLocalVisualStudio7GeneratorInternals
  1234. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1235. {
  1236. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1237. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1238. {
  1239. if(l->IsPath)
  1240. {
  1241. std::string rel = lg->Convert(l->Value.c_str(),
  1242. cmLocalGenerator::START_OUTPUT,
  1243. cmLocalGenerator::UNCHANGED);
  1244. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1245. }
  1246. else if (!l->Target
  1247. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1248. {
  1249. fout << l->Value << " ";
  1250. }
  1251. }
  1252. }
  1253. //----------------------------------------------------------------------------
  1254. void
  1255. cmLocalVisualStudio7GeneratorInternals
  1256. ::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep)
  1257. {
  1258. // VS < 8 does not support per-config source locations so we
  1259. // list object library content on the link line instead.
  1260. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1261. cmGeneratorTarget* gt =
  1262. lg->GetGlobalGenerator()->GetGeneratorTarget(t);
  1263. std::vector<std::string> objs;
  1264. gt->UseObjectLibraries(objs);
  1265. const char* sep = isep? isep : "";
  1266. for(std::vector<std::string>::const_iterator
  1267. oi = objs.begin(); oi != objs.end(); ++oi)
  1268. {
  1269. std::string rel = lg->Convert(oi->c_str(),
  1270. cmLocalGenerator::START_OUTPUT,
  1271. cmLocalGenerator::UNCHANGED);
  1272. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1273. sep = " ";
  1274. }
  1275. }
  1276. //----------------------------------------------------------------------------
  1277. void
  1278. cmLocalVisualStudio7Generator
  1279. ::OutputLibraryDirectories(std::ostream& fout,
  1280. std::vector<std::string> const& dirs)
  1281. {
  1282. const char* comma = "";
  1283. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1284. d != dirs.end(); ++d)
  1285. {
  1286. // Remove any trailing slash and skip empty paths.
  1287. std::string dir = *d;
  1288. if(dir[dir.size()-1] == '/')
  1289. {
  1290. dir = dir.substr(0, dir.size()-1);
  1291. }
  1292. if(dir.empty())
  1293. {
  1294. continue;
  1295. }
  1296. // Switch to a relative path specification if it is shorter.
  1297. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1298. {
  1299. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1300. if(rel.size() < dir.size())
  1301. {
  1302. dir = rel;
  1303. }
  1304. }
  1305. // First search a configuration-specific subdirectory and then the
  1306. // original directory.
  1307. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1308. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1309. comma = ",";
  1310. }
  1311. }
  1312. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1313. const std::string& libName,
  1314. cmTarget &target)
  1315. {
  1316. // get the configurations
  1317. std::vector<std::string> *configs =
  1318. static_cast<cmGlobalVisualStudio7Generator *>
  1319. (this->GlobalGenerator)->GetConfigurations();
  1320. // We may be modifying the source groups temporarily, so make a copy.
  1321. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1322. // get the classes from the source lists then add them to the groups
  1323. this->ModuleDefinitionFile = "";
  1324. std::vector<cmSourceFile*> classes;
  1325. target.GetSourceFiles(classes);
  1326. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1327. i != classes.end(); i++)
  1328. {
  1329. // Add the file to the list of sources.
  1330. std::string source = (*i)->GetFullPath();
  1331. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1332. {
  1333. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1334. }
  1335. cmSourceGroup* sourceGroup =
  1336. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1337. sourceGroup->AssignSource(*i);
  1338. }
  1339. // open the project
  1340. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1341. // write the configuration information
  1342. this->WriteConfigurations(fout, libName, target);
  1343. fout << "\t<Files>\n";
  1344. // Loop through every source group.
  1345. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1346. {
  1347. cmSourceGroup sg = sourceGroups[i];
  1348. this->WriteGroup(&sg, target, fout, libName, configs);
  1349. }
  1350. if(this->GetVersion() >= VS8 && !this->FortranProject)
  1351. {
  1352. // VS >= 8 support per-config source locations so we
  1353. // list object library content as external objects.
  1354. cmGeneratorTarget* gt =
  1355. this->GlobalGenerator->GetGeneratorTarget(&target);
  1356. std::vector<std::string> objs;
  1357. gt->UseObjectLibraries(objs);
  1358. if(!objs.empty())
  1359. {
  1360. // TODO: Separate sub-filter for each object library used?
  1361. fout << "\t\t<Filter Name=\"Object Libraries\">\n";
  1362. for(std::vector<std::string>::const_iterator
  1363. oi = objs.begin(); oi != objs.end(); ++oi)
  1364. {
  1365. std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str());
  1366. fout << "\t\t\t<File RelativePath=\"" << o << "\" />\n";
  1367. }
  1368. fout << "\t\t</Filter>\n";
  1369. }
  1370. }
  1371. fout << "\t</Files>\n";
  1372. // Write the VCProj file's footer.
  1373. this->WriteVCProjFooter(fout, target);
  1374. }
  1375. struct cmLVS7GFileConfig
  1376. {
  1377. std::string ObjectName;
  1378. std::string CompileFlags;
  1379. std::string CompileDefs;
  1380. std::string CompileDefsConfig;
  1381. std::string AdditionalDeps;
  1382. bool ExcludedFromBuild;
  1383. };
  1384. class cmLocalVisualStudio7GeneratorFCInfo
  1385. {
  1386. public:
  1387. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1388. cmTarget& target,
  1389. cmSourceFile const& sf,
  1390. std::vector<std::string>* configs);
  1391. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1392. };
  1393. cmLocalVisualStudio7GeneratorFCInfo
  1394. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1395. cmTarget& target,
  1396. cmSourceFile const& sf,
  1397. std::vector<std::string>* configs)
  1398. {
  1399. cmGeneratorTarget* gt =
  1400. lg->GetGlobalGenerator()->GetGeneratorTarget(&target);
  1401. std::string objectName;
  1402. if(gt->HasExplicitObjectName(&sf))
  1403. {
  1404. objectName = gt->GetObjectName(&sf);
  1405. }
  1406. // Compute per-source, per-config information.
  1407. for(std::vector<std::string>::iterator i = configs->begin();
  1408. i != configs->end(); ++i)
  1409. {
  1410. std::string configUpper = cmSystemTools::UpperCase(*i);
  1411. cmLVS7GFileConfig fc;
  1412. bool needfc = false;
  1413. if(!objectName.empty())
  1414. {
  1415. fc.ObjectName = objectName;
  1416. needfc = true;
  1417. }
  1418. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1419. {
  1420. fc.CompileFlags = cflags;
  1421. needfc = true;
  1422. }
  1423. if(lg->FortranProject)
  1424. {
  1425. switch(lg->GetFortranFormat(sf.GetProperty("Fortran_FORMAT")))
  1426. {
  1427. case cmLocalGenerator::FortranFormatFixed:
  1428. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1429. needfc = true;
  1430. break;
  1431. case cmLocalGenerator::FortranFormatFree:
  1432. fc.CompileFlags = "-free " + fc.CompileFlags;
  1433. needfc = true;
  1434. break;
  1435. default: break;
  1436. }
  1437. }
  1438. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1439. {
  1440. fc.CompileDefs = cdefs;
  1441. needfc = true;
  1442. }
  1443. std::string defPropName = "COMPILE_DEFINITIONS_";
  1444. defPropName += configUpper;
  1445. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1446. {
  1447. fc.CompileDefsConfig = ccdefs;
  1448. needfc = true;
  1449. }
  1450. // Check for extra object-file dependencies.
  1451. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1452. {
  1453. std::vector<std::string> depends;
  1454. cmSystemTools::ExpandListArgument(deps, depends);
  1455. const char* sep = "";
  1456. for(std::vector<std::string>::iterator j = depends.begin();
  1457. j != depends.end(); ++j)
  1458. {
  1459. fc.AdditionalDeps += sep;
  1460. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1461. sep = ";";
  1462. needfc = true;
  1463. }
  1464. }
  1465. std::string lang =
  1466. lg->GlobalGenerator->GetLanguageFromExtension
  1467. (sf.GetExtension().c_str());
  1468. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1469. const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
  1470. bool needForceLang = false;
  1471. // source file does not match its extension language
  1472. if(lang != sourceLang)
  1473. {
  1474. needForceLang = true;
  1475. lang = sourceLang;
  1476. }
  1477. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1478. // the project file
  1479. fc.ExcludedFromBuild =
  1480. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1481. if(fc.ExcludedFromBuild)
  1482. {
  1483. needfc = true;
  1484. }
  1485. // if the source file does not match the linker language
  1486. // then force c or c++
  1487. if(needForceLang || (linkLanguage != lang))
  1488. {
  1489. if(lang == "CXX")
  1490. {
  1491. // force a C++ file type
  1492. fc.CompileFlags += " /TP ";
  1493. needfc = true;
  1494. }
  1495. else if(lang == "C")
  1496. {
  1497. // force to c
  1498. fc.CompileFlags += " /TC ";
  1499. needfc = true;
  1500. }
  1501. }
  1502. if(needfc)
  1503. {
  1504. this->FileConfigMap[*i] = fc;
  1505. }
  1506. }
  1507. }
  1508. //----------------------------------------------------------------------------
  1509. std::string
  1510. cmLocalVisualStudio7Generator
  1511. ::ComputeLongestObjectDirectory(cmTarget& target) const
  1512. {
  1513. std::vector<std::string> *configs =
  1514. static_cast<cmGlobalVisualStudio7Generator *>
  1515. (this->GlobalGenerator)->GetConfigurations();
  1516. // Compute the maximum length configuration name.
  1517. std::string config_max;
  1518. for(std::vector<std::string>::iterator i = configs->begin();
  1519. i != configs->end(); ++i)
  1520. {
  1521. if(i->size() > config_max.size())
  1522. {
  1523. config_max = *i;
  1524. }
  1525. }
  1526. // Compute the maximum length full path to the intermediate
  1527. // files directory for any configuration. This is used to construct
  1528. // object file names that do not produce paths that are too long.
  1529. std::string dir_max;
  1530. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1531. dir_max += "/";
  1532. dir_max += this->GetTargetDirectory(target);
  1533. dir_max += "/";
  1534. dir_max += config_max;
  1535. dir_max += "/";
  1536. return dir_max;
  1537. }
  1538. bool cmLocalVisualStudio7Generator
  1539. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1540. std::ostream &fout, const std::string& libName,
  1541. std::vector<std::string> *configs)
  1542. {
  1543. const std::vector<const cmSourceFile *> &sourceFiles =
  1544. sg->GetSourceFiles();
  1545. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1546. // Write the children to temporary output.
  1547. bool hasChildrenWithSources = false;
  1548. cmOStringStream tmpOut;
  1549. for(unsigned int i=0;i<children.size();++i)
  1550. {
  1551. if(this->WriteGroup(&children[i], target, tmpOut, libName, configs))
  1552. {
  1553. hasChildrenWithSources = true;
  1554. }
  1555. }
  1556. // If the group is empty, don't write it at all.
  1557. if(sourceFiles.empty() && !hasChildrenWithSources)
  1558. {
  1559. return false;
  1560. }
  1561. // If the group has a name, write the header.
  1562. std::string name = sg->GetName();
  1563. if(name != "")
  1564. {
  1565. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1566. }
  1567. // Loop through each source in the source group.
  1568. std::string objectName;
  1569. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1570. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1571. {
  1572. std::string source = (*sf)->GetFullPath();
  1573. FCInfo fcinfo(this, target, *(*sf), configs);
  1574. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1575. target.GetType() == cmTarget::GLOBAL_TARGET )
  1576. {
  1577. fout << "\t\t\t<File\n";
  1578. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1579. // Tell MS-Dev what the source is. If the compiler knows how to
  1580. // build it, then it will.
  1581. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1582. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1583. {
  1584. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1585. }
  1586. else if(!fcinfo.FileConfigMap.empty())
  1587. {
  1588. const char* aCompilerTool = "VCCLCompilerTool";
  1589. const char* lang = "CXX";
  1590. if(this->FortranProject)
  1591. {
  1592. aCompilerTool = "VFFortranCompilerTool";
  1593. }
  1594. std::string ext = (*sf)->GetExtension();
  1595. ext = cmSystemTools::LowerCase(ext);
  1596. if(ext == "idl")
  1597. {
  1598. aCompilerTool = "VCMIDLTool";
  1599. if(this->FortranProject)
  1600. {
  1601. aCompilerTool = "VFMIDLTool";
  1602. }
  1603. }
  1604. if(ext == "rc")
  1605. {
  1606. aCompilerTool = "VCResourceCompilerTool";
  1607. lang = "RC";
  1608. if(this->FortranProject)
  1609. {
  1610. aCompilerTool = "VFResourceCompilerTool";
  1611. }
  1612. }
  1613. if(ext == "def")
  1614. {
  1615. aCompilerTool = "VCCustomBuildTool";
  1616. if(this->FortranProject)
  1617. {
  1618. aCompilerTool = "VFCustomBuildTool";
  1619. }
  1620. }
  1621. for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
  1622. fci = fcinfo.FileConfigMap.begin();
  1623. fci != fcinfo.FileConfigMap.end(); ++fci)
  1624. {
  1625. cmLVS7GFileConfig const& fc = fci->second;
  1626. fout << "\t\t\t\t<FileConfiguration\n"
  1627. << "\t\t\t\t\tName=\"" << fci->first
  1628. << "|" << this->PlatformName << "\"";
  1629. if(fc.ExcludedFromBuild)
  1630. {
  1631. fout << " ExcludedFromBuild=\"true\"";
  1632. }
  1633. fout << ">\n";
  1634. fout << "\t\t\t\t\t<Tool\n"
  1635. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1636. if(!fc.CompileFlags.empty() ||
  1637. !fc.CompileDefs.empty() ||
  1638. !fc.CompileDefsConfig.empty())
  1639. {
  1640. Options::Tool tool = Options::Compiler;
  1641. cmVS7FlagTable const* table =
  1642. cmLocalVisualStudio7GeneratorFlagTable;
  1643. if(this->FortranProject)
  1644. {
  1645. tool = Options::FortranCompiler;
  1646. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1647. }
  1648. Options fileOptions(this, tool, table,
  1649. this->ExtraFlagTable);
  1650. fileOptions.Parse(fc.CompileFlags.c_str());
  1651. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1652. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1653. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1654. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1655. fileOptions.OutputPreprocessorDefinitions(fout,
  1656. "\t\t\t\t\t", "\n",
  1657. lang);
  1658. }
  1659. if(!fc.AdditionalDeps.empty())
  1660. {
  1661. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1662. << fc.AdditionalDeps.c_str() << "\"\n";
  1663. }
  1664. if(!fc.ObjectName.empty())
  1665. {
  1666. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1667. << fc.ObjectName.c_str() << "\"\n";
  1668. }
  1669. fout << "\t\t\t\t\t/>\n"
  1670. << "\t\t\t\t</FileConfiguration>\n";
  1671. }
  1672. }
  1673. fout << "\t\t\t</File>\n";
  1674. }
  1675. }
  1676. // If the group has children with source files, write the children.
  1677. if(hasChildrenWithSources)
  1678. {
  1679. fout << tmpOut.str();
  1680. }
  1681. // If the group has a name, write the footer.
  1682. if(name != "")
  1683. {
  1684. this->WriteVCProjEndGroup(fout);
  1685. }
  1686. return true;
  1687. }
  1688. void cmLocalVisualStudio7Generator::
  1689. WriteCustomRule(std::ostream& fout,
  1690. const char* source,
  1691. const cmCustomCommand& command,
  1692. FCInfo& fcinfo)
  1693. {
  1694. std::string comment = this->ConstructComment(command);
  1695. // Write the rule for each configuration.
  1696. std::vector<std::string>::iterator i;
  1697. std::vector<std::string> *configs =
  1698. static_cast<cmGlobalVisualStudio7Generator *>
  1699. (this->GlobalGenerator)->GetConfigurations();
  1700. const char* compileTool = "VCCLCompilerTool";
  1701. if(this->FortranProject)
  1702. {
  1703. compileTool = "VFCLCompilerTool";
  1704. }
  1705. const char* customTool = "VCCustomBuildTool";
  1706. if(this->FortranProject)
  1707. {
  1708. customTool = "VFCustomBuildTool";
  1709. }
  1710. for(i = configs->begin(); i != configs->end(); ++i)
  1711. {
  1712. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1713. fout << "\t\t\t\t<FileConfiguration\n";
  1714. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1715. if(!fc.CompileFlags.empty())
  1716. {
  1717. fout << "\t\t\t\t\t<Tool\n"
  1718. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1719. << "\t\t\t\t\tAdditionalOptions=\""
  1720. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1721. }
  1722. std::string script = this->ConstructScript(command, i->c_str());
  1723. if(this->FortranProject)
  1724. {
  1725. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1726. }
  1727. fout << "\t\t\t\t\t<Tool\n"
  1728. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1729. << "\t\t\t\t\tDescription=\""
  1730. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1731. << "\t\t\t\t\tCommandLine=\""
  1732. << this->EscapeForXML(script.c_str()) << "\"\n"
  1733. << "\t\t\t\t\tAdditionalDependencies=\"";
  1734. if(command.GetDepends().empty())
  1735. {
  1736. // There are no real dependencies. Produce an artificial one to
  1737. // make sure the rule runs reliably.
  1738. if(!cmSystemTools::FileExists(source))
  1739. {
  1740. cmsys::ofstream depout(source);
  1741. depout << "Artificial dependency for a custom command.\n";
  1742. }
  1743. fout << this->ConvertToXMLOutputPath(source);
  1744. }
  1745. else
  1746. {
  1747. // Write out the dependencies for the rule.
  1748. for(std::vector<std::string>::const_iterator d =
  1749. command.GetDepends().begin();
  1750. d != command.GetDepends().end();
  1751. ++d)
  1752. {
  1753. // Get the real name of the dependency in case it is a CMake target.
  1754. std::string dep;
  1755. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1756. {
  1757. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1758. << ";";
  1759. }
  1760. }
  1761. }
  1762. fout << "\"\n";
  1763. fout << "\t\t\t\t\tOutputs=\"";
  1764. if(command.GetOutputs().empty())
  1765. {
  1766. fout << source << "_force";
  1767. }
  1768. else
  1769. {
  1770. // Write a rule for the output generated by this command.
  1771. const char* sep = "";
  1772. for(std::vector<std::string>::const_iterator o =
  1773. command.GetOutputs().begin();
  1774. o != command.GetOutputs().end();
  1775. ++o)
  1776. {
  1777. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1778. sep = ";";
  1779. }
  1780. }
  1781. fout << "\"/>\n";
  1782. fout << "\t\t\t\t</FileConfiguration>\n";
  1783. }
  1784. }
  1785. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1786. const char* group,
  1787. const char* )
  1788. {
  1789. fout << "\t\t<Filter\n"
  1790. << "\t\t\tName=\"" << group << "\"\n"
  1791. << "\t\t\tFilter=\"\">\n";
  1792. }
  1793. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1794. {
  1795. fout << "\t\t</Filter>\n";
  1796. }
  1797. // look for custom rules on a target and collect them together
  1798. void cmLocalVisualStudio7Generator
  1799. ::OutputTargetRules(std::ostream& fout,
  1800. const char* configName,
  1801. cmTarget &target,
  1802. const std::string& /*libName*/)
  1803. {
  1804. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1805. {
  1806. return;
  1807. }
  1808. EventWriter event(this, configName, fout);
  1809. // Add pre-build event.
  1810. const char* tool =
  1811. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1812. event.Start(tool);
  1813. event.Write(target.GetPreBuildCommands());
  1814. event.Finish();
  1815. // Add pre-link event.
  1816. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1817. event.Start(tool);
  1818. event.Write(target.GetPreLinkCommands());
  1819. cmsys::auto_ptr<cmCustomCommand> pcc(
  1820. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1821. if(pcc.get())
  1822. {
  1823. event.Write(*pcc);
  1824. }
  1825. event.Finish();
  1826. // Add post-build event.
  1827. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1828. event.Start(tool);
  1829. event.Write(target.GetPostBuildCommands());
  1830. event.Finish();
  1831. }
  1832. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1833. cmTarget& target)
  1834. {
  1835. // if we have all the required Source code control tags
  1836. // then add that to the project
  1837. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1838. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1839. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1840. if(vsProvider && vsLocalpath && vsProjectname)
  1841. {
  1842. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1843. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1844. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1845. const char* vsAuxPath = target.GetProperty("VS_SCC_AUXPATH");
  1846. if(vsAuxPath)
  1847. {
  1848. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1849. }
  1850. }
  1851. }
  1852. void
  1853. cmLocalVisualStudio7Generator
  1854. ::WriteProjectStartFortran(std::ostream& fout,
  1855. const std::string& libName,
  1856. cmTarget & target)
  1857. {
  1858. cmGlobalVisualStudio7Generator* gg =
  1859. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1860. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1861. << "<VisualStudioProject\n"
  1862. << "\tProjectCreator=\"Intel Fortran\"\n"
  1863. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1864. const char* keyword = target.GetProperty("VS_KEYWORD");
  1865. if(!keyword)
  1866. {
  1867. keyword = "Console Application";
  1868. }
  1869. const char* projectType = 0;
  1870. switch(target.GetType())
  1871. {
  1872. case cmTarget::STATIC_LIBRARY:
  1873. projectType = "typeStaticLibrary";
  1874. if(keyword)
  1875. {
  1876. keyword = "Static Library";
  1877. }
  1878. break;
  1879. case cmTarget::SHARED_LIBRARY:
  1880. case cmTarget::MODULE_LIBRARY:
  1881. projectType = "typeDynamicLibrary";
  1882. if(!keyword)
  1883. {
  1884. keyword = "Dll";
  1885. }
  1886. break;
  1887. case cmTarget::EXECUTABLE:
  1888. if(!keyword)
  1889. {
  1890. keyword = "Console Application";
  1891. }
  1892. projectType = 0;
  1893. break;
  1894. case cmTarget::UTILITY:
  1895. case cmTarget::GLOBAL_TARGET:
  1896. default:
  1897. break;
  1898. }
  1899. if(projectType)
  1900. {
  1901. fout << "\tProjectType=\"" << projectType << "\"\n";
  1902. }
  1903. this->WriteProjectSCC(fout, target);
  1904. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1905. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1906. << "\t<Platforms>\n"
  1907. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1908. << "\t</Platforms>\n";
  1909. }
  1910. void
  1911. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1912. const std::string& libName,
  1913. cmTarget & target,
  1914. std::vector<cmSourceGroup> &)
  1915. {
  1916. if(this->FortranProject)
  1917. {
  1918. this->WriteProjectStartFortran(fout, libName, target);
  1919. return;
  1920. }
  1921. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1922. << "<VisualStudioProject\n"
  1923. << "\tProjectType=\"Visual C++\"\n";
  1924. if(this->Version == VS71)
  1925. {
  1926. fout << "\tVersion=\"7.10\"\n";
  1927. }
  1928. else
  1929. {
  1930. fout << "\tVersion=\"" << (this->Version/10) << ".00\"\n";
  1931. }
  1932. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1933. if(!projLabel)
  1934. {
  1935. projLabel = libName.c_str();
  1936. }
  1937. const char* keyword = target.GetProperty("VS_KEYWORD");
  1938. if(!keyword)
  1939. {
  1940. keyword = "Win32Proj";
  1941. }
  1942. cmGlobalVisualStudio7Generator* gg =
  1943. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1944. fout << "\tName=\"" << projLabel << "\"\n";
  1945. if(this->Version >= VS8)
  1946. {
  1947. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1948. }
  1949. this->WriteProjectSCC(fout, target);
  1950. if(const char* targetFrameworkVersion =
  1951. target.GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  1952. {
  1953. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1954. }
  1955. fout << "\tKeyword=\"" << keyword << "\">\n"
  1956. << "\t<Platforms>\n"
  1957. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1958. << "\t</Platforms>\n";
  1959. }
  1960. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
  1961. cmTarget &target)
  1962. {
  1963. fout << "\t<Globals>\n";
  1964. cmPropertyMap const& props = target.GetProperties();
  1965. for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
  1966. {
  1967. if(i->first.find("VS_GLOBAL_") == 0)
  1968. {
  1969. std::string name = i->first.substr(10);
  1970. if(name != "")
  1971. {
  1972. fout << "\t\t<Global\n"
  1973. << "\t\t\tName=\"" << name << "\"\n"
  1974. << "\t\t\tValue=\"" << i->second.GetValue() << "\"\n"
  1975. << "\t\t/>\n";
  1976. }
  1977. }
  1978. }
  1979. fout << "\t</Globals>\n"
  1980. << "</VisualStudioProject>\n";
  1981. }
  1982. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1983. {
  1984. std::string ret = s;
  1985. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1986. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1987. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1988. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1989. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1990. return ret;
  1991. }
  1992. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1993. {
  1994. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1995. }
  1996. std::string cmLocalVisualStudio7Generator
  1997. ::ConvertToXMLOutputPath(const char* path)
  1998. {
  1999. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2000. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2001. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  2002. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2003. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2004. return ret;
  2005. }
  2006. std::string cmLocalVisualStudio7Generator
  2007. ::ConvertToXMLOutputPathSingle(const char* path)
  2008. {
  2009. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  2010. cmSystemTools::ReplaceString(ret, "\"", "");
  2011. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  2012. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  2013. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  2014. return ret;
  2015. }
  2016. // This class is used to parse an existing vs 7 project
  2017. // and extract the GUID
  2018. class cmVS7XMLParser : public cmXMLParser
  2019. {
  2020. public:
  2021. virtual void EndElement(const char* /* name */)
  2022. {
  2023. }
  2024. virtual void StartElement(const char* name, const char** atts)
  2025. {
  2026. // once the GUID is found do nothing
  2027. if(this->GUID.size())
  2028. {
  2029. return;
  2030. }
  2031. int i =0;
  2032. if(strcmp("VisualStudioProject", name) == 0)
  2033. {
  2034. while(atts[i])
  2035. {
  2036. if(strcmp(atts[i], "ProjectGUID") == 0)
  2037. {
  2038. if(atts[i+1])
  2039. {
  2040. this->GUID = atts[i+1];
  2041. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  2042. }
  2043. else
  2044. {
  2045. this->GUID = "";
  2046. }
  2047. return;
  2048. }
  2049. ++i;
  2050. }
  2051. }
  2052. }
  2053. int InitializeParser()
  2054. {
  2055. int ret = cmXMLParser::InitializeParser();
  2056. if(ret == 0)
  2057. {
  2058. return ret;
  2059. }
  2060. // visual studio projects have a strange encoding, but it is
  2061. // really utf-8
  2062. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  2063. return 1;
  2064. }
  2065. std::string GUID;
  2066. };
  2067. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  2068. const char* name,
  2069. const char* path)
  2070. {
  2071. cmVS7XMLParser parser;
  2072. parser.ParseFile(path);
  2073. // if we can not find a GUID then create one
  2074. if(parser.GUID.size() == 0)
  2075. {
  2076. cmGlobalVisualStudio7Generator* gg =
  2077. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  2078. gg->CreateGUID(name);
  2079. return;
  2080. }
  2081. std::string guidStoreName = name;
  2082. guidStoreName += "_GUID_CMAKE";
  2083. // save the GUID in the cache
  2084. this->GlobalGenerator->GetCMakeInstance()->
  2085. AddCacheEntry(guidStoreName.c_str(),
  2086. parser.GUID.c_str(),
  2087. "Stored GUID",
  2088. cmCacheManager::INTERNAL);
  2089. }
  2090. //----------------------------------------------------------------------------
  2091. std::string cmLocalVisualStudio7Generator
  2092. ::GetTargetDirectory(cmTarget const& target) const
  2093. {
  2094. std::string dir;
  2095. dir += target.GetName();
  2096. dir += ".dir";
  2097. return dir;
  2098. }
  2099. //----------------------------------------------------------------------------
  2100. #include <windows.h>
  2101. static bool cmLVS6G_IsFAT(const char* dir)
  2102. {
  2103. if(dir[0] && dir[1] == ':')
  2104. {
  2105. char volRoot[4] = "_:/";
  2106. volRoot[0] = dir[0];
  2107. char fsName[16];
  2108. if(GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2109. strstr(fsName, "FAT") != 0)
  2110. {
  2111. return true;
  2112. }
  2113. }
  2114. return false;
  2115. }