cmLocalVisualStudio7Generator.cxx 77 KB

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