cmLocalVisualStudio7Generator.cxx 66 KB

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