cmLocalVisualStudio7Generator.cxx 61 KB

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