cmLocalVisualStudio7Generator.cxx 67 KB

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