cmLocalVisualStudio10Generator.cxx 3.7 KB

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