cmLocalVisualStudio7Generator.cxx 71 KB

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