cmLocalVisualStudio7Generator.cxx 75 KB

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