cmLocalVisualStudio7Generator.cxx 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  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. {"DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  379. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  380. // Precompiled header and related options. Note that the
  381. // UsePrecompiledHeader entries are marked as "Continue" so that the
  382. // corresponding PrecompiledHeaderThrough entry can be found.
  383. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  384. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  385. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  386. cmVS7FlagTable::UserValueRequired},
  387. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  388. cmVS7FlagTable::UserValue},
  389. // The YX and Yu options are in a per-global-generator table because
  390. // their values differ based on the VS IDE version.
  391. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  392. cmVS7FlagTable::UserValueRequired},
  393. // boolean flags
  394. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
  395. {"BufferSecurityCheck", "GS-", "Turn off Buffer security check", "FALSE", 0},
  396. {"Detect64BitPortabilityProblems", "Wp64",
  397. "Detect 64-bit Portability Problems", "TRUE", 0},
  398. {"EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  399. "TRUE", 0},
  400. {"EnableFunctionLevelLinking", "Gy",
  401. "EnableFunctionLevelLinking", "TRUE", 0},
  402. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
  403. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
  404. {"ImproveFloatingPointConsistency", "Op",
  405. "ImproveFloatingPointConsistency", "TRUE", 0},
  406. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
  407. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
  408. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
  409. {"RuntimeTypeInfo", "GR",
  410. "Turn on Run time type information for c++", "TRUE", 0},
  411. {"RuntimeTypeInfo", "GR-",
  412. "Turn off Run time type information for c++", "FALSE", 0},
  413. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
  414. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
  415. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
  416. {0,0,0,0,0}
  417. };
  418. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  419. {
  420. // option flags (some flags map to the same option)
  421. {"GenerateManifest", "MANIFEST:NO",
  422. "disable manifest generation", "FALSE", 0},
  423. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
  424. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  425. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  426. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  427. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},
  428. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  429. "TRUE", 0},
  430. {"FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0},
  431. {"FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  432. "2", 0},
  433. {"EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs",
  434. "1", 0},
  435. {"EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0},
  436. {"OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0},
  437. {"OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0},
  438. {"TargetMachine", "MACHINE:I386", "Machine x86", "1", 0},
  439. {"TargetMachine", "MACHINE:X86", "Machine x86", "1", 0},
  440. {"TargetMachine", "MACHINE:X64", "Machine x64", "17", 0},
  441. {"ModuleDefinitionFile", "DEF:", "add an export def file", "",
  442. cmVS7FlagTable::UserValue},
  443. {"GenerateMapFile", "MAP", "enable generation of map file", "TRUE", 0},
  444. {0,0,0,0,0}
  445. };
  446. //----------------------------------------------------------------------------
  447. class cmLocalVisualStudio7GeneratorOptions
  448. {
  449. public:
  450. // Construct an options table for a given tool.
  451. enum Tool
  452. {
  453. Compiler,
  454. Linker,
  455. FortranCompiler
  456. };
  457. cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator* lg,
  458. int version,
  459. Tool tool,
  460. cmVS7FlagTable const* extraTable = 0);
  461. // Store options from command line flags.
  462. void Parse(const char* flags);
  463. // Fix the ExceptionHandling option to default to off.
  464. void FixExceptionHandlingDefault();
  465. // Store options for verbose builds.
  466. void SetVerboseMakefile(bool verbose);
  467. // Store definitions and flags.
  468. void AddDefine(const std::string& define);
  469. void AddDefines(const char* defines);
  470. void AddFlag(const char* flag, const char* value);
  471. // Check for specific options.
  472. bool UsingUnicode();
  473. bool IsDebug();
  474. // Write options to output.
  475. void OutputPreprocessorDefinitions(std::ostream& fout,
  476. const char* prefix,
  477. const char* suffix);
  478. void OutputFlagMap(std::ostream& fout, const char* indent);
  479. void OutputAdditionalOptions(std::ostream& fout,
  480. const char* prefix,
  481. const char* suffix);
  482. private:
  483. cmLocalVisualStudio7Generator* LocalGenerator;
  484. int Version;
  485. // create a map of xml tags to the values they should have in the output
  486. // for example, "BufferSecurityCheck" = "TRUE"
  487. // first fill this table with the values for the configuration
  488. // Debug, Release, etc,
  489. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  490. // and CMAKE_C_FLAGS
  491. // and overwrite or add new values to this map
  492. std::map<cmStdString, cmStdString> FlagMap;
  493. // Preprocessor definitions.
  494. std::vector<std::string> Defines;
  495. // Unrecognized flags that get no special handling.
  496. cmStdString FlagString;
  497. Tool CurrentTool;
  498. bool DoingDefine;
  499. cmVS7FlagTable const* FlagTable;
  500. cmVS7FlagTable const* ExtraFlagTable;
  501. void HandleFlag(const char* flag);
  502. bool CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  503. bool& flag_handled);
  504. };
  505. //----------------------------------------------------------------------------
  506. // Helper class to write build event <Tool .../> elements.
  507. class cmLocalVisualStudio7Generator::EventWriter
  508. {
  509. public:
  510. EventWriter(cmLocalVisualStudio7Generator* lg,
  511. const char* config, std::ostream& os):
  512. LG(lg), Config(config), Stream(os), First(true) {}
  513. void Start(const char* tool)
  514. {
  515. this->First = true;
  516. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  517. }
  518. void Finish()
  519. {
  520. this->Stream << (this->First? "" : "\"") << "/>\n";
  521. }
  522. void Write(std::vector<cmCustomCommand> const& ccs)
  523. {
  524. for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  525. ci != ccs.end(); ++ci)
  526. {
  527. this->Write(*ci);
  528. }
  529. }
  530. void Write(cmCustomCommand const& cc)
  531. {
  532. if(this->First)
  533. {
  534. const char* comment = cc.GetComment();
  535. if(comment && *comment)
  536. {
  537. this->Stream << "\nDescription=\""
  538. << this->LG->EscapeForXML(comment) << "\"";
  539. }
  540. this->Stream << "\nCommandLine=\"";
  541. this->First = false;
  542. }
  543. else
  544. {
  545. this->Stream << this->LG->EscapeForXML("\n");
  546. }
  547. std::string script =
  548. this->LG->ConstructScript(cc.GetCommandLines(),
  549. cc.GetWorkingDirectory(),
  550. this->Config,
  551. cc.GetEscapeOldStyle(),
  552. cc.GetEscapeAllowMakeVars());
  553. this->Stream << this->LG->EscapeForXML(script.c_str());
  554. }
  555. private:
  556. cmLocalVisualStudio7Generator* LG;
  557. const char* Config;
  558. std::ostream& Stream;
  559. bool First;
  560. };
  561. //----------------------------------------------------------------------------
  562. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  563. const char* configName,
  564. const char *libName,
  565. cmTarget &target)
  566. {
  567. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  568. if(!mfcFlag)
  569. {
  570. mfcFlag = "0";
  571. }
  572. fout << "\t\t<Configuration\n"
  573. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  574. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  575. // This is an internal type to Visual Studio, it seems that:
  576. // 4 == static library
  577. // 2 == dll
  578. // 1 == executable
  579. // 10 == utility
  580. const char* configType = "10";
  581. const char* projectType = 0;
  582. switch(target.GetType())
  583. {
  584. case cmTarget::STATIC_LIBRARY:
  585. projectType = "typeStaticLibrary";
  586. configType = "4";
  587. break;
  588. case cmTarget::SHARED_LIBRARY:
  589. case cmTarget::MODULE_LIBRARY:
  590. projectType = "typeDynamicLibrary";
  591. configType = "2";
  592. break;
  593. case cmTarget::EXECUTABLE:
  594. configType = "1";
  595. break;
  596. case cmTarget::UTILITY:
  597. case cmTarget::GLOBAL_TARGET:
  598. configType = "10";
  599. default:
  600. break;
  601. }
  602. if(this->FortranProject && projectType)
  603. {
  604. configType = projectType;
  605. }
  606. std::string flags;
  607. if(strcmp(configType, "10") != 0)
  608. {
  609. const char* linkLanguage =
  610. target.GetLinkerLanguage(this->GetGlobalGenerator());
  611. if(!linkLanguage)
  612. {
  613. cmSystemTools::Error
  614. ("CMake can not determine linker language for target:",
  615. target.GetName());
  616. return;
  617. }
  618. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0
  619. || strcmp(linkLanguage, "Fortran") == 0)
  620. {
  621. std::string baseFlagVar = "CMAKE_";
  622. baseFlagVar += linkLanguage;
  623. baseFlagVar += "_FLAGS";
  624. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  625. std::string flagVar = baseFlagVar + std::string("_") +
  626. cmSystemTools::UpperCase(configName);
  627. flags += " ";
  628. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  629. }
  630. // set the correct language
  631. if(strcmp(linkLanguage, "C") == 0)
  632. {
  633. flags += " /TC ";
  634. }
  635. if(strcmp(linkLanguage, "CXX") == 0)
  636. {
  637. flags += " /TP ";
  638. }
  639. }
  640. // Add the target-specific flags.
  641. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  642. {
  643. flags += " ";
  644. flags += targetFlags;
  645. }
  646. std::string configUpper = cmSystemTools::UpperCase(configName);
  647. std::string defPropName = "COMPILE_DEFINITIONS_";
  648. defPropName += configUpper;
  649. // Get preprocessor definitions for this directory.
  650. std::string defineFlags = this->Makefile->GetDefineFlags();
  651. Options::Tool t = Options::Compiler;
  652. if(this->FortranProject)
  653. {
  654. t = Options::FortranCompiler;
  655. }
  656. Options targetOptions(this, this->Version, t, this->ExtraFlagTable);
  657. targetOptions.FixExceptionHandlingDefault();
  658. targetOptions.Parse(flags.c_str());
  659. targetOptions.Parse(defineFlags.c_str());
  660. targetOptions.AddDefines
  661. (this->Makefile->GetProperty("COMPILE_DEFINITIONS"));
  662. targetOptions.AddDefines(target.GetProperty("COMPILE_DEFINITIONS"));
  663. targetOptions.AddDefines(this->Makefile->GetProperty(defPropName.c_str()));
  664. targetOptions.AddDefines(target.GetProperty(defPropName.c_str()));
  665. targetOptions.SetVerboseMakefile(
  666. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  667. // Add a definition for the configuration name.
  668. std::string configDefine = "CMAKE_INTDIR=\"";
  669. configDefine += configName;
  670. configDefine += "\"";
  671. targetOptions.AddDefine(configDefine);
  672. // Add the export symbol definition for shared library objects.
  673. if(const char* exportMacro = target.GetExportMacro())
  674. {
  675. targetOptions.AddDefine(exportMacro);
  676. }
  677. // The intermediate directory name consists of a directory for the
  678. // target and a subdirectory for the configuration name.
  679. std::string intermediateDir = this->GetTargetDirectory(target);
  680. intermediateDir += "/";
  681. intermediateDir += configName;
  682. fout << "\t\t\tIntermediateDirectory=\""
  683. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  684. << "\"\n"
  685. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  686. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  687. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  688. // If unicode is enabled change the character set to unicode, if not
  689. // then default to MBCS.
  690. if(targetOptions.UsingUnicode())
  691. {
  692. fout << "\t\t\tCharacterSet=\"1\">\n";
  693. }
  694. else
  695. {
  696. fout << "\t\t\tCharacterSet=\"2\">\n";
  697. }
  698. const char* tool = "VCCLCompilerTool";
  699. if(this->FortranProject)
  700. {
  701. tool = "VFFortranCompilerTool";
  702. }
  703. fout << "\t\t\t<Tool\n"
  704. << "\t\t\t\tName=\"" << tool << "\"\n";
  705. if(this->FortranProject)
  706. {
  707. const char* target_mod_dir =
  708. target.GetProperty("Fortran_MODULE_DIRECTORY");
  709. std::string modDir;
  710. if(target_mod_dir)
  711. {
  712. modDir = this->Convert(target_mod_dir,
  713. cmLocalGenerator::START_OUTPUT,
  714. cmLocalGenerator::UNCHANGED);
  715. }
  716. else
  717. {
  718. modDir = ".";
  719. }
  720. fout << "\t\t\t\tModulePath=\""
  721. << this->ConvertToXMLOutputPath(modDir.c_str())
  722. << "\\$(ConfigurationName)\"\n";
  723. }
  724. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  725. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  726. std::vector<std::string> includes;
  727. this->GetIncludeDirectories(includes);
  728. std::vector<std::string>::iterator i = includes.begin();
  729. for(;i != includes.end(); ++i)
  730. {
  731. // output the include path
  732. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  733. fout << ipath << ";";
  734. // if this is fortran then output the include with
  735. // a ConfigurationName on the end of it.
  736. if(this->FortranProject)
  737. {
  738. ipath = i->c_str();
  739. ipath += "/$(ConfigurationName)";
  740. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  741. fout << ipath << ";";
  742. }
  743. }
  744. fout << "\"\n";
  745. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  746. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  747. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  748. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  749. if(target.GetType() == cmTarget::EXECUTABLE ||
  750. target.GetType() == cmTarget::STATIC_LIBRARY ||
  751. target.GetType() == cmTarget::SHARED_LIBRARY ||
  752. target.GetType() == cmTarget::MODULE_LIBRARY)
  753. {
  754. // We need to specify a program database file name even for
  755. // non-debug configurations because VS still creates .idb files.
  756. fout << "\t\t\t\tProgramDataBaseFileName=\""
  757. << target.GetDirectory(configName) << "/"
  758. << target.GetPDBName(configName) << "\"\n";
  759. }
  760. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  761. tool = "VCCustomBuildTool";
  762. if(this->FortranProject)
  763. {
  764. tool = "VFCustomBuildTool";
  765. }
  766. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  767. tool = "VCResourceCompilerTool";
  768. if(this->FortranProject)
  769. {
  770. tool = "VFResourceCompilerTool";
  771. }
  772. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  773. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  774. for(i = includes.begin();i != includes.end(); ++i)
  775. {
  776. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  777. fout << ipath << ";";
  778. }
  779. // add the -D flags to the RC tool
  780. fout << "\"";
  781. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  782. fout << "/>\n";
  783. tool = "VCMIDLTool";
  784. if(this->FortranProject)
  785. {
  786. tool = "VFMIDLTool";
  787. }
  788. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  789. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  790. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  791. if( this->PlatformName == "x64" )
  792. {
  793. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  794. }
  795. else if( this->PlatformName == "ia64" )
  796. {
  797. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  798. }
  799. else
  800. {
  801. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  802. }
  803. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  804. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  805. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  806. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  807. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  808. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  809. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  810. // end of <Tool Name=VCMIDLTool
  811. // Check if we need the FAT32 workaround.
  812. if ( this->Version >= 8 )
  813. {
  814. // Check the filesystem type where the target will be written.
  815. if(cmLVS6G_IsFAT(target.GetDirectory(configName).c_str()))
  816. {
  817. // Add a flag telling the manifest tool to use a workaround
  818. // for FAT32 file systems, which can cause an empty manifest
  819. // to be embedded into the resulting executable. See CMake
  820. // bug #2617.
  821. const char* tool = "VCManifestTool";
  822. if(this->FortranProject)
  823. {
  824. tool = "VFManifestTool";
  825. }
  826. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  827. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  828. << "\t\t\t/>\n";
  829. }
  830. }
  831. this->OutputTargetRules(fout, configName, target, libName);
  832. this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug());
  833. fout << "\t\t</Configuration>\n";
  834. }
  835. //----------------------------------------------------------------------------
  836. std::string
  837. cmLocalVisualStudio7Generator
  838. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  839. {
  840. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  841. std::string extraLinkOptionsBuildTypeDef =
  842. rootLinkerFlags + "_" + configTypeUpper;
  843. std::string extraLinkOptionsBuildType =
  844. this->Makefile->GetRequiredDefinition
  845. (extraLinkOptionsBuildTypeDef.c_str());
  846. return extraLinkOptionsBuildType;
  847. }
  848. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  849. const char* configName,
  850. cmTarget &target,
  851. bool isDebug)
  852. {
  853. std::string temp;
  854. std::string extraLinkOptions;
  855. if(target.GetType() == cmTarget::EXECUTABLE)
  856. {
  857. extraLinkOptions =
  858. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  859. + std::string(" ")
  860. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  861. }
  862. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  863. {
  864. extraLinkOptions =
  865. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  866. + std::string(" ")
  867. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  868. }
  869. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  870. {
  871. extraLinkOptions =
  872. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  873. + std::string(" ")
  874. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  875. }
  876. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  877. if(targetLinkFlags)
  878. {
  879. extraLinkOptions += " ";
  880. extraLinkOptions += targetLinkFlags;
  881. }
  882. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  883. std::string linkFlagsConfig = "LINK_FLAGS_";
  884. linkFlagsConfig += configTypeUpper;
  885. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  886. if(targetLinkFlags)
  887. {
  888. extraLinkOptions += " ";
  889. extraLinkOptions += targetLinkFlags;
  890. }
  891. Options linkOptions(this, this->Version, Options::Linker);
  892. linkOptions.Parse(extraLinkOptions.c_str());
  893. switch(target.GetType())
  894. {
  895. case cmTarget::STATIC_LIBRARY:
  896. {
  897. std::string targetNameFull = target.GetFullName(configName);
  898. std::string libpath = target.GetDirectory(configName);
  899. libpath += "/";
  900. libpath += targetNameFull;
  901. const char* tool = "VCLibrarianTool";
  902. if(this->FortranProject)
  903. {
  904. tool = "VFLibrarianTool";
  905. }
  906. fout << "\t\t\t<Tool\n"
  907. << "\t\t\t\tName=\"" << tool << "\"\n";
  908. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  909. {
  910. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  911. }
  912. fout << "\t\t\t\tOutputFile=\""
  913. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  914. break;
  915. }
  916. case cmTarget::SHARED_LIBRARY:
  917. case cmTarget::MODULE_LIBRARY:
  918. {
  919. std::string targetName;
  920. std::string targetNameSO;
  921. std::string targetNameFull;
  922. std::string targetNameImport;
  923. std::string targetNamePDB;
  924. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  925. targetNameImport, targetNamePDB, configName);
  926. // Compute the link library and directory information.
  927. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  928. if(!pcli)
  929. {
  930. return;
  931. }
  932. cmComputeLinkInformation& cli = *pcli;
  933. const char* linkLanguage = cli.GetLinkLanguage();
  934. // Compute the variable name to lookup standard libraries for this
  935. // language.
  936. std::string standardLibsVar = "CMAKE_";
  937. standardLibsVar += linkLanguage;
  938. standardLibsVar += "_STANDARD_LIBRARIES";
  939. const char* tool = "VCLinkerTool";
  940. if(this->FortranProject)
  941. {
  942. tool = "VFLinkerTool";
  943. }
  944. fout << "\t\t\t<Tool\n"
  945. << "\t\t\t\tName=\"" << tool << "\"\n";
  946. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  947. // Use the NOINHERIT macro to avoid getting VS project default
  948. // libraries which may be set by the user to something bad.
  949. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  950. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  951. << " ";
  952. this->Internal->OutputLibraries(fout, cli.GetItems());
  953. fout << "\"\n";
  954. temp = target.GetDirectory(configName);
  955. temp += "/";
  956. temp += targetNameFull;
  957. fout << "\t\t\t\tOutputFile=\""
  958. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  959. this->WriteTargetVersionAttribute(fout, target);
  960. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  961. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  962. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  963. fout << "\"\n";
  964. this->OutputModuleDefinitionFile(fout, target);
  965. temp = target.GetDirectory(configName);
  966. temp += "/";
  967. temp += targetNamePDB;
  968. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  969. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  970. if(isDebug)
  971. {
  972. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  973. }
  974. std::string stackVar = "CMAKE_";
  975. stackVar += linkLanguage;
  976. stackVar += "_STACK_SIZE";
  977. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  978. if(stackVal)
  979. {
  980. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  981. }
  982. temp = target.GetDirectory(configName, true);
  983. temp += "/";
  984. temp += targetNameImport;
  985. fout << "\t\t\t\tImportLibrary=\""
  986. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  987. }
  988. break;
  989. case cmTarget::EXECUTABLE:
  990. {
  991. std::string targetName;
  992. std::string targetNameFull;
  993. std::string targetNameImport;
  994. std::string targetNamePDB;
  995. target.GetExecutableNames(targetName, targetNameFull,
  996. targetNameImport, targetNamePDB, configName);
  997. // Compute the link library and directory information.
  998. cmComputeLinkInformation* pcli = target.GetLinkInformation(configName);
  999. if(!pcli)
  1000. {
  1001. return;
  1002. }
  1003. cmComputeLinkInformation& cli = *pcli;
  1004. const char* linkLanguage = cli.GetLinkLanguage();
  1005. // Compute the variable name to lookup standard libraries for this
  1006. // language.
  1007. std::string standardLibsVar = "CMAKE_";
  1008. standardLibsVar += linkLanguage;
  1009. standardLibsVar += "_STANDARD_LIBRARIES";
  1010. const char* tool = "VCLinkerTool";
  1011. if(this->FortranProject)
  1012. {
  1013. tool = "VFLinkerTool";
  1014. }
  1015. fout << "\t\t\t<Tool\n"
  1016. << "\t\t\t\tName=\"" << tool << "\"\n";
  1017. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  1018. // Use the NOINHERIT macro to avoid getting VS project default
  1019. // libraries which may be set by the user to something bad.
  1020. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1021. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  1022. << " ";
  1023. this->Internal->OutputLibraries(fout, cli.GetItems());
  1024. fout << "\"\n";
  1025. temp = target.GetDirectory(configName);
  1026. temp += "/";
  1027. temp += targetNameFull;
  1028. fout << "\t\t\t\tOutputFile=\""
  1029. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1030. this->WriteTargetVersionAttribute(fout, target);
  1031. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1032. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1033. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1034. fout << "\"\n";
  1035. fout << "\t\t\t\tProgramDataBaseFile=\""
  1036. << target.GetDirectory(configName) << "/" << targetNamePDB
  1037. << "\"\n";
  1038. if(isDebug)
  1039. {
  1040. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  1041. }
  1042. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  1043. {
  1044. fout << "\t\t\t\tSubSystem=\"2\"\n";
  1045. }
  1046. else
  1047. {
  1048. fout << "\t\t\t\tSubSystem=\"1\"\n";
  1049. }
  1050. std::string stackVar = "CMAKE_";
  1051. stackVar += linkLanguage;
  1052. stackVar += "_STACK_SIZE";
  1053. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1054. if(stackVal)
  1055. {
  1056. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1057. }
  1058. temp = target.GetDirectory(configName, true);
  1059. temp += "/";
  1060. temp += targetNameImport;
  1061. fout << "\t\t\t\tImportLibrary=\""
  1062. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1063. break;
  1064. }
  1065. case cmTarget::UTILITY:
  1066. case cmTarget::GLOBAL_TARGET:
  1067. break;
  1068. }
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. void
  1072. cmLocalVisualStudio7Generator
  1073. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  1074. {
  1075. int major;
  1076. int minor;
  1077. target.GetTargetVersion(major, minor);
  1078. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1079. }
  1080. void cmLocalVisualStudio7Generator
  1081. ::OutputModuleDefinitionFile(std::ostream& fout,
  1082. cmTarget &target)
  1083. {
  1084. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  1085. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1086. i != classes.end(); i++)
  1087. {
  1088. cmSourceFile* sf = *i;
  1089. if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
  1090. {
  1091. fout << "\t\t\t\tModuleDefinitionFile=\""
  1092. << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
  1093. << "\"\n";
  1094. return;
  1095. }
  1096. }
  1097. }
  1098. //----------------------------------------------------------------------------
  1099. void
  1100. cmLocalVisualStudio7GeneratorInternals
  1101. ::OutputLibraries(std::ostream& fout, ItemVector const& libs)
  1102. {
  1103. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1104. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  1105. {
  1106. if(l->IsPath)
  1107. {
  1108. std::string rel = lg->Convert(l->Value.c_str(),
  1109. cmLocalGenerator::START_OUTPUT,
  1110. cmLocalGenerator::UNCHANGED);
  1111. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1112. }
  1113. else
  1114. {
  1115. fout << l->Value << " ";
  1116. }
  1117. }
  1118. }
  1119. //----------------------------------------------------------------------------
  1120. void
  1121. cmLocalVisualStudio7Generator
  1122. ::OutputLibraryDirectories(std::ostream& fout,
  1123. std::vector<std::string> const& dirs)
  1124. {
  1125. const char* comma = "";
  1126. for(std::vector<std::string>::const_iterator d = dirs.begin();
  1127. d != dirs.end(); ++d)
  1128. {
  1129. // Remove any trailing slash and skip empty paths.
  1130. std::string dir = *d;
  1131. if(dir[dir.size()-1] == '/')
  1132. {
  1133. dir = dir.substr(0, dir.size()-1);
  1134. }
  1135. if(dir.empty())
  1136. {
  1137. continue;
  1138. }
  1139. // Switch to a relative path specification if it is shorter.
  1140. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  1141. {
  1142. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  1143. if(rel.size() < dir.size())
  1144. {
  1145. dir = rel;
  1146. }
  1147. }
  1148. // First search a configuration-specific subdirectory and then the
  1149. // original directory.
  1150. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  1151. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1152. comma = ",";
  1153. }
  1154. }
  1155. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1156. const char *libName,
  1157. cmTarget &target)
  1158. {
  1159. // get the configurations
  1160. std::vector<std::string> *configs =
  1161. static_cast<cmGlobalVisualStudio7Generator *>
  1162. (this->GlobalGenerator)->GetConfigurations();
  1163. // We may be modifying the source groups temporarily, so make a copy.
  1164. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1165. // get the classes from the source lists then add them to the groups
  1166. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  1167. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  1168. i != classes.end(); i++)
  1169. {
  1170. // Add the file to the list of sources.
  1171. std::string source = (*i)->GetFullPath();
  1172. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  1173. {
  1174. this->ModuleDefinitionFile = (*i)->GetFullPath();
  1175. }
  1176. cmSourceGroup& sourceGroup =
  1177. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1178. sourceGroup.AssignSource(*i);
  1179. }
  1180. // Compute which sources need unique object computation.
  1181. this->ComputeObjectNameRequirements(sourceGroups);
  1182. // open the project
  1183. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1184. // write the configuration information
  1185. this->WriteConfigurations(fout, libName, target);
  1186. fout << "\t<Files>\n";
  1187. // Loop through every source group.
  1188. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  1189. {
  1190. cmSourceGroup sg = sourceGroups[i];
  1191. this->WriteGroup(&sg, target, fout, libName, configs);
  1192. }
  1193. //}
  1194. fout << "\t</Files>\n";
  1195. // Write the VCProj file's footer.
  1196. this->WriteVCProjFooter(fout);
  1197. }
  1198. struct cmLVS7GFileConfig
  1199. {
  1200. std::string ObjectName;
  1201. std::string CompileFlags;
  1202. std::string CompileDefs;
  1203. std::string CompileDefsConfig;
  1204. std::string AdditionalDeps;
  1205. bool ExcludedFromBuild;
  1206. };
  1207. class cmLocalVisualStudio7GeneratorFCInfo
  1208. {
  1209. public:
  1210. cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1211. cmTarget& target,
  1212. cmSourceFile const& sf,
  1213. std::vector<std::string>* configs,
  1214. std::string const& dir_max);
  1215. std::map<cmStdString, cmLVS7GFileConfig> FileConfigMap;
  1216. };
  1217. cmLocalVisualStudio7GeneratorFCInfo
  1218. ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg,
  1219. cmTarget& target,
  1220. cmSourceFile const& sf,
  1221. std::vector<std::string>* configs,
  1222. std::string const& dir_max)
  1223. {
  1224. std::string objectName;
  1225. if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end())
  1226. {
  1227. objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max);
  1228. }
  1229. // Compute per-source, per-config information.
  1230. for(std::vector<std::string>::iterator i = configs->begin();
  1231. i != configs->end(); ++i)
  1232. {
  1233. std::string configUpper = cmSystemTools::UpperCase(*i);
  1234. cmLVS7GFileConfig fc;
  1235. bool needfc = false;
  1236. if(!objectName.empty())
  1237. {
  1238. fc.ObjectName = objectName;
  1239. needfc = true;
  1240. }
  1241. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1242. {
  1243. fc.CompileFlags = cflags;
  1244. needfc = true;
  1245. }
  1246. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1247. {
  1248. fc.CompileDefs = cdefs;
  1249. needfc = true;
  1250. }
  1251. std::string defPropName = "COMPILE_DEFINITIONS_";
  1252. defPropName += configUpper;
  1253. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1254. {
  1255. fc.CompileDefsConfig = ccdefs;
  1256. needfc = true;
  1257. }
  1258. // Check for extra object-file dependencies.
  1259. if(const char* deps = sf.GetProperty("OBJECT_DEPENDS"))
  1260. {
  1261. std::vector<std::string> depends;
  1262. cmSystemTools::ExpandListArgument(deps, depends);
  1263. const char* sep = "";
  1264. for(std::vector<std::string>::iterator j = depends.begin();
  1265. j != depends.end(); ++j)
  1266. {
  1267. fc.AdditionalDeps += sep;
  1268. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1269. sep = ";";
  1270. needfc = true;
  1271. }
  1272. }
  1273. const char* lang =
  1274. lg->GlobalGenerator->GetLanguageFromExtension
  1275. (sf.GetExtension().c_str());
  1276. const char* sourceLang = lg->GetSourceFileLanguage(sf);
  1277. const char* linkLanguage = target.GetLinkerLanguage
  1278. (lg->GetGlobalGenerator());
  1279. bool needForceLang = false;
  1280. // source file does not match its extension language
  1281. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  1282. {
  1283. needForceLang = true;
  1284. lang = sourceLang;
  1285. }
  1286. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1287. // the project file
  1288. fc.ExcludedFromBuild =
  1289. (sf.GetPropertyAsBool("HEADER_FILE_ONLY"));
  1290. if(fc.ExcludedFromBuild)
  1291. {
  1292. needfc = true;
  1293. }
  1294. // if the source file does not match the linker language
  1295. // then force c or c++
  1296. if(needForceLang || (linkLanguage && lang
  1297. && strcmp(lang, linkLanguage) != 0))
  1298. {
  1299. if(strcmp(lang, "CXX") == 0)
  1300. {
  1301. // force a C++ file type
  1302. fc.CompileFlags += " /TP ";
  1303. needfc = true;
  1304. }
  1305. else if(strcmp(lang, "C") == 0)
  1306. {
  1307. // force to c
  1308. fc.CompileFlags += " /TC ";
  1309. needfc = true;
  1310. }
  1311. }
  1312. if(needfc)
  1313. {
  1314. this->FileConfigMap[*i] = fc;
  1315. }
  1316. }
  1317. }
  1318. void cmLocalVisualStudio7Generator
  1319. ::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
  1320. std::ostream &fout, const char *libName,
  1321. std::vector<std::string> *configs)
  1322. {
  1323. const std::vector<const cmSourceFile *> &sourceFiles =
  1324. sg->GetSourceFiles();
  1325. // If the group is empty, don't write it at all.
  1326. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  1327. {
  1328. return;
  1329. }
  1330. // If the group has a name, write the header.
  1331. std::string name = sg->GetName();
  1332. if(name != "")
  1333. {
  1334. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1335. }
  1336. // Compute the maximum length configuration name.
  1337. std::string config_max;
  1338. for(std::vector<std::string>::iterator i = configs->begin();
  1339. i != configs->end(); ++i)
  1340. {
  1341. if(i->size() > config_max.size())
  1342. {
  1343. config_max = *i;
  1344. }
  1345. }
  1346. // Compute the maximum length full path to the intermediate
  1347. // files directory for any configuration. This is used to construct
  1348. // object file names that do not produce paths that are too long.
  1349. std::string dir_max;
  1350. dir_max += this->Makefile->GetCurrentOutputDirectory();
  1351. dir_max += "/";
  1352. dir_max += this->GetTargetDirectory(target);
  1353. dir_max += "/";
  1354. dir_max += config_max;
  1355. dir_max += "/";
  1356. // Loop through each source in the source group.
  1357. std::string objectName;
  1358. for(std::vector<const cmSourceFile *>::const_iterator sf =
  1359. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  1360. {
  1361. std::string source = (*sf)->GetFullPath();
  1362. FCInfo fcinfo(this, target, *(*sf), configs, dir_max);
  1363. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1364. target.GetType() == cmTarget::GLOBAL_TARGET )
  1365. {
  1366. fout << "\t\t\t<File\n";
  1367. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1368. // Tell MS-Dev what the source is. If the compiler knows how to
  1369. // build it, then it will.
  1370. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1371. if(cmCustomCommand const* command = (*sf)->GetCustomCommand())
  1372. {
  1373. this->WriteCustomRule(fout, source.c_str(), *command, fcinfo);
  1374. }
  1375. else if(!fcinfo.FileConfigMap.empty())
  1376. {
  1377. const char* aCompilerTool = "VCCLCompilerTool";
  1378. std::string ext = (*sf)->GetExtension();
  1379. ext = cmSystemTools::LowerCase(ext);
  1380. if(ext == "idl")
  1381. {
  1382. aCompilerTool = "VCMIDLTool";
  1383. if(this->FortranProject)
  1384. {
  1385. aCompilerTool = "VFMIDLTool";
  1386. }
  1387. }
  1388. if(ext == "rc")
  1389. {
  1390. aCompilerTool = "VCResourceCompilerTool";
  1391. if(this->FortranProject)
  1392. {
  1393. aCompilerTool = "VFResourceCompilerTool";
  1394. }
  1395. }
  1396. if(ext == "def")
  1397. {
  1398. aCompilerTool = "VCCustomBuildTool";
  1399. if(this->FortranProject)
  1400. {
  1401. aCompilerTool = "VFCustomBuildTool";
  1402. }
  1403. }
  1404. for(std::map<cmStdString, cmLVS7GFileConfig>::const_iterator
  1405. fci = fcinfo.FileConfigMap.begin();
  1406. fci != fcinfo.FileConfigMap.end(); ++fci)
  1407. {
  1408. cmLVS7GFileConfig const& fc = fci->second;
  1409. fout << "\t\t\t\t<FileConfiguration\n"
  1410. << "\t\t\t\t\tName=\"" << fci->first
  1411. << "|" << this->PlatformName << "\"";
  1412. if(fc.ExcludedFromBuild)
  1413. {
  1414. fout << " ExcludedFromBuild=\"true\"";
  1415. }
  1416. fout << ">\n";
  1417. fout << "\t\t\t\t\t<Tool\n"
  1418. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1419. if(!fc.CompileFlags.empty() ||
  1420. !fc.CompileDefs.empty() ||
  1421. !fc.CompileDefsConfig.empty())
  1422. {
  1423. Options fileOptions(this, this->Version, Options::Compiler,
  1424. this->ExtraFlagTable);
  1425. fileOptions.Parse(fc.CompileFlags.c_str());
  1426. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1427. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1428. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1429. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1430. fileOptions.OutputPreprocessorDefinitions(fout,
  1431. "\t\t\t\t\t", "\n");
  1432. }
  1433. if(!fc.AdditionalDeps.empty())
  1434. {
  1435. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1436. << fc.AdditionalDeps.c_str() << "\"\n";
  1437. }
  1438. if(!fc.ObjectName.empty())
  1439. {
  1440. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1441. << fc.ObjectName.c_str() << "\"\n";
  1442. }
  1443. fout << "\t\t\t\t\t/>\n"
  1444. << "\t\t\t\t</FileConfiguration>\n";
  1445. }
  1446. }
  1447. fout << "\t\t\t</File>\n";
  1448. }
  1449. }
  1450. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1451. for(unsigned int i=0;i<children.size();++i)
  1452. {
  1453. this->WriteGroup(&children[i], target, fout, libName, configs);
  1454. }
  1455. // If the group has a name, write the footer.
  1456. if(name != "")
  1457. {
  1458. this->WriteVCProjEndGroup(fout);
  1459. }
  1460. }
  1461. void cmLocalVisualStudio7Generator::
  1462. WriteCustomRule(std::ostream& fout,
  1463. const char* source,
  1464. const cmCustomCommand& command,
  1465. FCInfo& fcinfo)
  1466. {
  1467. std::string comment = this->ConstructComment(command);
  1468. // Write the rule for each configuration.
  1469. std::vector<std::string>::iterator i;
  1470. std::vector<std::string> *configs =
  1471. static_cast<cmGlobalVisualStudio7Generator *>
  1472. (this->GlobalGenerator)->GetConfigurations();
  1473. const char* compileTool = "VCCLCompilerTool";
  1474. if(this->FortranProject)
  1475. {
  1476. compileTool = "VFCLCompilerTool";
  1477. }
  1478. const char* customTool = "VCCustomBuildTool";
  1479. if(this->FortranProject)
  1480. {
  1481. customTool = "VFCustomBuildTool";
  1482. }
  1483. for(i = configs->begin(); i != configs->end(); ++i)
  1484. {
  1485. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1486. fout << "\t\t\t\t<FileConfiguration\n";
  1487. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1488. if(!fc.CompileFlags.empty())
  1489. {
  1490. fout << "\t\t\t\t\t<Tool\n"
  1491. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1492. << "\t\t\t\t\tAdditionalOptions=\""
  1493. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1494. }
  1495. std::string script =
  1496. this->ConstructScript(command.GetCommandLines(),
  1497. command.GetWorkingDirectory(),
  1498. i->c_str(),
  1499. command.GetEscapeOldStyle(),
  1500. command.GetEscapeAllowMakeVars());
  1501. fout << "\t\t\t\t\t<Tool\n"
  1502. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1503. << "\t\t\t\t\tDescription=\""
  1504. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1505. << "\t\t\t\t\tCommandLine=\""
  1506. << this->EscapeForXML(script.c_str()) << "\"\n"
  1507. << "\t\t\t\t\tAdditionalDependencies=\"";
  1508. if(command.GetDepends().empty())
  1509. {
  1510. // There are no real dependencies. Produce an artificial one to
  1511. // make sure the rule runs reliably.
  1512. if(!cmSystemTools::FileExists(source))
  1513. {
  1514. std::ofstream depout(source);
  1515. depout << "Artificial dependency for a custom command.\n";
  1516. }
  1517. fout << this->ConvertToXMLOutputPath(source);
  1518. }
  1519. else
  1520. {
  1521. // Write out the dependencies for the rule.
  1522. for(std::vector<std::string>::const_iterator d =
  1523. command.GetDepends().begin();
  1524. d != command.GetDepends().end();
  1525. ++d)
  1526. {
  1527. // Get the real name of the dependency in case it is a CMake target.
  1528. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1529. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1530. << ";";
  1531. }
  1532. }
  1533. fout << "\"\n";
  1534. fout << "\t\t\t\t\tOutputs=\"";
  1535. if(command.GetOutputs().empty())
  1536. {
  1537. fout << source << "_force";
  1538. }
  1539. else
  1540. {
  1541. // Write a rule for the output generated by this command.
  1542. const char* sep = "";
  1543. for(std::vector<std::string>::const_iterator o =
  1544. command.GetOutputs().begin();
  1545. o != command.GetOutputs().end();
  1546. ++o)
  1547. {
  1548. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1549. sep = ";";
  1550. }
  1551. }
  1552. fout << "\"/>\n";
  1553. fout << "\t\t\t\t</FileConfiguration>\n";
  1554. }
  1555. }
  1556. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1557. const char* group,
  1558. const char* )
  1559. {
  1560. fout << "\t\t<Filter\n"
  1561. << "\t\t\tName=\"" << group << "\"\n"
  1562. << "\t\t\tFilter=\"\">\n";
  1563. }
  1564. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1565. {
  1566. fout << "\t\t</Filter>\n";
  1567. }
  1568. void cmLocalVisualStudio7Generator::MaybeCreateImplibDir(cmTarget& target,
  1569. const char* config,
  1570. EventWriter& event)
  1571. {
  1572. // If an executable exports symbols then VS wants to create an
  1573. // import library but forgets to create the output directory.
  1574. if(target.GetType() != cmTarget::EXECUTABLE) { return; }
  1575. std::string outDir = target.GetDirectory(config, false);
  1576. std::string impDir = target.GetDirectory(config, true);
  1577. if(impDir == outDir) { return; }
  1578. // Add a pre-build event to create the directory.
  1579. cmCustomCommandLine command;
  1580. command.push_back(this->Makefile->GetRequiredDefinition("CMAKE_COMMAND"));
  1581. command.push_back("-E");
  1582. command.push_back("make_directory");
  1583. command.push_back(impDir);
  1584. std::vector<std::string> no_output;
  1585. std::vector<std::string> no_depends;
  1586. cmCustomCommandLines commands;
  1587. commands.push_back(command);
  1588. cmCustomCommand cc(no_output, no_depends, commands, 0, 0);
  1589. cc.SetEscapeOldStyle(false);
  1590. cc.SetEscapeAllowMakeVars(true);
  1591. event.Write(cc);
  1592. }
  1593. // look for custom rules on a target and collect them together
  1594. void cmLocalVisualStudio7Generator
  1595. ::OutputTargetRules(std::ostream& fout,
  1596. const char* configName,
  1597. cmTarget &target,
  1598. const char * /*libName*/)
  1599. {
  1600. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1601. {
  1602. return;
  1603. }
  1604. EventWriter event(this, configName, fout);
  1605. // Add pre-build event.
  1606. const char* tool =
  1607. this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
  1608. event.Start(tool);
  1609. event.Write(target.GetPreBuildCommands());
  1610. this->MaybeCreateImplibDir(target, configName, event);
  1611. event.Finish();
  1612. // Add pre-link event.
  1613. tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
  1614. event.Start(tool);
  1615. event.Write(target.GetPreLinkCommands());
  1616. event.Finish();
  1617. // Add post-build event.
  1618. tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
  1619. event.Start(tool);
  1620. event.Write(target.GetPostBuildCommands());
  1621. event.Finish();
  1622. }
  1623. void
  1624. cmLocalVisualStudio7Generator
  1625. ::WriteProjectStartFortran(std::ostream& fout,
  1626. const char *libName,
  1627. cmTarget & target)
  1628. {
  1629. cmGlobalVisualStudio7Generator* gg =
  1630. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1631. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1632. << "<VisualStudioProject\n"
  1633. << "\tProjectCreator=\"Intel Fortran\"\n"
  1634. << "\tVersion=\"9.10\"\n";
  1635. const char* keyword = target.GetProperty("VS_KEYWORD");
  1636. if(!keyword)
  1637. {
  1638. keyword = "Console Application";
  1639. }
  1640. const char* projectType = 0;
  1641. switch(target.GetType())
  1642. {
  1643. case cmTarget::STATIC_LIBRARY:
  1644. projectType = "typeStaticLibrary";
  1645. if(keyword)
  1646. {
  1647. keyword = "Static Library";
  1648. }
  1649. break;
  1650. case cmTarget::SHARED_LIBRARY:
  1651. case cmTarget::MODULE_LIBRARY:
  1652. projectType = "typeDynamicLibrary";
  1653. if(!keyword)
  1654. {
  1655. keyword = "Dll";
  1656. }
  1657. break;
  1658. case cmTarget::EXECUTABLE:
  1659. if(!keyword)
  1660. {
  1661. keyword = "Console Application";
  1662. }
  1663. projectType = 0;
  1664. break;
  1665. case cmTarget::UTILITY:
  1666. case cmTarget::GLOBAL_TARGET:
  1667. default:
  1668. break;
  1669. }
  1670. if(projectType)
  1671. {
  1672. fout << "\tProjectType=\"" << projectType << "\"\n";
  1673. }
  1674. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1675. << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
  1676. << "\t<Platforms>\n"
  1677. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1678. << "\t</Platforms>\n";
  1679. }
  1680. void
  1681. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1682. const char *libName,
  1683. cmTarget & target,
  1684. std::vector<cmSourceGroup> &)
  1685. {
  1686. if(this->FortranProject)
  1687. {
  1688. this->WriteProjectStartFortran(fout, libName, target);
  1689. return;
  1690. }
  1691. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1692. << "<VisualStudioProject\n"
  1693. << "\tProjectType=\"Visual C++\"\n";
  1694. if(this->Version == 71)
  1695. {
  1696. fout << "\tVersion=\"7.10\"\n";
  1697. }
  1698. else
  1699. {
  1700. fout << "\tVersion=\"" << this->Version << ".00\"\n";
  1701. }
  1702. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1703. if(!projLabel)
  1704. {
  1705. projLabel = libName;
  1706. }
  1707. const char* keyword = target.GetProperty("VS_KEYWORD");
  1708. if(!keyword)
  1709. {
  1710. keyword = "Win32Proj";
  1711. }
  1712. const char* vsProjectname = target.GetProperty("VS_SCC_PROJECTNAME");
  1713. const char* vsLocalpath = target.GetProperty("VS_SCC_LOCALPATH");
  1714. const char* vsProvider = target.GetProperty("VS_SCC_PROVIDER");
  1715. cmGlobalVisualStudio7Generator* gg =
  1716. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1717. fout << "\tName=\"" << projLabel << "\"\n";
  1718. if(this->Version >= 8)
  1719. {
  1720. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1721. }
  1722. // if we have all the required Source code control tags
  1723. // then add that to the project
  1724. if(vsProvider && vsLocalpath && vsProjectname)
  1725. {
  1726. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1727. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1728. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1729. }
  1730. fout << "\tKeyword=\"" << keyword << "\">\n"
  1731. << "\t<Platforms>\n"
  1732. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1733. << "\t</Platforms>\n";
  1734. }
  1735. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1736. {
  1737. fout << "\t<Globals>\n"
  1738. << "\t</Globals>\n"
  1739. << "</VisualStudioProject>\n";
  1740. }
  1741. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1742. {
  1743. std::string ret = s;
  1744. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1745. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1746. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1747. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1748. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1749. return ret;
  1750. }
  1751. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1752. {
  1753. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1754. }
  1755. std::string cmLocalVisualStudio7Generator
  1756. ::ConvertToXMLOutputPath(const char* path)
  1757. {
  1758. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1759. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1760. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1761. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1762. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1763. return ret;
  1764. }
  1765. std::string cmLocalVisualStudio7Generator
  1766. ::ConvertToXMLOutputPathSingle(const char* path)
  1767. {
  1768. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1769. cmSystemTools::ReplaceString(ret, "\"", "");
  1770. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1771. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1772. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1773. return ret;
  1774. }
  1775. // This class is used to parse an existing vs 7 project
  1776. // and extract the GUID
  1777. class cmVS7XMLParser : public cmXMLParser
  1778. {
  1779. public:
  1780. virtual void EndElement(const char* /* name */)
  1781. {
  1782. }
  1783. virtual void StartElement(const char* name, const char** atts)
  1784. {
  1785. // once the GUID is found do nothing
  1786. if(this->GUID.size())
  1787. {
  1788. return;
  1789. }
  1790. int i =0;
  1791. if(strcmp("VisualStudioProject", name) == 0)
  1792. {
  1793. while(atts[i])
  1794. {
  1795. if(strcmp(atts[i], "ProjectGUID") == 0)
  1796. {
  1797. if(atts[i+1])
  1798. {
  1799. this->GUID = atts[i+1];
  1800. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1801. }
  1802. else
  1803. {
  1804. this->GUID = "";
  1805. }
  1806. return;
  1807. }
  1808. ++i;
  1809. }
  1810. }
  1811. }
  1812. int InitializeParser()
  1813. {
  1814. int ret = cmXMLParser::InitializeParser();
  1815. if(ret == 0)
  1816. {
  1817. return ret;
  1818. }
  1819. // visual studio projects have a strange encoding, but it is
  1820. // really utf-8
  1821. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1822. return 1;
  1823. }
  1824. std::string GUID;
  1825. };
  1826. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1827. const char* name,
  1828. const char* path)
  1829. {
  1830. cmVS7XMLParser parser;
  1831. parser.ParseFile(path);
  1832. // if we can not find a GUID then create one
  1833. if(parser.GUID.size() == 0)
  1834. {
  1835. cmGlobalVisualStudio7Generator* gg =
  1836. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1837. gg->CreateGUID(name);
  1838. return;
  1839. }
  1840. std::string guidStoreName = name;
  1841. guidStoreName += "_GUID_CMAKE";
  1842. // save the GUID in the cache
  1843. this->GlobalGenerator->GetCMakeInstance()->
  1844. AddCacheEntry(guidStoreName.c_str(),
  1845. parser.GUID.c_str(),
  1846. "Stored GUID",
  1847. cmCacheManager::INTERNAL);
  1848. }
  1849. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1850. {
  1851. cmLocalGenerator::ConfigureFinalPass();
  1852. cmTargets &tgts = this->Makefile->GetTargets();
  1853. cmGlobalVisualStudio7Generator* gg =
  1854. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1855. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1856. {
  1857. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1858. {
  1859. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1860. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1861. std::string project_name = cmds[0][0];
  1862. this->ReadAndStoreExternalGUID(project_name.c_str(),
  1863. cmds[0][1].c_str());
  1864. }
  1865. else
  1866. {
  1867. gg->CreateGUID(l->first.c_str());
  1868. }
  1869. }
  1870. }
  1871. //----------------------------------------------------------------------------
  1872. std::string cmLocalVisualStudio7Generator
  1873. ::GetTargetDirectory(cmTarget const& target) const
  1874. {
  1875. std::string dir;
  1876. dir += target.GetName();
  1877. dir += ".dir";
  1878. return dir;
  1879. }
  1880. //----------------------------------------------------------------------------
  1881. cmLocalVisualStudio7GeneratorOptions
  1882. ::cmLocalVisualStudio7GeneratorOptions(cmLocalVisualStudio7Generator* lg,
  1883. int version,
  1884. Tool tool,
  1885. cmVS7FlagTable const* extraTable):
  1886. LocalGenerator(lg), Version(version), CurrentTool(tool),
  1887. DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable)
  1888. {
  1889. // Choose the flag table for the requested tool.
  1890. switch(tool)
  1891. {
  1892. case Compiler:
  1893. this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
  1894. case Linker:
  1895. this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
  1896. case FortranCompiler:
  1897. this->FlagTable = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1898. default: break;
  1899. }
  1900. }
  1901. //----------------------------------------------------------------------------
  1902. void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
  1903. {
  1904. // Exception handling is on by default because the platform file has
  1905. // "/EHsc" in the flags. Normally, that will override this
  1906. // initialization to off, but the user has the option of removing
  1907. // the flag to disable exception handling. When the user does
  1908. // remove the flag we need to override the IDE default of on.
  1909. switch (this->Version)
  1910. {
  1911. case 7:
  1912. case 71:
  1913. this->FlagMap["ExceptionHandling"] = "FALSE";
  1914. break;
  1915. default:
  1916. this->FlagMap["ExceptionHandling"] = "0";
  1917. break;
  1918. }
  1919. }
  1920. //----------------------------------------------------------------------------
  1921. void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
  1922. {
  1923. // If verbose makefiles have been requested and the /nologo option
  1924. // was not given explicitly in the flags we want to add an attribute
  1925. // to the generated project to disable logo suppression. Otherwise
  1926. // the GUI default is to enable suppression.
  1927. if(verbose &&
  1928. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  1929. {
  1930. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  1931. }
  1932. }
  1933. //----------------------------------------------------------------------------
  1934. void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
  1935. {
  1936. this->Defines.push_back(def);
  1937. }
  1938. //----------------------------------------------------------------------------
  1939. void cmLocalVisualStudio7GeneratorOptions::AddDefines(const char* defines)
  1940. {
  1941. if(defines)
  1942. {
  1943. // Expand the list of definitions.
  1944. cmSystemTools::ExpandListArgument(defines, this->Defines);
  1945. }
  1946. }
  1947. //----------------------------------------------------------------------------
  1948. void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
  1949. const char* value)
  1950. {
  1951. this->FlagMap[flag] = value;
  1952. }
  1953. bool cmLocalVisualStudio7GeneratorOptions::IsDebug()
  1954. {
  1955. return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end();
  1956. }
  1957. //----------------------------------------------------------------------------
  1958. bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
  1959. {
  1960. // Look for the a _UNICODE definition.
  1961. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  1962. di != this->Defines.end(); ++di)
  1963. {
  1964. if(*di == "_UNICODE")
  1965. {
  1966. return true;
  1967. }
  1968. }
  1969. return false;
  1970. }
  1971. //----------------------------------------------------------------------------
  1972. void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
  1973. {
  1974. // Parse the input string as a windows command line since the string
  1975. // is intended for writing directly into the build files.
  1976. std::vector<std::string> args;
  1977. cmSystemTools::ParseWindowsCommandLine(flags, args);
  1978. // Process flags that need to be represented specially in the IDE
  1979. // project file.
  1980. for(std::vector<std::string>::iterator ai = args.begin();
  1981. ai != args.end(); ++ai)
  1982. {
  1983. this->HandleFlag(ai->c_str());
  1984. }
  1985. }
  1986. //----------------------------------------------------------------------------
  1987. void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
  1988. {
  1989. // If the last option was -D then this option is the definition.
  1990. if(this->DoingDefine)
  1991. {
  1992. this->DoingDefine = false;
  1993. this->Defines.push_back(flag);
  1994. return;
  1995. }
  1996. // Look for known arguments.
  1997. if(flag[0] == '-' || flag[0] == '/')
  1998. {
  1999. // Look for preprocessor definitions.
  2000. if(this->CurrentTool == Compiler && flag[1] == 'D')
  2001. {
  2002. if(flag[2] == '\0')
  2003. {
  2004. // The next argument will have the definition.
  2005. this->DoingDefine = true;
  2006. }
  2007. else
  2008. {
  2009. // Store this definition.
  2010. this->Defines.push_back(flag+2);
  2011. }
  2012. return;
  2013. }
  2014. // Look through the available flag tables.
  2015. bool flag_handled = false;
  2016. if(this->FlagTable &&
  2017. this->CheckFlagTable(this->FlagTable, flag, flag_handled))
  2018. {
  2019. return;
  2020. }
  2021. if(this->ExtraFlagTable &&
  2022. this->CheckFlagTable(this->ExtraFlagTable, flag, flag_handled))
  2023. {
  2024. return;
  2025. }
  2026. // If any map entry handled the flag we are done.
  2027. if(flag_handled)
  2028. {
  2029. return;
  2030. }
  2031. }
  2032. // This option is not known. Store it in the output flags.
  2033. this->FlagString += " ";
  2034. this->FlagString +=
  2035. cmSystemTools::EscapeWindowsShellArgument(
  2036. flag,
  2037. cmsysSystem_Shell_Flag_AllowMakeVariables |
  2038. cmsysSystem_Shell_Flag_VSIDE);
  2039. }
  2040. //----------------------------------------------------------------------------
  2041. bool
  2042. cmLocalVisualStudio7GeneratorOptions
  2043. ::CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  2044. bool& flag_handled)
  2045. {
  2046. // Look for an entry in the flag table matching this flag.
  2047. for(cmVS7FlagTable const* entry = table; entry->IDEName; ++entry)
  2048. {
  2049. bool entry_found = false;
  2050. if(entry->special & cmVS7FlagTable::UserValue)
  2051. {
  2052. // This flag table entry accepts a user-specified value. If
  2053. // the entry specifies UserRequired we must match only if a
  2054. // non-empty value is given.
  2055. int n = static_cast<int>(strlen(entry->commandFlag));
  2056. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  2057. (!(entry->special & cmVS7FlagTable::UserRequired) ||
  2058. static_cast<int>(strlen(flag+1)) > n))
  2059. {
  2060. if(entry->special & cmVS7FlagTable::UserIgnored)
  2061. {
  2062. // Ignore the user-specified value.
  2063. this->FlagMap[entry->IDEName] = entry->value;
  2064. }
  2065. else if(entry->special & cmVS7FlagTable::SemicolonAppendable)
  2066. {
  2067. const char *new_value = flag+1+n;
  2068. std::map<cmStdString,cmStdString>::iterator itr;
  2069. itr = this->FlagMap.find(entry->IDEName);
  2070. if(itr != this->FlagMap.end())
  2071. {
  2072. // Append to old value (if present) with semicolons;
  2073. itr->second += ";";
  2074. itr->second += new_value;
  2075. }
  2076. else
  2077. {
  2078. this->FlagMap[entry->IDEName] = new_value;
  2079. }
  2080. }
  2081. else
  2082. {
  2083. // Use the user-specified value.
  2084. this->FlagMap[entry->IDEName] = flag+1+n;
  2085. }
  2086. entry_found = true;
  2087. }
  2088. }
  2089. else if(strcmp(flag+1, entry->commandFlag) == 0)
  2090. {
  2091. // This flag table entry provides a fixed value.
  2092. this->FlagMap[entry->IDEName] = entry->value;
  2093. entry_found = true;
  2094. }
  2095. // If the flag has been handled by an entry not requesting a
  2096. // search continuation we are done.
  2097. if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
  2098. {
  2099. return true;
  2100. }
  2101. // If the entry was found the flag has been handled.
  2102. flag_handled = flag_handled || entry_found;
  2103. }
  2104. return false;
  2105. }
  2106. //----------------------------------------------------------------------------
  2107. void
  2108. cmLocalVisualStudio7GeneratorOptions
  2109. ::OutputPreprocessorDefinitions(std::ostream& fout,
  2110. const char* prefix,
  2111. const char* suffix)
  2112. {
  2113. if(this->Defines.empty())
  2114. {
  2115. return;
  2116. }
  2117. fout << prefix << "PreprocessorDefinitions=\"";
  2118. const char* comma = "";
  2119. for(std::vector<std::string>::const_iterator di = this->Defines.begin();
  2120. di != this->Defines.end(); ++di)
  2121. {
  2122. // Escape the definition for the compiler.
  2123. std::string define =
  2124. this->LocalGenerator->EscapeForShell(di->c_str(), true);
  2125. // Escape this flag for the IDE.
  2126. define = cmLocalVisualStudio7GeneratorEscapeForXML(define.c_str());
  2127. // Store the flag in the project file.
  2128. fout << comma << define;
  2129. comma = ",";
  2130. }
  2131. fout << "\"" << suffix;
  2132. }
  2133. //----------------------------------------------------------------------------
  2134. void
  2135. cmLocalVisualStudio7GeneratorOptions
  2136. ::OutputFlagMap(std::ostream& fout, const char* indent)
  2137. {
  2138. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  2139. m != this->FlagMap.end(); ++m)
  2140. {
  2141. fout << indent << m->first << "=\"" << m->second << "\"\n";
  2142. }
  2143. }
  2144. //----------------------------------------------------------------------------
  2145. void
  2146. cmLocalVisualStudio7GeneratorOptions
  2147. ::OutputAdditionalOptions(std::ostream& fout,
  2148. const char* prefix,
  2149. const char* suffix)
  2150. {
  2151. if(!this->FlagString.empty())
  2152. {
  2153. fout << prefix << "AdditionalOptions=\"";
  2154. fout <<
  2155. cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
  2156. fout << "\"" << suffix;
  2157. }
  2158. }
  2159. void cmLocalVisualStudio7Generator::
  2160. GetTargetObjectFileDirectories(cmTarget* target,
  2161. std::vector<std::string>&
  2162. dirs)
  2163. {
  2164. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  2165. dir += "/";
  2166. dir += this->GetTargetDirectory(*target);
  2167. dir += "/";
  2168. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  2169. dirs.push_back(dir);
  2170. }
  2171. //----------------------------------------------------------------------------
  2172. #include <windows.h>
  2173. static bool cmLVS6G_IsFAT(const char* dir)
  2174. {
  2175. if(dir[0] && dir[1] == ':')
  2176. {
  2177. char volRoot[4] = "_:/";
  2178. volRoot[0] = dir[0];
  2179. char fsName[16];
  2180. if(GetVolumeInformation(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2181. strstr(fsName, "FAT") != 0)
  2182. {
  2183. return true;
  2184. }
  2185. }
  2186. return false;
  2187. }