cmLocalVisualStudio7Generator.cxx 62 KB

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