cmLocalVisualStudio10Generator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmLocalVisualStudio10Generator.h"
  11. #include "cmMakefile.h"
  12. #include "cmVisualStudio10TargetGenerator.h"
  13. #include "cmGlobalVisualStudio10Generator.h"
  14. #include <cm_expat.h>
  15. #include "cmXMLParser.h"
  16. class cmVS10XMLParser : public cmXMLParser
  17. {
  18. public:
  19. virtual void EndElement(const std::string& /* name */)
  20. {
  21. }
  22. virtual void CharacterDataHandler(const char* data, int length)
  23. {
  24. if(this->DoGUID )
  25. {
  26. this->GUID.assign(data+1, length-2);
  27. this->DoGUID = false;
  28. }
  29. }
  30. virtual void StartElement(const std::string& name, const char**)
  31. {
  32. // once the GUID is found do nothing
  33. if(!this->GUID.empty())
  34. {
  35. return;
  36. }
  37. if("ProjectGUID" == name || "ProjectGuid" == name)
  38. {
  39. this->DoGUID = true;
  40. }
  41. }
  42. int InitializeParser()
  43. {
  44. this->DoGUID = false;
  45. int ret = cmXMLParser::InitializeParser();
  46. if(ret == 0)
  47. {
  48. return ret;
  49. }
  50. // visual studio projects have a strange encoding, but it is
  51. // really utf-8
  52. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  53. return 1;
  54. }
  55. std::string GUID;
  56. bool DoGUID;
  57. };
  58. //----------------------------------------------------------------------------
  59. cmLocalVisualStudio10Generator
  60. ::cmLocalVisualStudio10Generator(cmGlobalGenerator* gg, cmMakefile* mf):
  61. cmLocalVisualStudio7Generator(gg, mf)
  62. {
  63. }
  64. cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
  65. {
  66. }
  67. void cmLocalVisualStudio10Generator::Generate()
  68. {
  69. std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
  70. for(std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
  71. l != tgts.end(); ++l)
  72. {
  73. if((*l)->GetType() == cmState::INTERFACE_LIBRARY)
  74. {
  75. continue;
  76. }
  77. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  78. ->TargetIsFortranOnly(*l))
  79. {
  80. this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
  81. }
  82. else
  83. {
  84. cmVisualStudio10TargetGenerator tg(
  85. *l, static_cast<cmGlobalVisualStudio10Generator*>(
  86. this->GetGlobalGenerator()));
  87. tg.Generate();
  88. }
  89. }
  90. this->WriteStampFiles();
  91. }
  92. void cmLocalVisualStudio10Generator
  93. ::ReadAndStoreExternalGUID(const std::string& name,
  94. const char* path)
  95. {
  96. cmVS10XMLParser parser;
  97. parser.ParseFile(path);
  98. // if we can not find a GUID then we will generate one later
  99. if(parser.GUID.empty())
  100. {
  101. return;
  102. }
  103. std::string guidStoreName = name;
  104. guidStoreName += "_GUID_CMAKE";
  105. // save the GUID in the cache
  106. this->GlobalGenerator->GetCMakeInstance()->
  107. AddCacheEntry(guidStoreName.c_str(),
  108. parser.GUID.c_str(),
  109. "Stored GUID",
  110. cmState::INTERNAL);
  111. }
  112. //----------------------------------------------------------------------------
  113. const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
  114. {
  115. return ":VCEnd";
  116. }