cmLocalVisualStudio7Generator.cxx 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  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. Tool CurrentTool;
  370. bool DoingDefine;
  371. cmVS7FlagTable const* FlagTable;
  372. cmVS7FlagTable const* ExtraFlagTable;
  373. void HandleFlag(const char* flag);
  374. bool CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  375. bool& flag_handled);
  376. };
  377. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  378. const char* configName,
  379. const char *libName,
  380. cmTarget &target)
  381. {
  382. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  383. if(!mfcFlag)
  384. {
  385. mfcFlag = "0";
  386. }
  387. fout << "\t\t<Configuration\n"
  388. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  389. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  390. // This is an internal type to Visual Studio, it seems that:
  391. // 4 == static library
  392. // 2 == dll
  393. // 1 == executable
  394. // 10 == utility
  395. const char* configType = "10";
  396. switch(target.GetType())
  397. {
  398. case cmTarget::STATIC_LIBRARY:
  399. configType = "4";
  400. break;
  401. case cmTarget::SHARED_LIBRARY:
  402. case cmTarget::MODULE_LIBRARY:
  403. configType = "2";
  404. break;
  405. case cmTarget::EXECUTABLE:
  406. configType = "1";
  407. break;
  408. case cmTarget::UTILITY:
  409. case cmTarget::GLOBAL_TARGET:
  410. configType = "10";
  411. default:
  412. break;
  413. }
  414. std::string flags;
  415. if(strcmp(configType, "10") != 0)
  416. {
  417. const char* linkLanguage =
  418. target.GetLinkerLanguage(this->GetGlobalGenerator());
  419. if(!linkLanguage)
  420. {
  421. cmSystemTools::Error
  422. ("CMake can not determine linker language for target:",
  423. target.GetName());
  424. return;
  425. }
  426. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
  427. {
  428. std::string baseFlagVar = "CMAKE_";
  429. baseFlagVar += linkLanguage;
  430. baseFlagVar += "_FLAGS";
  431. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  432. std::string flagVar = baseFlagVar + std::string("_") +
  433. cmSystemTools::UpperCase(configName);
  434. flags += " ";
  435. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  436. }
  437. // set the correct language
  438. if(strcmp(linkLanguage, "C") == 0)
  439. {
  440. flags += " /TC ";
  441. }
  442. if(strcmp(linkLanguage, "CXX") == 0)
  443. {
  444. flags += " /TP ";
  445. }
  446. }
  447. // Add the target-specific flags.
  448. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  449. {
  450. flags += " ";
  451. flags += targetFlags;
  452. }
  453. // Get preprocessor definitions for this directory.
  454. std::string defineFlags = this->Makefile->GetDefineFlags();
  455. // Construct a set of build options for this target.
  456. Options targetOptions(Options::Compiler, this->ExtraFlagTable);
  457. targetOptions.FixExceptionHandlingDefault();
  458. targetOptions.Parse(flags.c_str());
  459. targetOptions.Parse(defineFlags.c_str());
  460. targetOptions.SetVerboseMakefile(
  461. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  462. // Add a definition for the configuration name.
  463. std::string configDefine = "CMAKE_INTDIR=\"";
  464. configDefine += configName;
  465. configDefine += "\"";
  466. targetOptions.AddDefine(configDefine);
  467. // Add the export symbol definition for shared library objects.
  468. if(const char* exportMacro = target.GetExportMacro())
  469. {
  470. targetOptions.AddDefine(exportMacro);
  471. }
  472. // The intermediate directory name consists of a directory for the
  473. // target and a subdirectory for the configuration name.
  474. std::string intermediateDir = this->GetTargetDirectory(target);
  475. intermediateDir += "/";
  476. intermediateDir += configName;
  477. fout << "\t\t\tIntermediateDirectory=\""
  478. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  479. << "\"\n"
  480. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  481. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  482. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  483. // If unicode is enabled change the character set to unicode, if not
  484. // then default to MBCS.
  485. if(targetOptions.UsingUnicode())
  486. {
  487. fout << "\t\t\tCharacterSet=\"1\">\n";
  488. }
  489. else
  490. {
  491. fout << "\t\t\tCharacterSet=\"2\">\n";
  492. }
  493. fout << "\t\t\t<Tool\n"
  494. << "\t\t\t\tName=\"VCCLCompilerTool\"\n";
  495. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  496. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  497. std::vector<std::string> includes;
  498. this->GetIncludeDirectories(includes);
  499. std::vector<std::string>::iterator i = includes.begin();
  500. for(;i != includes.end(); ++i)
  501. {
  502. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  503. fout << ipath << ";";
  504. }
  505. fout << "\"\n";
  506. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  507. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  508. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  509. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  510. if(target.GetType() == cmTarget::EXECUTABLE ||
  511. target.GetType() == cmTarget::STATIC_LIBRARY ||
  512. target.GetType() == cmTarget::SHARED_LIBRARY ||
  513. target.GetType() == cmTarget::MODULE_LIBRARY)
  514. {
  515. // We need to specify a program database file name even for
  516. // non-debug configurations because VS still creates .idb files.
  517. fout << "\t\t\t\tProgramDataBaseFileName=\""
  518. << target.GetDirectory(configName) << "/"
  519. << target.GetPDBName(configName) << "\"\n";
  520. }
  521. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  522. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  523. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  524. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  525. for(i = includes.begin();i != includes.end(); ++i)
  526. {
  527. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  528. fout << ipath << ";";
  529. }
  530. // add the -D flags to the RC tool
  531. fout << "\"";
  532. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  533. fout << "/>\n";
  534. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  535. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  536. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  537. if( this->PlatformName == "x64" )
  538. {
  539. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  540. }
  541. else if( this->PlatformName == "ia64" )
  542. {
  543. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  544. }
  545. else
  546. {
  547. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  548. }
  549. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  550. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  551. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  552. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  553. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  554. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  555. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  556. // end of <Tool Name=VCMIDLTool
  557. // If we are building a version 8 project file, add a flag telling the
  558. // manifest tool to use a workaround for FAT32 file systems, which can cause
  559. // an empty manifest to be embedded into the resulting executable.
  560. // See CMake bug #2617.
  561. if ( this->Version >= 8 )
  562. {
  563. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  564. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  565. << "\t\t\t/>\n";
  566. }
  567. this->OutputTargetRules(fout, configName, target, libName);
  568. this->OutputBuildTool(fout, configName, target);
  569. fout << "\t\t</Configuration>\n";
  570. }
  571. //----------------------------------------------------------------------------
  572. std::string
  573. cmLocalVisualStudio7Generator
  574. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  575. {
  576. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  577. std::string extraLinkOptionsBuildTypeDef =
  578. rootLinkerFlags + "_" + configTypeUpper;
  579. std::string extraLinkOptionsBuildType =
  580. this->Makefile->GetRequiredDefinition
  581. (extraLinkOptionsBuildTypeDef.c_str());
  582. return extraLinkOptionsBuildType;
  583. }
  584. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  585. const char* configName,
  586. cmTarget &target)
  587. {
  588. std::string temp;
  589. std::string extraLinkOptions;
  590. if(target.GetType() == cmTarget::EXECUTABLE)
  591. {
  592. extraLinkOptions =
  593. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  594. + std::string(" ")
  595. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  596. }
  597. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  598. {
  599. extraLinkOptions =
  600. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  601. + std::string(" ")
  602. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  603. }
  604. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  605. {
  606. extraLinkOptions =
  607. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  608. + std::string(" ")
  609. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  610. }
  611. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  612. if(targetLinkFlags)
  613. {
  614. extraLinkOptions += " ";
  615. extraLinkOptions += targetLinkFlags;
  616. }
  617. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  618. std::string linkFlagsConfig = "LINK_FLAGS_";
  619. linkFlagsConfig += configTypeUpper;
  620. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  621. if(targetLinkFlags)
  622. {
  623. extraLinkOptions += " ";
  624. extraLinkOptions += targetLinkFlags;
  625. }
  626. Options linkOptions(Options::Linker);
  627. linkOptions.Parse(extraLinkOptions.c_str());
  628. switch(target.GetType())
  629. {
  630. case cmTarget::STATIC_LIBRARY:
  631. {
  632. std::string targetNameFull = target.GetFullName(configName);
  633. std::string libpath = target.GetDirectory(configName);
  634. libpath += "/";
  635. libpath += targetNameFull;
  636. fout << "\t\t\t<Tool\n"
  637. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  638. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  639. {
  640. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  641. }
  642. fout << "\t\t\t\tOutputFile=\""
  643. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  644. break;
  645. }
  646. case cmTarget::SHARED_LIBRARY:
  647. case cmTarget::MODULE_LIBRARY:
  648. {
  649. std::string targetName;
  650. std::string targetNameSO;
  651. std::string targetNameFull;
  652. std::string targetNameImport;
  653. std::string targetNamePDB;
  654. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  655. targetNameImport, targetNamePDB, configName);
  656. // Compute the link library and directory information.
  657. std::vector<cmStdString> linkLibs;
  658. std::vector<cmStdString> linkDirs;
  659. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  660. // Get the language to use for linking.
  661. const char* linkLanguage =
  662. target.GetLinkerLanguage(this->GetGlobalGenerator());
  663. if(!linkLanguage)
  664. {
  665. cmSystemTools::Error
  666. ("CMake can not determine linker language for target:",
  667. target.GetName());
  668. return;
  669. }
  670. // Compute the variable name to lookup standard libraries for this
  671. // language.
  672. std::string standardLibsVar = "CMAKE_";
  673. standardLibsVar += linkLanguage;
  674. standardLibsVar += "_STANDARD_LIBRARIES";
  675. fout << "\t\t\t<Tool\n"
  676. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  677. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  678. // Use the NOINHERIT macro to avoid getting VS project default
  679. // libraries which may be set by the user to something bad.
  680. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  681. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  682. << " ";
  683. this->OutputLibraries(fout, linkLibs);
  684. fout << "\"\n";
  685. temp = target.GetDirectory(configName);
  686. temp += "/";
  687. temp += targetNameFull;
  688. fout << "\t\t\t\tOutputFile=\""
  689. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  690. this->WriteTargetVersionAttribute(fout, target);
  691. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  692. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  693. this->OutputLibraryDirectories(fout, linkDirs);
  694. fout << "\"\n";
  695. this->OutputModuleDefinitionFile(fout, target);
  696. temp = target.GetDirectory(configName);
  697. temp += "/";
  698. temp += targetNamePDB;
  699. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  700. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  701. if(strcmp(configName, "Debug") == 0
  702. || strcmp(configName, "RelWithDebInfo") == 0)
  703. {
  704. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  705. }
  706. std::string stackVar = "CMAKE_";
  707. stackVar += linkLanguage;
  708. stackVar += "_STACK_SIZE";
  709. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  710. if(stackVal)
  711. {
  712. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  713. }
  714. temp = target.GetDirectory(configName, true);
  715. temp += "/";
  716. temp += targetNameImport;
  717. fout << "\t\t\t\tImportLibrary=\""
  718. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  719. }
  720. break;
  721. case cmTarget::EXECUTABLE:
  722. {
  723. std::string targetName;
  724. std::string targetNameFull;
  725. std::string targetNameImport;
  726. std::string targetNamePDB;
  727. target.GetExecutableNames(targetName, targetNameFull,
  728. targetNameImport, targetNamePDB, configName);
  729. // Compute the link library and directory information.
  730. std::vector<cmStdString> linkLibs;
  731. std::vector<cmStdString> linkDirs;
  732. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  733. // Get the language to use for linking.
  734. const char* linkLanguage =
  735. target.GetLinkerLanguage(this->GetGlobalGenerator());
  736. if(!linkLanguage)
  737. {
  738. cmSystemTools::Error
  739. ("CMake can not determine linker language for target:",
  740. target.GetName());
  741. return;
  742. }
  743. // Compute the variable name to lookup standard libraries for this
  744. // language.
  745. std::string standardLibsVar = "CMAKE_";
  746. standardLibsVar += linkLanguage;
  747. standardLibsVar += "_STANDARD_LIBRARIES";
  748. fout << "\t\t\t<Tool\n"
  749. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  750. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  751. // Use the NOINHERIT macro to avoid getting VS project default
  752. // libraries which may be set by the user to something bad.
  753. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  754. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  755. << " ";
  756. this->OutputLibraries(fout, linkLibs);
  757. fout << "\"\n";
  758. temp = target.GetDirectory(configName);
  759. temp += "/";
  760. temp += targetNameFull;
  761. fout << "\t\t\t\tOutputFile=\""
  762. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  763. this->WriteTargetVersionAttribute(fout, target);
  764. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  765. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  766. this->OutputLibraryDirectories(fout, linkDirs);
  767. fout << "\"\n";
  768. fout << "\t\t\t\tProgramDataBaseFile=\""
  769. << target.GetDirectory(configName) << "/" << targetNamePDB
  770. << "\"\n";
  771. if(strcmp(configName, "Debug") == 0
  772. || strcmp(configName, "RelWithDebInfo") == 0)
  773. {
  774. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  775. }
  776. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  777. {
  778. fout << "\t\t\t\tSubSystem=\"2\"\n";
  779. }
  780. else
  781. {
  782. fout << "\t\t\t\tSubSystem=\"1\"\n";
  783. }
  784. std::string stackVar = "CMAKE_";
  785. stackVar += linkLanguage;
  786. stackVar += "_STACK_SIZE";
  787. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  788. if(stackVal)
  789. {
  790. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  791. }
  792. temp = target.GetDirectory(configName, true);
  793. temp += "/";
  794. temp += targetNameImport;
  795. fout << "\t\t\t\tImportLibrary=\""
  796. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  797. break;
  798. }
  799. case cmTarget::UTILITY:
  800. case cmTarget::GLOBAL_TARGET:
  801. break;
  802. }
  803. }
  804. //----------------------------------------------------------------------------
  805. void
  806. cmLocalVisualStudio7Generator
  807. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  808. {
  809. int major;
  810. int minor;
  811. target.GetTargetVersion(major, minor);
  812. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  813. }
  814. void cmLocalVisualStudio7Generator
  815. ::OutputModuleDefinitionFile(std::ostream& fout,
  816. cmTarget &target)
  817. {
  818. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  819. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  820. i != classes.end(); i++)
  821. {
  822. cmSourceFile* sf = *i;
  823. if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
  824. {
  825. fout << "\t\t\t\tModuleDefinitionFile=\""
  826. << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
  827. << "\"\n";
  828. return;
  829. }
  830. }
  831. }
  832. //----------------------------------------------------------------------------
  833. void
  834. cmLocalVisualStudio7Generator
  835. ::OutputLibraries(std::ostream& fout,
  836. std::vector<cmStdString> const& libs)
  837. {
  838. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  839. l != libs.end(); ++l)
  840. {
  841. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  842. }
  843. }
  844. //----------------------------------------------------------------------------
  845. void
  846. cmLocalVisualStudio7Generator
  847. ::OutputLibraryDirectories(std::ostream& fout,
  848. std::vector<cmStdString> const& dirs)
  849. {
  850. const char* comma = "";
  851. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  852. d != dirs.end(); ++d)
  853. {
  854. // Remove any trailing slash and skip empty paths.
  855. std::string dir = *d;
  856. if(dir[dir.size()-1] == '/')
  857. {
  858. dir = dir.substr(0, dir.size()-1);
  859. }
  860. if(dir.empty())
  861. {
  862. continue;
  863. }
  864. // Switch to a relative path specification if it is shorter.
  865. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  866. {
  867. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  868. if(rel.size() < dir.size())
  869. {
  870. dir = rel;
  871. }
  872. }
  873. // First search a configuration-specific subdirectory and then the
  874. // original directory.
  875. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  876. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  877. comma = ",";
  878. }
  879. }
  880. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  881. const char *libName,
  882. cmTarget &target)
  883. {
  884. // get the configurations
  885. std::vector<std::string> *configs =
  886. static_cast<cmGlobalVisualStudio7Generator *>
  887. (this->GlobalGenerator)->GetConfigurations();
  888. // trace the visual studio dependencies
  889. std::string name = libName;
  890. name += ".vcproj.cmake";
  891. // We may be modifying the source groups temporarily, so make a copy.
  892. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  893. // get the classes from the source lists then add them to the groups
  894. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  895. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  896. i != classes.end(); i++)
  897. {
  898. // Add the file to the list of sources.
  899. std::string source = (*i)->GetFullPath();
  900. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  901. {
  902. this->ModuleDefinitionFile = (*i)->GetFullPath();
  903. }
  904. cmSourceGroup& sourceGroup =
  905. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  906. sourceGroup.AssignSource(*i);
  907. }
  908. // Compute which sources need unique object computation.
  909. this->ComputeObjectNameRequirements(sourceGroups);
  910. // open the project
  911. this->WriteProjectStart(fout, libName, target, sourceGroups);
  912. // write the configuration information
  913. this->WriteConfigurations(fout, libName, target);
  914. fout << "\t<Files>\n";
  915. // Loop through every source group.
  916. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  917. {
  918. cmSourceGroup sg = sourceGroups[i];
  919. this->WriteGroup(&sg, target, fout, libName, configs);
  920. }
  921. //}
  922. fout << "\t</Files>\n";
  923. // Write the VCProj file's footer.
  924. this->WriteVCProjFooter(fout);
  925. }
  926. void cmLocalVisualStudio7Generator
  927. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  928. std::ostream &fout, const char *libName,
  929. std::vector<std::string> *configs)
  930. {
  931. const std::vector<const cmSourceFile *> &sourceFiles =
  932. sg->GetSourceFiles();
  933. // If the group is empty, don't write it at all.
  934. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  935. {
  936. return;
  937. }
  938. // If the group has a name, write the header.
  939. std::string name = sg->GetName();
  940. if(name != "")
  941. {
  942. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  943. }
  944. // Compute the maximum length of a configuration name.
  945. std::string::size_type config_len_max = 0;
  946. for(std::vector<std::string>::iterator i = configs->begin();
  947. i != configs->end(); ++i)
  948. {
  949. if(i->size() > config_len_max)
  950. {
  951. config_len_max = i->size();
  952. }
  953. }
  954. // Compute the maximum length of the full path to the intermediate
  955. // files directory for any configuration. This is used to construct
  956. // object file names that do not produce paths that are too long.
  957. std::string::size_type dir_len = 0;
  958. dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
  959. dir_len += 1;
  960. dir_len += this->GetTargetDirectory(target).size();
  961. dir_len += 1;
  962. dir_len += config_len_max;
  963. dir_len += 1;
  964. // Loop through each source in the source group.
  965. std::string objectName;
  966. for(std::vector<const cmSourceFile *>::const_iterator sf =
  967. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  968. {
  969. std::string source = (*sf)->GetFullPath();
  970. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  971. std::string compileFlags;
  972. std::string additionalDeps;
  973. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  974. {
  975. objectName = this->GetObjectFileNameWithoutTarget(*(*sf), dir_len);
  976. }
  977. else
  978. {
  979. objectName = "";
  980. }
  981. // Add per-source flags.
  982. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  983. if(cflags)
  984. {
  985. compileFlags += " ";
  986. compileFlags += cflags;
  987. }
  988. const char* lang =
  989. this->GlobalGenerator->GetLanguageFromExtension
  990. ((*sf)->GetExtension().c_str());
  991. const char* sourceLang = this->GetSourceFileLanguage(*(*sf));
  992. const char* linkLanguage = target.GetLinkerLanguage
  993. (this->GetGlobalGenerator());
  994. bool needForceLang = false;
  995. // source file does not match its extension language
  996. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  997. {
  998. needForceLang = true;
  999. lang = sourceLang;
  1000. }
  1001. // If lang is set, the compiler will generate code automatically.
  1002. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1003. // the project file
  1004. bool excludedFromBuild =
  1005. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  1006. // if the source file does not match the linker language
  1007. // then force c or c++
  1008. if(needForceLang || (linkLanguage && lang
  1009. && strcmp(lang, linkLanguage) != 0))
  1010. {
  1011. if(strcmp(lang, "CXX") == 0)
  1012. {
  1013. // force a C++ file type
  1014. compileFlags += " /TP ";
  1015. }
  1016. else if(strcmp(lang, "C") == 0)
  1017. {
  1018. // force to c
  1019. compileFlags += " /TC ";
  1020. }
  1021. }
  1022. // Check for extra object-file dependencies.
  1023. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  1024. if(deps)
  1025. {
  1026. std::vector<std::string> depends;
  1027. cmSystemTools::ExpandListArgument(deps, depends);
  1028. if(!depends.empty())
  1029. {
  1030. std::vector<std::string>::iterator i = depends.begin();
  1031. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  1032. for(++i;i != depends.end(); ++i)
  1033. {
  1034. additionalDeps += ";";
  1035. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  1036. }
  1037. }
  1038. }
  1039. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1040. target.GetType() == cmTarget::GLOBAL_TARGET )
  1041. {
  1042. fout << "\t\t\t<File\n";
  1043. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1044. // Tell MS-Dev what the source is. If the compiler knows how to
  1045. // build it, then it will.
  1046. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1047. if (command)
  1048. {
  1049. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  1050. this->WriteCustomRule(fout, source.c_str(), *command, flags);
  1051. }
  1052. else if(compileFlags.size() || additionalDeps.length()
  1053. || objectName.size() || excludedFromBuild)
  1054. {
  1055. const char* aCompilerTool = "VCCLCompilerTool";
  1056. std::string ext = (*sf)->GetExtension();
  1057. ext = cmSystemTools::LowerCase(ext);
  1058. if(ext == "idl")
  1059. {
  1060. aCompilerTool = "VCMIDLTool";
  1061. }
  1062. if(ext == "rc")
  1063. {
  1064. aCompilerTool = "VCResourceCompilerTool";
  1065. }
  1066. if(ext == "def")
  1067. {
  1068. aCompilerTool = "VCCustomBuildTool";
  1069. }
  1070. for(std::vector<std::string>::iterator i = configs->begin();
  1071. i != configs->end(); ++i)
  1072. {
  1073. fout << "\t\t\t\t<FileConfiguration\n"
  1074. << "\t\t\t\t\tName=\"" << *i
  1075. << "|" << this->PlatformName << "\"";
  1076. if(excludedFromBuild)
  1077. {
  1078. fout << " ExcludedFromBuild=\"true\"";
  1079. }
  1080. fout << ">\n";
  1081. fout << "\t\t\t\t\t<Tool\n"
  1082. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1083. if(!compileFlags.empty())
  1084. {
  1085. Options fileOptions(Options::Compiler, this->ExtraFlagTable);
  1086. fileOptions.Parse(compileFlags.c_str());
  1087. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1088. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1089. fileOptions.OutputPreprocessorDefinitions(fout,
  1090. "\t\t\t\t\t", "\n");
  1091. }
  1092. if(additionalDeps.length())
  1093. {
  1094. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1095. << additionalDeps.c_str() << "\"\n";
  1096. }
  1097. if(objectName.size())
  1098. {
  1099. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1100. << objectName.c_str() << "\"\n";
  1101. }
  1102. fout << "\t\t\t\t\t/>\n"
  1103. << "\t\t\t\t</FileConfiguration>\n";
  1104. }
  1105. }
  1106. fout << "\t\t\t</File>\n";
  1107. }
  1108. }
  1109. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  1110. for(unsigned int i=0;i<children.size();++i)
  1111. {
  1112. this->WriteGroup(&children[i], target, fout, libName, configs);
  1113. }
  1114. // If the group has a name, write the footer.
  1115. if(name != "")
  1116. {
  1117. this->WriteVCProjEndGroup(fout);
  1118. }
  1119. }
  1120. void cmLocalVisualStudio7Generator::
  1121. WriteCustomRule(std::ostream& fout,
  1122. const char* source,
  1123. const cmCustomCommand& command,
  1124. const char* compileFlags)
  1125. {
  1126. std::string comment = this->ConstructComment(command);
  1127. // Write the rule for each configuration.
  1128. std::vector<std::string>::iterator i;
  1129. std::vector<std::string> *configs =
  1130. static_cast<cmGlobalVisualStudio7Generator *>
  1131. (this->GlobalGenerator)->GetConfigurations();
  1132. for(i = configs->begin(); i != configs->end(); ++i)
  1133. {
  1134. fout << "\t\t\t\t<FileConfiguration\n";
  1135. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1136. if(compileFlags)
  1137. {
  1138. fout << "\t\t\t\t\t<Tool\n"
  1139. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1140. << "\t\t\t\t\tAdditionalOptions=\""
  1141. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1142. }
  1143. std::string script =
  1144. this->ConstructScript(command.GetCommandLines(),
  1145. command.GetWorkingDirectory(),
  1146. i->c_str(),
  1147. command.GetEscapeOldStyle(),
  1148. command.GetEscapeAllowMakeVars());
  1149. fout << "\t\t\t\t\t<Tool\n"
  1150. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1151. << "\t\t\t\t\tDescription=\""
  1152. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1153. << "\t\t\t\t\tCommandLine=\""
  1154. << this->EscapeForXML(script.c_str()) << "\"\n"
  1155. << "\t\t\t\t\tAdditionalDependencies=\"";
  1156. if(command.GetDepends().empty())
  1157. {
  1158. // There are no real dependencies. Produce an artificial one to
  1159. // make sure the rule runs reliably.
  1160. if(!cmSystemTools::FileExists(source))
  1161. {
  1162. std::ofstream depout(source);
  1163. depout << "Artificial dependency for a custom command.\n";
  1164. }
  1165. fout << this->ConvertToXMLOutputPath(source);
  1166. }
  1167. else
  1168. {
  1169. // Write out the dependencies for the rule.
  1170. for(std::vector<std::string>::const_iterator d =
  1171. command.GetDepends().begin();
  1172. d != command.GetDepends().end();
  1173. ++d)
  1174. {
  1175. // Get the real name of the dependency in case it is a CMake target.
  1176. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1177. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1178. << ";";
  1179. }
  1180. }
  1181. fout << "\"\n";
  1182. fout << "\t\t\t\t\tOutputs=\"";
  1183. if(command.GetOutputs().empty())
  1184. {
  1185. fout << source << "_force";
  1186. }
  1187. else
  1188. {
  1189. // Write a rule for the output generated by this command.
  1190. const char* sep = "";
  1191. for(std::vector<std::string>::const_iterator o =
  1192. command.GetOutputs().begin();
  1193. o != command.GetOutputs().end();
  1194. ++o)
  1195. {
  1196. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1197. sep = ";";
  1198. }
  1199. }
  1200. fout << "\"/>\n";
  1201. fout << "\t\t\t\t</FileConfiguration>\n";
  1202. }
  1203. }
  1204. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1205. const char* group,
  1206. const char* )
  1207. {
  1208. fout << "\t\t<Filter\n"
  1209. << "\t\t\tName=\"" << group << "\"\n"
  1210. << "\t\t\tFilter=\"\">\n";
  1211. }
  1212. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1213. {
  1214. fout << "\t\t</Filter>\n";
  1215. }
  1216. // look for custom rules on a target and collect them together
  1217. void cmLocalVisualStudio7Generator
  1218. ::OutputTargetRules(std::ostream& fout,
  1219. const char* configName,
  1220. cmTarget &target,
  1221. const char * /*libName*/)
  1222. {
  1223. if (target.GetType() > cmTarget::GLOBAL_TARGET)
  1224. {
  1225. return;
  1226. }
  1227. // add the pre build rules
  1228. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"";
  1229. bool init = false;
  1230. for (std::vector<cmCustomCommand>::const_iterator cr =
  1231. target.GetPreBuildCommands().begin();
  1232. cr != target.GetPreBuildCommands().end(); ++cr)
  1233. {
  1234. if(!init)
  1235. {
  1236. fout << "\nCommandLine=\"";
  1237. init = true;
  1238. }
  1239. else
  1240. {
  1241. fout << this->EscapeForXML("\n");
  1242. }
  1243. std::string script =
  1244. this->ConstructScript(cr->GetCommandLines(),
  1245. cr->GetWorkingDirectory(),
  1246. configName,
  1247. cr->GetEscapeOldStyle(),
  1248. cr->GetEscapeAllowMakeVars());
  1249. fout << this->EscapeForXML(script.c_str()).c_str();
  1250. }
  1251. if (init)
  1252. {
  1253. fout << "\"";
  1254. }
  1255. fout << "/>\n";
  1256. // add the pre Link rules
  1257. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"";
  1258. init = false;
  1259. for (std::vector<cmCustomCommand>::const_iterator cr =
  1260. target.GetPreLinkCommands().begin();
  1261. cr != target.GetPreLinkCommands().end(); ++cr)
  1262. {
  1263. if(!init)
  1264. {
  1265. fout << "\nCommandLine=\"";
  1266. init = true;
  1267. }
  1268. else
  1269. {
  1270. fout << this->EscapeForXML("\n");
  1271. }
  1272. std::string script =
  1273. this->ConstructScript(cr->GetCommandLines(),
  1274. cr->GetWorkingDirectory(),
  1275. configName,
  1276. cr->GetEscapeOldStyle(),
  1277. cr->GetEscapeAllowMakeVars());
  1278. fout << this->EscapeForXML(script.c_str()).c_str();
  1279. }
  1280. if (init)
  1281. {
  1282. fout << "\"";
  1283. }
  1284. fout << "/>\n";
  1285. // add the PostBuild rules
  1286. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"";
  1287. init = false;
  1288. for (std::vector<cmCustomCommand>::const_iterator cr =
  1289. target.GetPostBuildCommands().begin();
  1290. cr != target.GetPostBuildCommands().end(); ++cr)
  1291. {
  1292. if(!init)
  1293. {
  1294. fout << "\nCommandLine=\"";
  1295. init = true;
  1296. }
  1297. else
  1298. {
  1299. fout << this->EscapeForXML("\n");
  1300. }
  1301. std::string script =
  1302. this->ConstructScript(cr->GetCommandLines(),
  1303. cr->GetWorkingDirectory(),
  1304. configName,
  1305. cr->GetEscapeOldStyle(),
  1306. cr->GetEscapeAllowMakeVars());
  1307. fout << this->EscapeForXML(script.c_str()).c_str();
  1308. }
  1309. if (init)
  1310. {
  1311. fout << "\"";
  1312. }
  1313. fout << "/>\n";
  1314. }
  1315. void
  1316. cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout,
  1317. const char *libName,
  1318. cmTarget & target,
  1319. std::vector<cmSourceGroup> &)
  1320. {
  1321. fout << "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  1322. << "<VisualStudioProject\n"
  1323. << "\tProjectType=\"Visual C++\"\n";
  1324. if(this->Version == 71)
  1325. {
  1326. fout << "\tVersion=\"7.10\"\n";
  1327. }
  1328. else
  1329. {
  1330. fout << "\tVersion=\"" << this->Version << ".00\"\n";
  1331. }
  1332. const char* projLabel = target.GetProperty("PROJECT_LABEL");
  1333. if(!projLabel)
  1334. {
  1335. projLabel = libName;
  1336. }
  1337. const char* keyword = target.GetProperty("VS_KEYWORD");
  1338. if(!keyword)
  1339. {
  1340. keyword = "Win32Proj";
  1341. }
  1342. cmGlobalVisualStudio7Generator* gg =
  1343. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1344. fout << "\tName=\"" << projLabel << "\"\n";
  1345. if(this->Version >= 8)
  1346. {
  1347. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
  1348. }
  1349. fout << "\tSccProjectName=\"\"\n"
  1350. << "\tSccLocalPath=\"\"\n"
  1351. << "\tKeyword=\"" << keyword << "\">\n"
  1352. << "\t<Platforms>\n"
  1353. << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
  1354. << "\t</Platforms>\n";
  1355. }
  1356. void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout)
  1357. {
  1358. fout << "\t<Globals>\n"
  1359. << "\t</Globals>\n"
  1360. << "</VisualStudioProject>\n";
  1361. }
  1362. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
  1363. {
  1364. std::string ret = s;
  1365. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1366. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1367. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1368. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1369. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1370. return ret;
  1371. }
  1372. std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
  1373. {
  1374. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1375. }
  1376. std::string cmLocalVisualStudio7Generator
  1377. ::ConvertToXMLOutputPath(const char* path)
  1378. {
  1379. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1380. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1381. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1382. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1383. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1384. return ret;
  1385. }
  1386. std::string cmLocalVisualStudio7Generator
  1387. ::ConvertToXMLOutputPathSingle(const char* path)
  1388. {
  1389. std::string ret = this->ConvertToOptionallyRelativeOutputPath(path);
  1390. cmSystemTools::ReplaceString(ret, "\"", "");
  1391. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1392. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1393. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1394. return ret;
  1395. }
  1396. // This class is used to parse an existing vs 7 project
  1397. // and extract the GUID
  1398. class cmVS7XMLParser : public cmXMLParser
  1399. {
  1400. public:
  1401. virtual void EndElement(const char* /* name */)
  1402. {
  1403. }
  1404. virtual void StartElement(const char* name, const char** atts)
  1405. {
  1406. // once the GUID is found do nothing
  1407. if(this->GUID.size())
  1408. {
  1409. return;
  1410. }
  1411. int i =0;
  1412. if(strcmp("VisualStudioProject", name) == 0)
  1413. {
  1414. while(atts[i])
  1415. {
  1416. if(strcmp(atts[i], "ProjectGUID") == 0)
  1417. {
  1418. if(atts[i+1])
  1419. {
  1420. this->GUID = atts[i+1];
  1421. this->GUID = this->GUID.substr(1, this->GUID.size()-2);
  1422. }
  1423. else
  1424. {
  1425. this->GUID = "";
  1426. }
  1427. return;
  1428. }
  1429. ++i;
  1430. }
  1431. }
  1432. }
  1433. int InitializeParser()
  1434. {
  1435. int ret = cmXMLParser::InitializeParser();
  1436. if(ret == 0)
  1437. {
  1438. return ret;
  1439. }
  1440. // visual studio projects have a strange encoding, but it is
  1441. // really utf-8
  1442. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1443. return 1;
  1444. }
  1445. std::string GUID;
  1446. };
  1447. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1448. const char* name,
  1449. const char* path)
  1450. {
  1451. cmVS7XMLParser parser;
  1452. parser.ParseFile(path);
  1453. // if we can not find a GUID then create one
  1454. if(parser.GUID.size() == 0)
  1455. {
  1456. cmGlobalVisualStudio7Generator* gg =
  1457. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1458. gg->CreateGUID(name);
  1459. return;
  1460. }
  1461. std::string guidStoreName = name;
  1462. guidStoreName += "_GUID_CMAKE";
  1463. // save the GUID in the cache
  1464. this->GlobalGenerator->GetCMakeInstance()->
  1465. AddCacheEntry(guidStoreName.c_str(),
  1466. parser.GUID.c_str(),
  1467. "Stored GUID",
  1468. cmCacheManager::INTERNAL);
  1469. }
  1470. void cmLocalVisualStudio7Generator::ConfigureFinalPass()
  1471. {
  1472. cmLocalGenerator::ConfigureFinalPass();
  1473. cmTargets &tgts = this->Makefile->GetTargets();
  1474. cmGlobalVisualStudio7Generator* gg =
  1475. static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
  1476. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  1477. {
  1478. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
  1479. {
  1480. cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
  1481. const cmCustomCommandLines& cmds = cc.GetCommandLines();
  1482. std::string project_name = cmds[0][0];
  1483. this->ReadAndStoreExternalGUID(project_name.c_str(),
  1484. cmds[0][1].c_str());
  1485. }
  1486. else
  1487. {
  1488. gg->CreateGUID(l->first.c_str());
  1489. }
  1490. }
  1491. }
  1492. //----------------------------------------------------------------------------
  1493. std::string cmLocalVisualStudio7Generator
  1494. ::GetTargetDirectory(cmTarget const& target) const
  1495. {
  1496. std::string dir;
  1497. dir += target.GetName();
  1498. dir += ".dir";
  1499. return dir;
  1500. }
  1501. //----------------------------------------------------------------------------
  1502. cmLocalVisualStudio7GeneratorOptions
  1503. ::cmLocalVisualStudio7GeneratorOptions(Tool tool,
  1504. cmVS7FlagTable const* extraTable):
  1505. CurrentTool(tool),
  1506. DoingDefine(false), FlagTable(0), ExtraFlagTable(extraTable)
  1507. {
  1508. // Choose the flag table for the requested tool.
  1509. switch(tool)
  1510. {
  1511. case Compiler:
  1512. this->FlagTable = cmLocalVisualStudio7GeneratorFlagTable; break;
  1513. case Linker:
  1514. this->FlagTable = cmLocalVisualStudio7GeneratorLinkFlagTable; break;
  1515. default: break;
  1516. }
  1517. }
  1518. //----------------------------------------------------------------------------
  1519. void cmLocalVisualStudio7GeneratorOptions::FixExceptionHandlingDefault()
  1520. {
  1521. // Exception handling is on by default because the platform file has
  1522. // "/EHsc" in the flags. Normally, that will override this
  1523. // initialization to off, but the user has the option of removing
  1524. // the flag to disable exception handling. When the user does
  1525. // remove the flag we need to override the IDE default of on.
  1526. this->FlagMap["ExceptionHandling"] = "FALSE";
  1527. }
  1528. //----------------------------------------------------------------------------
  1529. void cmLocalVisualStudio7GeneratorOptions::SetVerboseMakefile(bool verbose)
  1530. {
  1531. // If verbose makefiles have been requested and the /nologo option
  1532. // was not given explicitly in the flags we want to add an attribute
  1533. // to the generated project to disable logo suppression. Otherwise
  1534. // the GUI default is to enable suppression.
  1535. if(verbose &&
  1536. this->FlagMap.find("SuppressStartupBanner") == this->FlagMap.end())
  1537. {
  1538. this->FlagMap["SuppressStartupBanner"] = "FALSE";
  1539. }
  1540. }
  1541. //----------------------------------------------------------------------------
  1542. void cmLocalVisualStudio7GeneratorOptions::AddDefine(const std::string& def)
  1543. {
  1544. this->Defines.push_back(def);
  1545. }
  1546. //----------------------------------------------------------------------------
  1547. void cmLocalVisualStudio7GeneratorOptions::AddFlag(const char* flag,
  1548. const char* value)
  1549. {
  1550. this->FlagMap[flag] = value;
  1551. }
  1552. //----------------------------------------------------------------------------
  1553. bool cmLocalVisualStudio7GeneratorOptions::UsingUnicode()
  1554. {
  1555. // Look for the a _UNICODE definition.
  1556. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1557. di != this->Defines.end(); ++di)
  1558. {
  1559. if(*di == "_UNICODE")
  1560. {
  1561. return true;
  1562. }
  1563. }
  1564. return false;
  1565. }
  1566. //----------------------------------------------------------------------------
  1567. void cmLocalVisualStudio7GeneratorOptions::Parse(const char* flags)
  1568. {
  1569. // Parse the input string as a windows command line since the string
  1570. // is intended for writing directly into the build files.
  1571. std::vector<std::string> args;
  1572. cmSystemTools::ParseWindowsCommandLine(flags, args);
  1573. // Process flags that need to be represented specially in the IDE
  1574. // project file.
  1575. for(std::vector<std::string>::iterator ai = args.begin();
  1576. ai != args.end(); ++ai)
  1577. {
  1578. this->HandleFlag(ai->c_str());
  1579. }
  1580. }
  1581. //----------------------------------------------------------------------------
  1582. void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* flag)
  1583. {
  1584. // If the last option was -D then this option is the definition.
  1585. if(this->DoingDefine)
  1586. {
  1587. this->DoingDefine = false;
  1588. this->Defines.push_back(flag);
  1589. return;
  1590. }
  1591. // Look for known arguments.
  1592. if(flag[0] == '-' || flag[0] == '/')
  1593. {
  1594. // Look for preprocessor definitions.
  1595. if(this->CurrentTool == Compiler && flag[1] == 'D')
  1596. {
  1597. if(flag[2] == '\0')
  1598. {
  1599. // The next argument will have the definition.
  1600. this->DoingDefine = true;
  1601. }
  1602. else
  1603. {
  1604. // Store this definition.
  1605. this->Defines.push_back(flag+2);
  1606. }
  1607. return;
  1608. }
  1609. // Look through the available flag tables.
  1610. bool flag_handled = false;
  1611. if(this->FlagTable &&
  1612. this->CheckFlagTable(this->FlagTable, flag, flag_handled))
  1613. {
  1614. return;
  1615. }
  1616. if(this->ExtraFlagTable &&
  1617. this->CheckFlagTable(this->ExtraFlagTable, flag, flag_handled))
  1618. {
  1619. return;
  1620. }
  1621. // If any map entry handled the flag we are done.
  1622. if(flag_handled)
  1623. {
  1624. return;
  1625. }
  1626. }
  1627. // This option is not known. Store it in the output flags.
  1628. this->FlagString += " ";
  1629. this->FlagString +=
  1630. cmSystemTools::EscapeWindowsShellArgument(flag,
  1631. cmsysSystem_Shell_Flag_VSIDE);
  1632. }
  1633. //----------------------------------------------------------------------------
  1634. bool
  1635. cmLocalVisualStudio7GeneratorOptions
  1636. ::CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  1637. bool& flag_handled)
  1638. {
  1639. // Look for an entry in the flag table matching this flag.
  1640. for(cmVS7FlagTable const* entry = table; entry->IDEName; ++entry)
  1641. {
  1642. bool entry_found = false;
  1643. if(entry->special & cmVS7FlagTable::UserValue)
  1644. {
  1645. // This flag table entry accepts a user-specified value. If
  1646. // the entry specifies UserRequired we must match only if a
  1647. // non-empty value is given.
  1648. int n = static_cast<int>(strlen(entry->commandFlag));
  1649. if(strncmp(flag+1, entry->commandFlag, n) == 0 &&
  1650. (!(entry->special & cmVS7FlagTable::UserRequired) ||
  1651. static_cast<int>(strlen(flag+1)) > n))
  1652. {
  1653. if(entry->special & cmVS7FlagTable::UserIgnored)
  1654. {
  1655. // Ignore the user-specified value.
  1656. this->FlagMap[entry->IDEName] = entry->value;
  1657. }
  1658. else
  1659. {
  1660. // Use the user-specified value.
  1661. this->FlagMap[entry->IDEName] = flag+1+n;
  1662. }
  1663. entry_found = true;
  1664. }
  1665. }
  1666. else if(strcmp(flag+1, entry->commandFlag) == 0)
  1667. {
  1668. // This flag table entry provides a fixed value.
  1669. this->FlagMap[entry->IDEName] = entry->value;
  1670. entry_found = true;
  1671. }
  1672. // If the flag has been handled by an entry not requesting a
  1673. // search continuation we are done.
  1674. if(entry_found && !(entry->special & cmVS7FlagTable::Continue))
  1675. {
  1676. return true;
  1677. }
  1678. // If the entry was found the flag has been handled.
  1679. flag_handled = flag_handled || entry_found;
  1680. }
  1681. return false;
  1682. }
  1683. //----------------------------------------------------------------------------
  1684. void
  1685. cmLocalVisualStudio7GeneratorOptions
  1686. ::OutputPreprocessorDefinitions(std::ostream& fout,
  1687. const char* prefix,
  1688. const char* suffix)
  1689. {
  1690. if(this->Defines.empty())
  1691. {
  1692. return;
  1693. }
  1694. fout << prefix << "PreprocessorDefinitions=\"";
  1695. const char* comma = "";
  1696. for(std::vector<cmStdString>::const_iterator di = this->Defines.begin();
  1697. di != this->Defines.end(); ++di)
  1698. {
  1699. // Double-quotes in the value of the definition must be escaped
  1700. // with a backslash.
  1701. std::string define = di->c_str();
  1702. cmSystemTools::ReplaceString(define, "\"", "\\\"");
  1703. // Escape this flag for the IDE.
  1704. define = cmLocalVisualStudio7GeneratorEscapeForXML(define.c_str());
  1705. // Write this flag. Quote it if the definition is not
  1706. // alphanumeric.
  1707. if(define.find_first_not_of(
  1708. "-_abcdefghigklmnopqrstuvwxyz1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZ")
  1709. != define.npos)
  1710. {
  1711. fout << comma << "&quot;" << define << "&quot;";
  1712. }
  1713. else
  1714. {
  1715. fout << comma << define;
  1716. }
  1717. comma = ",";
  1718. }
  1719. fout << "\"" << suffix;
  1720. }
  1721. //----------------------------------------------------------------------------
  1722. void
  1723. cmLocalVisualStudio7GeneratorOptions
  1724. ::OutputFlagMap(std::ostream& fout, const char* indent)
  1725. {
  1726. for(std::map<cmStdString, cmStdString>::iterator m = this->FlagMap.begin();
  1727. m != this->FlagMap.end(); ++m)
  1728. {
  1729. fout << indent << m->first << "=\"" << m->second << "\"\n";
  1730. }
  1731. }
  1732. //----------------------------------------------------------------------------
  1733. void
  1734. cmLocalVisualStudio7GeneratorOptions
  1735. ::OutputAdditionalOptions(std::ostream& fout,
  1736. const char* prefix,
  1737. const char* suffix)
  1738. {
  1739. if(!this->FlagString.empty())
  1740. {
  1741. fout << prefix << "AdditionalOptions=\"";
  1742. fout <<
  1743. cmLocalVisualStudio7GeneratorEscapeForXML(this->FlagString.c_str());
  1744. fout << "\"" << suffix;
  1745. }
  1746. }
  1747. void cmLocalVisualStudio7Generator::
  1748. GetTargetObjectFileDirectories(cmTarget* target,
  1749. std::vector<std::string>&
  1750. dirs)
  1751. {
  1752. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1753. dir += "/";
  1754. dir += this->GetTargetDirectory(*target);
  1755. dir += "/";
  1756. dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory();
  1757. dirs.push_back(dir);
  1758. }