cmLocalVisualStudio10Generator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "cmLocalVisualStudio10Generator.h"
  14. #include "cmTarget.h"
  15. #include "cmMakefile.h"
  16. #include "cmVisualStudio10TargetGenerator.h"
  17. #include "cmGlobalVisualStudio7Generator.h"
  18. #include <cm_expat.h>
  19. #include "cmXMLParser.h"
  20. class cmVS10XMLParser : public cmXMLParser
  21. {
  22. public:
  23. virtual void EndElement(const char* /* name */)
  24. {
  25. }
  26. virtual void CharacterDataHandler(const char* data, int length)
  27. {
  28. if(this->DoGUID )
  29. {
  30. this->GUID.assign(data, length);
  31. this->DoGUID = false;
  32. }
  33. }
  34. virtual void StartElement(const char* name, const char**)
  35. {
  36. // once the GUID is found do nothing
  37. if(this->GUID.size())
  38. {
  39. return;
  40. }
  41. if(strcmp("ProjectGUID", name) == 0)
  42. {
  43. this->DoGUID = true;
  44. }
  45. }
  46. int InitializeParser()
  47. {
  48. this->DoGUID = false;
  49. int ret = cmXMLParser::InitializeParser();
  50. if(ret == 0)
  51. {
  52. return ret;
  53. }
  54. // visual studio projects have a strange encoding, but it is
  55. // really utf-8
  56. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  57. return 1;
  58. }
  59. std::string GUID;
  60. bool DoGUID;
  61. };
  62. //----------------------------------------------------------------------------
  63. cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator()
  64. {
  65. this->NeedXMLEscape = true;
  66. }
  67. cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
  68. {
  69. }
  70. void cmLocalVisualStudio10Generator::Generate()
  71. {
  72. cmTargets &tgts = this->Makefile->GetTargets();
  73. // Create the regeneration custom rule.
  74. if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION"))
  75. {
  76. // Create a rule to regenerate the build system when the target
  77. // specification source changes.
  78. if(cmSourceFile* sf = this->CreateVCProjBuildRule())
  79. {
  80. // Add the rule to targets that need it.
  81. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  82. {
  83. if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
  84. {
  85. l->second.AddSourceFile(sf);
  86. }
  87. }
  88. }
  89. }
  90. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  91. {
  92. cmVisualStudio10TargetGenerator tg(&l->second,
  93. (cmGlobalVisualStudio7Generator*)
  94. this->GetGlobalGenerator());
  95. tg.Generate();
  96. }
  97. this->WriteStampFiles();
  98. }
  99. void cmLocalVisualStudio10Generator
  100. ::ReadAndStoreExternalGUID(const char* name,
  101. const char* path)
  102. {
  103. cmVS10XMLParser parser;
  104. parser.ParseFile(path);
  105. std::string guidStoreName = name;
  106. guidStoreName += "_GUID_CMAKE";
  107. // save the GUID in the cache
  108. this->GlobalGenerator->GetCMakeInstance()->
  109. AddCacheEntry(guidStoreName.c_str(),
  110. parser.GUID.c_str(),
  111. "Stored GUID",
  112. cmCacheManager::INTERNAL);
  113. }