cmLocalVisualStudio7Generator.cxx 58 KB

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