cmLocalVisualStudio7Generator.cxx 64 KB

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