cmLocalVisualStudio7Generator.cxx 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  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 | cmVS7FlagTable::SemicolonAppendable},
  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. {"EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  437. cmVS7FlagTable::UserValue},
  438. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  439. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  440. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  441. "TRUE", 0},
  442. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  443. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  444. "2", 0},
  445. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  446. "1", 0},
  447. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  448. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  449. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  450. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  451. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  452. {"TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0},
  453. {"TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0},
  454. {"TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0},
  455. {"TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0},
  456. {"TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0},
  457. {"TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0},
  458. {"TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0},
  459. {"TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0},
  460. {"TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0},
  461. {"TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0},
  462. {"TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0},
  463. {"TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0},
  464. {"TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0},
  465. {"TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0},
  466. {"TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0},
  467. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  468. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  469. cmVS7FlagTable::UserValue},
  470. {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
  471. {0,0,0,0,0}
  472. };
  473. //----------------------------------------------------------------------------
  474. // Helper class to write build event <Tool .../> elements.
  475. class cmLocalVisualStudio7Generator::EventWriter
  476. {
  477. public:
  478. EventWriter(cmLocalVisualStudio7Generator* lg,
  479. const char* config, std::ostream& os):
  480. LG(lg), Config(config), Stream(os), First(true) {}
  481. void Start(const char* tool)
  482. {
  483. this->First = true;
  484. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  485. }
  486. void Finish()
  487. {
  488. this->Stream << (this->First? "" : "\"") << "/>\n";
  489. }
  490. void Write(std::vector<cmCustomCommand> const& ccs)
  491. {
  492. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  493. ci != ccs.end(); ++ci)
  494. {
  495. this->Write(*ci);
  496. }
  497. }
  498. void Write(cmCustomCommand const& cc)
  499. {
  500. if(this->First)
  501. {
  502. const char* comment = cc.GetComment();
  503. if(comment && *comment)
  504. {
  505. this->Stream << "\nDescription=\""
  506. << this->LG->EscapeForXML(comment) << "\"";
  507. }
  508. this->Stream << "\nCommandLine=\"";
  509. this->First = false;
  510. }
  511. else
  512. {
  513. this->Stream << this->LG->EscapeForXML("\n");
  514. }
  515. std::string script = this->LG->ConstructScript(cc, this->Config);
  516. this->Stream << this->LG->EscapeForXML(script.c_str());
  517. }
  518. private:
  519. cmLocalVisualStudio7Generator* LG;
  520. const char* Config;
  521. std::ostream& Stream;
  522. bool First;
  523. };
  524. //----------------------------------------------------------------------------
  525. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  526. const char* configName,
  527. const char *libName,
  528. cmTarget &target)
  529. {
  530. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  531. if(!mfcFlag)
  532. {
  533. mfcFlag = "0";
  534. }
  535. fout << "\t\t<Configuration\n"
  536. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  537. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  538. // This is an internal type to Visual Studio, it seems that:
  539. // 4 == static library
  540. // 2 == dll
  541. // 1 == executable
  542. // 10 == utility
  543. const char* configType = "10";
  544. const char* projectType = 0;
  545. bool targetBuilds = true;
  546. switch(target.GetType())
  547. {
  548. case cmTarget::STATIC_LIBRARY:
  549. projectType = "typeStaticLibrary";
  550. configType = "4";
  551. break;
  552. case cmTarget::SHARED_LIBRARY:
  553. case cmTarget::MODULE_LIBRARY:
  554. projectType = "typeDynamicLibrary";
  555. configType = "2";
  556. break;
  557. case cmTarget::EXECUTABLE:
  558. configType = "1";
  559. break;
  560. case cmTarget::UTILITY:
  561. case cmTarget::GLOBAL_TARGET:
  562. configType = "10";
  563. default:
  564. targetBuilds = false;
  565. break;
  566. }
  567. if(this->FortranProject && projectType)
  568. {
  569. configType = projectType;
  570. }
  571. std::string flags;
  572. if(strcmp(configType, "10") != 0)
  573. {
  574. const char* linkLanguage = (this->FortranProject? "Fortran":
  575. target.GetLinkerLanguage(configName));
  576. if(!linkLanguage)
  577. {
  578. cmSystemTools::Error
  579. ("CMake can not determine linker language for target:",
  580. target.GetName());
  581. return;
  582. }
  583. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  584. || strcmp(linkLanguage, "Fortran") == 0)
  585. {
  586. std::string baseFlagVar = "CMAKE_";
  587. baseFlagVar += linkLanguage;
  588. baseFlagVar += "_FLAGS";
  589. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  590. std::string flagVar = baseFlagVar + std::string("_") +
  591. cmSystemTools::UpperCase(configName);
  592. flags += " ";
  593. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  594. }
  595. // set the correct language
  596. if(strcmp(linkLanguage, "C") == 0)
  597. {
  598. flags += " /TC ";
  599. }
  600. if(strcmp(linkLanguage, "CXX") == 0)
  601. {
  602. flags += " /TP ";
  603. }
  604. }
  605. // Add the target-specific flags.
  606. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  607. {
  608. flags += " ";
  609. flags += targetFlags;
  610. }
  611. std::string configUpper = cmSystemTools::UpperCase(configName);
  612. std::string defPropName = "COMPILE_DEFINITIONS_";
  613. defPropName += configUpper;
  614. // Get preprocessor definitions for this directory.
  615. std::string defineFlags = this->Makefile->GetDefineFlags();
  616. Options::Tool t = Options::Compiler;
  617. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  618. if(this->FortranProject)
  619. {
  620. t = Options::FortranCompiler;
  621. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  622. }
  623. Options targetOptions(this, this->Version, t,
  624. table,
  625. this->ExtraFlagTable);
  626. targetOptions.FixExceptionHandlingDefault();
  627. targetOptions.Parse(flags.c_str());
  628. targetOptions.Parse(defineFlags.c_str());
  629. targetOptions.ParseFinish();
  630. targetOptions.AddDefines
  631. (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
  632. targetOptions.AddDefines(target.GetProperty("COMPILE_DEFINITIONS"));
  633. targetOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
  634. targetOptions.AddDefines(target.GetProperty(defPropName.c_str()));
  635. targetOptions.SetVerboseMakefile(
  636. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  637. // Add a definition for the configuration name.
  638. std::string configDefine = "CMAKE_INTDIR=\"";
  639. configDefine += configName;
  640. configDefine += "\"";
  641. targetOptions.AddDefine(configDefine);
  642. // Add the export symbol definition for shared library objects.
  643. if(const char* exportMacro = target.GetExportMacro())
  644. {
  645. targetOptions.AddDefine(exportMacro);
  646. }
  647. // The intermediate directory name consists of a directory for the
  648. // target and a subdirectory for the configuration name.
  649. std::string intermediateDir = this->GetTargetDirectory(target);
  650. intermediateDir += "/";
  651. intermediateDir += configName;
  652. fout << "\t\t\tIntermediateDirectory=\""
  653. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  654. << "\"\n"
  655. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  656. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  657. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  658. // If unicode is enabled change the character set to unicode, if not
  659. // then default to MBCS.
  660. if(targetOptions.UsingUnicode())
  661. {
  662. fout << "\t\t\tCharacterSet=\"1\">\n";
  663. }
  664. else
  665. {
  666. fout << "\t\t\tCharacterSet=\"2\">\n";
  667. }
  668. const char* tool = "VCCLCompilerTool";
  669. if(this->FortranProject)
  670. {
  671. tool = "VFFortranCompilerTool";
  672. }
  673. fout << "\t\t\t<Tool\n"
  674. << "\t\t\t\tName=\"" << tool << "\"\n";
  675. if(this->FortranProject)
  676. {
  677. const char* target_mod_dir =
  678. target.GetProperty("Fortran_MODULE_DIRECTORY");
  679. std::string modDir;
  680. if(target_mod_dir)
  681. {
  682. modDir = this->Convert(target_mod_dir,
  683. cmLocalGenerator::START_OUTPUT,
  684. cmLocalGenerator::UNCHANGED);
  685. }
  686. else
  687. {
  688. modDir = ".";
  689. }
  690. fout << "\t\t\t\tModulePath=\""
  691. << this->ConvertToXMLOutputPath(modDir.c_str())
  692. << "\\$(ConfigurationName)\"\n";
  693. }
  694. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  695. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  696. std::vector<std::string> includes;
  697. this->GetIncludeDirectories(includes);
  698. std::vector<std::string>::iterator i = includes.begin();
  699. for(;i != includes.end(); ++i)
  700. {
  701. // output the include path
  702. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  703. fout << ipath << ";";
  704. // if this is fortran then output the include with
  705. // a ConfigurationName on the end of it.
  706. if(this->FortranProject)
  707. {
  708. ipath = i->c_str();
  709. ipath += "/$(ConfigurationName)";
  710. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  711. fout << ipath << ";";
  712. }
  713. }
  714. fout << "\"\n";
  715. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  716. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  717. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  718. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  719. if(targetBuilds)
  720. {
  721. // We need to specify a program database file name even for
  722. // non-debug configurations because VS still creates .idb files.
  723. fout << "\t\t\t\tProgramDataBaseFileName=\""
  724. << this->ConvertToXMLOutputPathSingle(
  725. target.GetDirectory(configName).c_str())
  726. << "/"
  727. << target.GetPDBName(configName) << "\"\n";
  728. }
  729. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  730. tool = "VCCustomBuildTool";
  731. if(this->FortranProject)
  732. {
  733. tool = "VFCustomBuildTool";
  734. }
  735. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  736. tool = "VCResourceCompilerTool";
  737. if(this->FortranProject)
  738. {
  739. tool = "VFResourceCompilerTool";
  740. }
  741. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  742. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  743. for(i = includes.begin();i != includes.end(); ++i)
  744. {
  745. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  746. fout << ipath << ";";
  747. }
  748. // add the -D flags to the RC tool
  749. fout << "\"";
  750. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  751. fout << "/>\n";
  752. tool = "VCMIDLTool";
  753. if(this->FortranProject)
  754. {
  755. tool = "VFMIDLTool";
  756. }
  757. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  758. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  759. if( this->PlatformName == "x64" )
  760. {
  761. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  762. }
  763. else if( this->PlatformName == "ia64" )
  764. {
  765. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  766. }
  767. else
  768. {
  769. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  770. }
  771. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  772. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  773. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  774. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  775. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  776. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  777. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  778. // end of <Tool Name=VCMIDLTool
  779. // Check if we need the FAT32 workaround.
  780. if(targetBuilds && this->Version >= 8)
  781. {
  782. // Check the filesystem type where the target will be written.
  783. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  784. {
  785. // Add a flag telling the manifest tool to use a workaround
  786. // for FAT32 file systems, which can cause an empty manifest
  787. // to be embedded into the resulting executable. See CMake
  788. // bug #2617.
  789. const char* tool = "VCManifestTool";
  790. if(this->FortranProject)
  791. {
  792. tool = "VFManifestTool";
  793. }
  794. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  795. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  796. << "\t\t\t/>\n";
  797. }
  798. }
  799. this->OutputTargetRules(fout, configName, target, libName);
  800. this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
  801. fout << "\t\t</Configuration>\n";
  802. }
  803. //----------------------------------------------------------------------------
  804. std::string
  805. cmLocalVisualStudio7Generator
  806. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  807. {
  808. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  809. std::string extraLinkOptionsBuildTypeDef =
  810. rootLinkerFlags + "_" + configTypeUpper;
  811. std::string extraLinkOptionsBuildType =
  812. this->Makefile->GetRequiredDefinition
  813. (extraLinkOptionsBuildTypeDef.c_str());
  814. return extraLinkOptionsBuildType;
  815. }
  816. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  817. const char* configName,
  818. cmTarget &target,
  819. bool isDebug)
  820. {
  821. cmGlobalVisualStudio7Generator* gg =
  822. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  823. std::string temp;
  824. std::string extraLinkOptions;
  825. if(target.GetType() == cmTarget::EXECUTABLE)
  826. {
  827. extraLinkOptions =
  828. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  829. + std::string(" ")
  830. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  831. }
  832. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  833. {
  834. extraLinkOptions =
  835. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  836. + std::string(" ")
  837. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  838. }
  839. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  840. {
  841. extraLinkOptions =
  842. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  843. + std::string(" ")
  844. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  845. }
  846. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  847. if(targetLinkFlags)
  848. {
  849. extraLinkOptions += " ";
  850. extraLinkOptions += targetLinkFlags;
  851. }
  852. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  853. std::string linkFlagsConfig = "LINK_FLAGS_";
  854. linkFlagsConfig += configTypeUpper;
  855. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  856. if(targetLinkFlags)
  857. {
  858. extraLinkOptions += " ";
  859. extraLinkOptions += targetLinkFlags;
  860. }
  861. Options linkOptions(this, this->Version, Options::Linker,
  862. cmLocalVisualStudio7GeneratorLinkFlagTable);
  863. linkOptions.Parse(extraLinkOptions.c_str());
  864. if(!this->ModuleDefinitionFile.empty())
  865. {
  866. std::string defFile =
  867. this->ConvertToXMLOutputPath(this->ModuleDefinitionFile.c_str());
  868. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  869. }
  870. switch(target.GetType())
  871. {
  872. case cmTarget::STATIC_LIBRARY:
  873. {
  874. std::string targetNameFull = target.GetFullName(configName);
  875. std::string libpath = target.GetDirectory(configName);
  876. libpath += "/";
  877. libpath += targetNameFull;
  878. const char* tool = "VCLibrarianTool";
  879. if(this->FortranProject)
  880. {
  881. tool = "VFLibrarianTool";
  882. }
  883. fout << "\t\t\t<Tool\n"
  884. << "\t\t\t\tName=\"" << tool << "\"\n";
  885. std::string libflags;
  886. if(const char* flags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  887. {
  888. libflags += flags;
  889. }
  890. std::string libFlagsConfig = "STATIC_LIBRARY_FLAGS_";
  891. libFlagsConfig += configTypeUpper;
  892. if(const char* flagsConfig = target.GetProperty(libFlagsConfig.c_str()))
  893. {
  894. libflags += " ";
  895. libflags += flagsConfig;
  896. }
  897. if(!libflags.empty())
  898. {
  899. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  900. }
  901. fout << "\t\t\t\tOutputFile=\""
  902. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  903. break;
  904. }
  905. case cmTarget::SHARED_LIBRARY:
  906. case cmTarget::MODULE_LIBRARY:
  907. {
  908. std::string targetName;
  909. std::string targetNameSO;
  910. std::string targetNameFull;
  911. std::string targetNameImport;
  912. std::string targetNamePDB;
  913. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  914. targetNameImport, targetNamePDB, configName);
  915. // Compute the link library and directory information.
  916. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  917. if(!pcli)
  918. {
  919. return;
  920. }
  921. cmComputeLinkInformation& cli = *pcli;
  922. const char* linkLanguage = cli.GetLinkLanguage();
  923. // Compute the variable name to lookup standard libraries for this
  924. // language.
  925. std::string standardLibsVar = "CMAKE_";
  926. standardLibsVar += linkLanguage;
  927. standardLibsVar += "_STANDARD_LIBRARIES";
  928. const char* tool = "VCLinkerTool";
  929. if(this->FortranProject)
  930. {
  931. tool = "VFLinkerTool";
  932. }
  933. fout << "\t\t\t<Tool\n"
  934. << "\t\t\t\tName=\"" << tool << "\"\n";
  935. if(!gg->NeedLinkLibraryDependencies(target))
  936. {
  937. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  938. }
  939. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  940. // Use the NOINHERIT macro to avoid getting VS project default
  941. // libraries which may be set by the user to something bad.
  942. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  943. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  944. << " ";
  945. this->Internal->OutputLibraries(fout, cli.GetItems());
  946. fout << "\"\n";
  947. temp = target.GetDirectory(configName);
  948. temp += "/";
  949. temp += targetNameFull;
  950. fout << "\t\t\t\tOutputFile=\""
  951. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  952. this->WriteTargetVersionAttribute(fout, target);
  953. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  954. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  955. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  956. fout << "\"\n";
  957. temp = target.GetDirectory(configName);
  958. temp += "/";
  959. temp += targetNamePDB;
  960. fout << "\t\t\t\tProgramDatabaseFile=\"" <<
  961. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  962. if(isDebug)
  963. {
  964. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  965. }
  966. std::string stackVar = "CMAKE_";
  967. stackVar += linkLanguage;
  968. stackVar += "_STACK_SIZE";
  969. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  970. if(stackVal)
  971. {
  972. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  973. }
  974. temp = target.GetDirectory(configName, true);
  975. temp += "/";
  976. temp += targetNameImport;
  977. fout << "\t\t\t\tImportLibrary=\""
  978. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  979. if(this->FortranProject)
  980. {
  981. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  982. }
  983. fout << "/>\n";
  984. }
  985. break;
  986. case cmTarget::EXECUTABLE:
  987. {
  988. std::string targetName;
  989. std::string targetNameFull;
  990. std::string targetNameImport;
  991. std::string targetNamePDB;
  992. target.GetExecutableNames(targetName, targetNameFull,
  993. targetNameImport, targetNamePDB, configName);
  994. // Compute the link library and directory information.
  995. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  996. if(!pcli)
  997. {
  998. return;
  999. }
  1000. cmComputeLinkInformation& cli = *pcli;
  1001. const char* linkLanguage = cli.GetLinkLanguage();
  1002. // Compute the variable name to lookup standard libraries for this
  1003. // language.
  1004. std::string standardLibsVar = "CMAKE_";
  1005. standardLibsVar += linkLanguage;
  1006. standardLibsVar += "_STANDARD_LIBRARIES";
  1007. const char* tool = "VCLinkerTool";
  1008. if(this->FortranProject)
  1009. {
  1010. tool = "VFLinkerTool";
  1011. }
  1012. fout << "\t\t\t<Tool\n"
  1013. << "\t\t\t\tName=\"" << tool << "\"\n";
  1014. if(!gg->NeedLinkLibraryDependencies(target))
  1015. {
  1016. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1017. }
  1018. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1019. // Use the NOINHERIT macro to avoid getting VS project default
  1020. // libraries which may be set by the user to something bad.
  1021. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1022. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  1023. << " ";
  1024. this->Internal->OutputLibraries(fout, cli.GetItems());
  1025. fout << "\"\n";
  1026. temp = target.GetDirectory(configName);
  1027. temp += "/";
  1028. temp += targetNameFull;
  1029. fout << "\t\t\t\tOutputFile=\""
  1030. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1031. this->WriteTargetVersionAttribute(fout, target);
  1032. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1033. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1034. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1035. fout << "\"\n";
  1036. std::string path = this->ConvertToXMLOutputPathSingle(
  1037. target.GetDirectory(configName).c_str());
  1038. fout << "\t\t\t\tProgramDatabaseFile=\""
  1039. << path << "/" << targetNamePDB
  1040. << "\"\n";
  1041. if(isDebug)
  1042. {
  1043. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  1044. }
  1045. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1046. {
  1047. fout << "\t\t\t\tSubSystem=\""
  1048. << (this->FortranProject? "subSystemWindows" : "2") << "\"\n";
  1049. }
  1050. else
  1051. {
  1052. fout << "\t\t\t\tSubSystem=\""
  1053. << (this->FortranProject? "subSystemConsole" : "1") << "\"\n";
  1054. }
  1055. std::string stackVar = "CMAKE_";
  1056. stackVar += linkLanguage;
  1057. stackVar += "_STACK_SIZE";
  1058. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1059. if(stackVal)
  1060. {
  1061. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1062. }
  1063. temp = target.GetDirectory(configName, true);
  1064. temp += "/";
  1065. temp += targetNameImport;
  1066. fout << "\t\t\t\tImportLibrary=\""
  1067. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1068. break;
  1069. }
  1070. case cmTarget::UTILITY:
  1071. case cmTarget::GLOBAL_TARGET:
  1072. break;
  1073. }
  1074. }
  1075. //----------------------------------------------------------------------------
  1076. void
  1077. cmLocalVisualStudio7Generator
  1078. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1079. {
  1080. int major;
  1081. int minor;
  1082. target.GetTargetVersion(major, minor);
  1083. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1084. }
  1085. //----------------------------------------------------------------------------
  1086. void
  1087. cmLocalVisualStudio7GeneratorInternals
  1088. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1089. {
  1090. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1091. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1092. {
  1093. if(l->IsPath)
  1094. {
  1095. std::string rel = lg->Convert(l->Value.c_str(),
  1096. cmLocalGenerator::START_OUTPUT,
  1097. cmLocalGenerator::UNCHANGED);
  1098. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1099. }
  1100. else
  1101. {
  1102. fout << l->Value << " ";
  1103. }
  1104. }
  1105. }
  1106. //----------------------------------------------------------------------------
  1107. void
  1108. cmLocalVisualStudio7Generator
  1109. ::OutputLibraryDirectories(std::ostream& fout,
  1110. std::vector<std::string> const& dirs)
  1111. {
  1112. const char* comma = "";
  1113. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1114. d != dirs.end(); ++d)
  1115. {
  1116. // Remove any trailing slash and skip empty paths.
  1117. std::string dir = *d;
  1118. if(dir[dir.size()-1] == '/')
  1119. {
  1120. dir = dir.substr(0, dir.size()-1);
  1121. }
  1122. if(dir.empty())
  1123. {
  1124. continue;
  1125. }
  1126. // Switch to a relative path specification if it is shorter.
  1127. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1128. {
  1129. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1130. if(rel.size() < dir.size())
  1131. {
  1132. dir = rel;
  1133. }
  1134. }
  1135. // First search a configuration-specific subdirectory and then the
  1136. // original directory.
  1137. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1138. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1139. comma = ",";
  1140. }
  1141. }
  1142. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1143. const char *libName,
  1144. cmTarget &target)
  1145. {
  1146. // get the configurations
  1147. std::vector<std::string> *configs =
  1148. static_cast<cmGlobalVisualStudio7Generator *>
  1149. (this->GlobalGenerator)->GetConfigurations();
  1150. // We may be modifying the source groups temporarily, so make a copy.
  1151. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1152. // get the classes from the source lists then add them to the groups
  1153. this->ModuleDefinitionFile = "";
  1154. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  1155. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1156. i != classes.end(); i++)
  1157. {
  1158. // Add the file to the list of sources.
  1159. std::string source = (*i)->GetFullPath();
  1160. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1161. {
  1162. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1163. }
  1164. cmSourceGroup& sourceGroup =
  1165. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1166. sourceGroup.AssignSource(*i);
  1167. }
  1168. // Compute which sources need unique object computation.
  1169. this->ComputeObjectNameRequirements(sourceGroups);
  1170. // open the project
  1171. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1172. // write the configuration information
  1173. this->WriteConfigurations(fout, libName, target);
  1174. fout << "\t<Files>\n";
  1175. // Loop through every source group.
  1176. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1177. {
  1178. cmSourceGroup sg = sourceGroups[i];
  1179. this->WriteGroup(&sg, target, fout, libName, configs);
  1180. }
  1181. //}
  1182. fout << "\t</Files>\n";
  1183. // Write the VCProj file's footer.
  1184. this->WriteVCProjFooter(fout);
  1185. }
  1186. struct cmLVS7GFileConfig
  1187. {
  1188. std::string ObjectName;
  1189. std::string CompileFlags;
  1190. std::string CompileDefs;
  1191. std::string CompileDefsConfig;
  1192. std::string AdditionalDeps;
  1193. bool ExcludedFromBuild;
  1194. };
  1195. class cmLocalVisualStudio7GeneratorFCInfo
  1196. {
  1197. public:
  1198. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1199. cmTarget& target,
  1200. cmSourceFile const& sf,
  1201. std::vector<std::string>* configs,
  1202. std::string const& dir_max);
  1203. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1204. };
  1205. cmLocalVisualStudio7GeneratorFCInfo
  1206. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1207. cmTarget& target,
  1208. cmSourceFile const& sf,
  1209. std::vector<std::string>* configs,
  1210. std::string const& dir_max)
  1211. {
  1212. std::string objectName;
  1213. if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
  1214. {
  1215. objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max);
  1216. }
  1217. // Compute per-source, per-config information.
  1218. for(std::vector<std::string>::iterator i = configs->begin();
  1219. i != configs->end(); ++i)
  1220. {
  1221. std::string configUpper = cmSystemTools::UpperCase(*i);
  1222. cmLVS7GFileConfig fc;
  1223. bool needfc = false;
  1224. if(!objectName.empty())
  1225. {
  1226. fc.ObjectName = objectName;
  1227. needfc = true;
  1228. }
  1229. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1230. {
  1231. fc.CompileFlags = cflags;
  1232. needfc = true;
  1233. }
  1234. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1235. {
  1236. fc.CompileDefs = cdefs;
  1237. needfc = true;
  1238. }
  1239. std::string defPropName = "COMPILE_DEFINITIONS_";
  1240. defPropName += configUpper;
  1241. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1242. {
  1243. fc.CompileDefsConfig = ccdefs;
  1244. needfc = true;
  1245. }
  1246. // Check for extra object-file dependencies.
  1247. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1248. {
  1249. std::vector<std::string> depends;
  1250. cmSystemTools::ExpandListArgument(deps, depends);
  1251. const char* sep = "";
  1252. for(std::vector<std::string>::iterator j = depends.begin();
  1253. j != depends.end(); ++j)
  1254. {
  1255. fc.AdditionalDeps += sep;
  1256. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1257. sep = ";";
  1258. needfc = true;
  1259. }
  1260. }
  1261. const char* lang =
  1262. lg->GlobalGenerator->GetLanguageFromExtension
  1263. (sf.GetExtension().c_str());
  1264. const char* sourceLang = lg->GetSourceFileLanguage(sf);
  1265. const char* linkLanguage = target.GetLinkerLanguage(i->c_str());
  1266. bool needForceLang = false;
  1267. // source file does not match its extension language
  1268. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1269. {
  1270. needForceLang = true;
  1271. lang = sourceLang;
  1272. }
  1273. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1274. // the project file
  1275. fc.ExcludedFromBuild =
  1276. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1277. if(fc.ExcludedFromBuild)
  1278. {
  1279. needfc = true;
  1280. }
  1281. // if the source file does not match the linker language
  1282. // then force c or c++
  1283. if(needForceLang || (linkLanguage && lang
  1284. && strcmp(lang, linkLanguage) != 0))
  1285. {
  1286. if(strcmp(lang, "CXX") == 0)
  1287. {
  1288. // force a C++ file type
  1289. fc.CompileFlags += " /TP ";
  1290. needfc = true;
  1291. }
  1292. else if(strcmp(lang, "C") == 0)
  1293. {
  1294. // force to c
  1295. fc.CompileFlags += " /TC ";
  1296. needfc = true;
  1297. }
  1298. }
  1299. if(needfc)
  1300. {
  1301. this->FileConfigMap[*i] = fc;
  1302. }
  1303. }
  1304. }
  1305. void cmLocalVisualStudio7Generator
  1306. ::ComputeMaxDirectoryLength(std::string& maxdir,
  1307. cmTarget& target)
  1308. {
  1309. std::vector<std::string> *configs =
  1310. static_cast<cmGlobalVisualStudio7Generator *>
  1311. (this->GlobalGenerator)->GetConfigurations();
  1312. // Compute the maximum length configuration name.
  1313. std::string config_max;
  1314. for(std::vector<std::string>::iterator i = configs->begin();
  1315. i != configs->end(); ++i)
  1316. {
  1317. if(i->size() > config_max.size())
  1318. {
  1319. config_max = *i;
  1320. }
  1321. }
  1322. // Compute the maximum length full path to the intermediate
  1323. // files directory for any configuration. This is used to construct
  1324. // object file names that do not produce paths that are too long.
  1325. std::string dir_max;
  1326. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1327. dir_max += "/";
  1328. dir_max += this->GetTargetDirectory(target);
  1329. dir_max += "/";
  1330. dir_max += config_max;
  1331. dir_max += "/";
  1332. maxdir = dir_max;
  1333. }
  1334. void cmLocalVisualStudio7Generator
  1335. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1336. std::ostream &fout, const char *libName,
  1337. std::vector<std::string> *configs)
  1338. {
  1339. const std::vector<const cmSourceFile *> &sourceFiles =
  1340. sg->GetSourceFiles();
  1341. // If the group is empty, don't write it at all.
  1342. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1343. {
  1344. return;
  1345. }
  1346. // If the group has a name, write the header.
  1347. std::string name = sg->GetName();
  1348. if(name != "")
  1349. {
  1350. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1351. }
  1352. // Compute the maximum length full path to the intermediate
  1353. // files directory for any configuration. This is used to construct
  1354. // object file names that do not produce paths that are too long.
  1355. std::string dir_max;
  1356. this->ComputeMaxDirectoryLength(dir_max, target);
  1357. // Loop through each source in the source group.
  1358. std::string objectName;
  1359. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1360. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1361. {
  1362. std::string source = (*sf)->GetFullPath();
  1363. FCInfo fcinfo(this, target, *(*sf), configs, dir_max);
  1364. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1365. target.GetType() == cmTarget::GLOBAL_TARGET )
  1366. {
  1367. fout << "\t\t\t<File\n";
  1368. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1369. // Tell MS-Dev what the source is. If the compiler knows how to
  1370. // build it, then it will.
  1371. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1372. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1373. {
  1374. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1375. }
  1376. else if(!fcinfo.FileConfigMap.empty())
  1377. {
  1378. const char* aCompilerTool = "VCCLCompilerTool";
  1379. const char* lang = "CXX";
  1380. if(this->FortranProject)
  1381. {
  1382. aCompilerTool = "VFFortranCompilerTool";
  1383. }
  1384. std::string ext = (*sf)->GetExtension();
  1385. ext = cmSystemTools::LowerCase(ext);
  1386. if(ext == "idl")
  1387. {
  1388. aCompilerTool = "VCMIDLTool";
  1389. if(this->FortranProject)
  1390. {
  1391. aCompilerTool = "VFMIDLTool";
  1392. }
  1393. }
  1394. if(ext == "rc")
  1395. {
  1396. aCompilerTool = "VCResourceCompilerTool";
  1397. lang = "RC";
  1398. if(this->FortranProject)
  1399. {
  1400. aCompilerTool = "VFResourceCompilerTool";
  1401. }
  1402. }
  1403. if(ext == "def")
  1404. {
  1405. aCompilerTool = "VCCustomBuildTool";
  1406. if(this->FortranProject)
  1407. {
  1408. aCompilerTool = "VFCustomBuildTool";
  1409. }
  1410. }
  1411. for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
  1412. fci = fcinfo.FileConfigMap.begin();
  1413. fci != fcinfo.FileConfigMap.end(); ++fci)
  1414. {
  1415. cmLVS7GFileConfig const& fc = fci->second;
  1416. fout << "\t\t\t\t<FileConfiguration\n"
  1417. << "\t\t\t\t\tName=\"" << fci->first
  1418. << "|" << this->PlatformName << "\"";
  1419. if(fc.ExcludedFromBuild)
  1420. {
  1421. fout << " ExcludedFromBuild=\"true\"";
  1422. }
  1423. fout << ">\n";
  1424. fout << "\t\t\t\t\t<Tool\n"
  1425. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1426. if(!fc.CompileFlags.empty() ||
  1427. !fc.CompileDefs.empty() ||
  1428. !fc.CompileDefsConfig.empty())
  1429. {
  1430. Options fileOptions(this, this->Version, Options::Compiler,
  1431. cmLocalVisualStudio7GeneratorFlagTable,
  1432. this->ExtraFlagTable);
  1433. fileOptions.Parse(fc.CompileFlags.c_str());
  1434. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1435. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1436. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1437. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1438. fileOptions.OutputPreprocessorDefinitions(fout,
  1439. "\t\t\t\t\t", "\n",
  1440. lang);
  1441. }
  1442. if(!fc.AdditionalDeps.empty())
  1443. {
  1444. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1445. << fc.AdditionalDeps.c_str() << "\"\n";
  1446. }
  1447. if(!fc.ObjectName.empty())
  1448. {
  1449. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1450. << fc.ObjectName.c_str() << "\"\n";
  1451. }
  1452. fout << "\t\t\t\t\t/>\n"
  1453. << "\t\t\t\t</FileConfiguration>\n";
  1454. }
  1455. }
  1456. fout << "\t\t\t</File>\n";
  1457. }
  1458. }
  1459. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1460. for(unsigned int i=0;i<children.size();++i)
  1461. {
  1462. this->WriteGroup(&children[i], target, fout, libName, configs);
  1463. }
  1464. // If the group has a name, write the footer.
  1465. if(name != "")
  1466. {
  1467. this->WriteVCProjEndGroup(fout);
  1468. }
  1469. }
  1470. void cmLocalVisualStudio7Generator::
  1471. WriteCustomRule(std::ostream& fout,
  1472. const char* source,
  1473. const cmCustomCommand& command,
  1474. FCInfo& fcinfo)
  1475. {
  1476. std::string comment = this->ConstructComment(command);
  1477. // Write the rule for each configuration.
  1478. std::vector<std::string>::iterator i;
  1479. std::vector<std::string> *configs =
  1480. static_cast<cmGlobalVisualStudio7Generator *>
  1481. (this->GlobalGenerator)->GetConfigurations();
  1482. const char* compileTool = "VCCLCompilerTool";
  1483. if(this->FortranProject)
  1484. {
  1485. compileTool = "VFCLCompilerTool";
  1486. }
  1487. const char* customTool = "VCCustomBuildTool";
  1488. if(this->FortranProject)
  1489. {
  1490. customTool = "VFCustomBuildTool";
  1491. }
  1492. for(i = configs->begin(); i != configs->end(); ++i)
  1493. {
  1494. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1495. fout << "\t\t\t\t<FileConfiguration\n";
  1496. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1497. if(!fc.CompileFlags.empty())
  1498. {
  1499. fout << "\t\t\t\t\t<Tool\n"
  1500. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1501. << "\t\t\t\t\tAdditionalOptions=\""
  1502. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1503. }
  1504. std::string script = this->ConstructScript(command, i->c_str());
  1505. fout << "\t\t\t\t\t<Tool\n"
  1506. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1507. << "\t\t\t\t\tDescription=\""
  1508. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1509. << "\t\t\t\t\tCommandLine=\""
  1510. << this->EscapeForXML(script.c_str()) << "\"\n"
  1511. << "\t\t\t\t\tAdditionalDependencies=\"";
  1512. if(command.GetDepends().empty())
  1513. {
  1514. // There are no real dependencies. Produce an artificial one to
  1515. // make sure the rule runs reliably.
  1516. if(!cmSystemTools::FileExists(source))
  1517. {
  1518. std::ofstream depout(source);
  1519. depout << "Artificial dependency for a custom command.\n";
  1520. }
  1521. fout << this->ConvertToXMLOutputPath(source);
  1522. }
  1523. else
  1524. {
  1525. // Write out the dependencies for the rule.
  1526. for(std::vector<std::string>::const_iterator d =
  1527. command.GetDepends().begin();
  1528. d != command.GetDepends().end();
  1529. ++d)
  1530. {
  1531. // Get the real name of the dependency in case it is a CMake target.
  1532. std::string dep;
  1533. if(this->GetRealDependency(d->c_str(), i->c_str(), dep))
  1534. {
  1535. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1536. << ";";
  1537. }
  1538. }
  1539. }
  1540. fout << "\"\n";
  1541. fout << "\t\t\t\t\tOutputs=\"";
  1542. if(command.GetOutputs().empty())
  1543. {
  1544. fout << source << "_force";
  1545. }
  1546. else
  1547. {
  1548. // Write a rule for the output generated by this command.
  1549. const char* sep = "";
  1550. for(std::vector<std::string>::const_iterator o =
  1551. command.GetOutputs().begin();
  1552. o != command.GetOutputs().end();
  1553. ++o)
  1554. {
  1555. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1556. sep = ";";
  1557. }
  1558. }
  1559. fout << "\"/>\n";
  1560. fout << "\t\t\t\t</FileConfiguration>\n";
  1561. }
  1562. }
  1563. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1564. const char* group,
  1565. const char* )
  1566. {
  1567. fout << "\t\t<Filter\n"
  1568. << "\t\t\tName=\"" << group << "\"\n"
  1569. << "\t\t\tFilter=\"\">\n";
  1570. }
  1571. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1572. {
  1573. fout << "\t\t</Filter>\n";
  1574. }
  1575. // look for custom rules on a target and collect them together
  1576. void cmLocalVisualStudio7Generator
  1577. ::OutputTargetRules(std::ostream& fout,
  1578. const char* configName,
  1579. cmTarget &target,
  1580. const char * /*libName*/)
  1581. {
  1582. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1583. {
  1584. return;
  1585. }
  1586. EventWriter event(this, configName, fout);
  1587. // Add pre-build event.
  1588. const char* tool =
  1589. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1590. event.Start(tool);
  1591. event.Write(target.GetPreBuildCommands());
  1592. event.Finish();
  1593. // Add pre-link event.
  1594. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1595. event.Start(tool);
  1596. event.Write(target.GetPreLinkCommands());
  1597. cmsys::auto_ptr<cmCustomCommand> pcc(
  1598. this->MaybeCreateImplibDir(target, configName));
  1599. if(pcc.get())
  1600. {
  1601. event.Write(*pcc);
  1602. }
  1603. event.Finish();
  1604. // Add post-build event.
  1605. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1606. event.Start(tool);
  1607. event.Write(target.GetPostBuildCommands());
  1608. event.Finish();
  1609. }
  1610. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1611. cmTarget& target)
  1612. {
  1613. // if we have all the required Source code control tags
  1614. // then add that to the project
  1615. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1616. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1617. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1618. if(vsProvider && vsLocalpath && vsProjectname)
  1619. {
  1620. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1621. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1622. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1623. }
  1624. }
  1625. void
  1626. cmLocalVisualStudio7Generator
  1627. ::WriteProjectStartFortran(std::ostream& fout,
  1628. const char *libName,
  1629. cmTarget & target)
  1630. {
  1631. cmGlobalVisualStudio7Generator* gg =
  1632. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1633. // Compute the version of the Intel plugin to the VS IDE.
  1634. // If the key does not exist then use a default guess.
  1635. std::string intelVersion = "9.10";
  1636. std::string vskey = gg->GetRegistryBase();
  1637. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  1638. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  1639. cmSystemTools::KeyWOW64_32);
  1640. // Version 10.1 actually uses 9.10 in project files!
  1641. if(intelVersion == "10.1")
  1642. {
  1643. intelVersion = "9.10";
  1644. }
  1645. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1646. << "<VisualStudioProject\n"
  1647. << "\tProjectCreator=\"Intel Fortran\"\n"
  1648. << "\tVersion=\"" << intelVersion << "\"\n";
  1649. const char* keyword = target.GetProperty("VS_KEYWORD");
  1650. if(!keyword)
  1651. {
  1652. keyword = "Console Application";
  1653. }
  1654. const char* projectType = 0;
  1655. switch(target.GetType())
  1656. {
  1657. case cmTarget::STATIC_LIBRARY:
  1658. projectType = "typeStaticLibrary";
  1659. if(keyword)
  1660. {
  1661. keyword = "Static Library";
  1662. }
  1663. break;
  1664. case cmTarget::SHARED_LIBRARY:
  1665. case cmTarget::MODULE_LIBRARY:
  1666. projectType = "typeDynamicLibrary";
  1667. if(!keyword)
  1668. {
  1669. keyword = "Dll";
  1670. }
  1671. break;
  1672. case cmTarget::EXECUTABLE:
  1673. if(!keyword)
  1674. {
  1675. keyword = "Console Application";
  1676. }
  1677. projectType = 0;
  1678. break;
  1679. case cmTarget::UTILITY:
  1680. case cmTarget::GLOBAL_TARGET:
  1681. default:
  1682. break;
  1683. }
  1684. if(projectType)
  1685. {
  1686. fout << "\tProjectType=\"" << projectType << "\"\n";
  1687. }
  1688. this->WriteProjectSCC(fout, target);
  1689. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1690. << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
  1691. << "\t<Platforms>\n"
  1692. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1693. << "\t</Platforms>\n";
  1694. }
  1695. void
  1696. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1697. const char *libName,
  1698. cmTarget & target,
  1699. std::vector<cmSourceGroup> &)
  1700. {
  1701. if(this->FortranProject)
  1702. {
  1703. this->WriteProjectStartFortran(fout, libName, target);
  1704. return;
  1705. }
  1706. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1707. << "<VisualStudioProject\n"
  1708. << "\tProjectType=\"Visual C++\"\n";
  1709. if(this->Version == 71)
  1710. {
  1711. fout << "\tVersion=\"7.10\"\n";
  1712. }
  1713. else
  1714. {
  1715. fout << "\tVersion=\"" << this->Version << ".00\"\n";
  1716. }
  1717. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1718. if(!projLabel)
  1719. {
  1720. projLabel = libName;
  1721. }
  1722. const char* keyword = target.GetProperty("VS_KEYWORD");
  1723. if(!keyword)
  1724. {
  1725. keyword = "Win32Proj";
  1726. }
  1727. cmGlobalVisualStudio7Generator* gg =
  1728. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1729. fout << "\tName=\"" << projLabel << "\"\n";
  1730. if(this->Version >= 8)
  1731. {
  1732. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1733. }
  1734. this->WriteProjectSCC(fout, target);
  1735. fout << "\tKeyword=\"" << keyword << "\">\n"
  1736. << "\t<Platforms>\n"
  1737. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1738. << "\t</Platforms>\n";
  1739. }
  1740. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1741. {
  1742. fout << "\t<Globals>\n"
  1743. << "\t</Globals>\n"
  1744. << "</VisualStudioProject>\n";
  1745. }
  1746. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1747. {
  1748. std::string ret = s;
  1749. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1750. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1751. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1752. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1753. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1754. return ret;
  1755. }
  1756. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1757. {
  1758. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1759. }
  1760. std::string cmLocalVisualStudio7Generator
  1761. ::ConvertToXMLOutputPath(const char* path)
  1762. {
  1763. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1764. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1765. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1766. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1767. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1768. return ret;
  1769. }
  1770. std::string cmLocalVisualStudio7Generator
  1771. ::ConvertToXMLOutputPathSingle(const char* path)
  1772. {
  1773. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1774. cmSystemTools::ReplaceString(ret, "\"", "");
  1775. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1776. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1777. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1778. return ret;
  1779. }
  1780. // This class is used to parse an existing vs 7 project
  1781. // and extract the GUID
  1782. class cmVS7XMLParser : public cmXMLParser
  1783. {
  1784. public:
  1785. virtual void EndElement(const char* /* name */)
  1786. {
  1787. }
  1788. virtual void StartElement(const char* name, const char** atts)
  1789. {
  1790. // once the GUID is found do nothing
  1791. if(this->GUID.size())
  1792. {
  1793. return;
  1794. }
  1795. int i =0;
  1796. if(strcmp("VisualStudioProject", name) == 0)
  1797. {
  1798. while(atts[i])
  1799. {
  1800. if(strcmp(atts[i], "ProjectGUID") == 0)
  1801. {
  1802. if(atts[i+1])
  1803. {
  1804. this->GUID = atts[i+1];
  1805. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1806. }
  1807. else
  1808. {
  1809. this->GUID = "";
  1810. }
  1811. return;
  1812. }
  1813. ++i;
  1814. }
  1815. }
  1816. }
  1817. int InitializeParser()
  1818. {
  1819. int ret = cmXMLParser::InitializeParser();
  1820. if(ret == 0)
  1821. {
  1822. return ret;
  1823. }
  1824. // visual studio projects have a strange encoding, but it is
  1825. // really utf-8
  1826. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1827. return 1;
  1828. }
  1829. std::string GUID;
  1830. };
  1831. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1832. const char* name,
  1833. const char* path)
  1834. {
  1835. cmVS7XMLParser parser;
  1836. parser.ParseFile(path);
  1837. // if we can not find a GUID then create one
  1838. if(parser.GUID.size() == 0)
  1839. {
  1840. cmGlobalVisualStudio7Generator* gg =
  1841. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1842. gg->CreateGUID(name);
  1843. return;
  1844. }
  1845. std::string guidStoreName = name;
  1846. guidStoreName += "_GUID_CMAKE";
  1847. // save the GUID in the cache
  1848. this->GlobalGenerator->GetCMakeInstance()->
  1849. AddCacheEntry(guidStoreName.c_str(),
  1850. parser.GUID.c_str(),
  1851. "Stored GUID",
  1852. cmCacheManager::INTERNAL);
  1853. }
  1854. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1855. {
  1856. cmLocalGenerator::ConfigureFinalPass();
  1857. cmTargets &tgts = this->Makefile->GetTargets();
  1858. cmGlobalVisualStudio7Generator* gg =
  1859. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1860. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1861. {
  1862. const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
  1863. if(path)
  1864. {
  1865. this->ReadAndStoreExternalGUID(
  1866. l->second.GetName(), path);
  1867. }
  1868. else
  1869. {
  1870. gg->CreateGUID(l->first.c_str());
  1871. }
  1872. }
  1873. }
  1874. //----------------------------------------------------------------------------
  1875. std::string cmLocalVisualStudio7Generator
  1876. ::GetTargetDirectory(cmTarget const& target) const
  1877. {
  1878. std::string dir;
  1879. dir += target.GetName();
  1880. dir += ".dir";
  1881. return dir;
  1882. }
  1883. void cmLocalVisualStudio7Generator::
  1884. GetTargetObjectFileDirectories(cmTarget* target,
  1885. std::vector<std::string>&
  1886. dirs)
  1887. {
  1888. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1889. dir += "/";
  1890. dir += this->GetTargetDirectory(*target);
  1891. dir += "/";
  1892. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1893. dirs.push_back(dir);
  1894. }
  1895. //----------------------------------------------------------------------------
  1896. #include <windows.h>
  1897. static bool cmLVS6G_IsFAT(const char* dir)
  1898. {
  1899. if(dir[0] && dir[1] == ':')
  1900. {
  1901. char volRoot[4] = "_:/";
  1902. volRoot[0] = dir[0];
  1903. char fsName[16];
  1904. if(GetVolumeInformation(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  1905. strstr(fsName, "FAT") != 0)
  1906. {
  1907. return true;
  1908. }
  1909. }
  1910. return false;
  1911. }