cmLocalVisualStudio7Generator.cxx 66 KB

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