resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmLocalVisualStudio10Generator.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmLocalVisualStudio10Generator.h"
4
5 #include <cm3p/expat.h>
6
7 #include "cmGlobalGenerator.h"
8 #include "cmGlobalVisualStudio10Generator.h"
9 #include "cmGlobalVisualStudioGenerator.h"
10 #include "cmStateTypes.h"
11 #include "cmStringAlgorithms.h"
12 #include "cmVisualStudio10TargetGenerator.h"
13 #include "cmXMLParser.h"
14 #include "cmake.h"
15
16 class cmGeneratorTarget;
17
18 class cmVS10XMLParser : public cmXMLParser
19 {
20 public:
21   virtual void EndElement(const std::string& /* name */) {}
22   virtual void CharacterDataHandler(const char* data, int length)
23   {
24     if (this->DoGUID) {
25       if (data[0] == '{') {
26         // remove surrounding curly brackets
27         this->GUID.assign(data + 1, length - 2);
28       } else {
29         this->GUID.assign(data, length);
30       }
31       this->DoGUID = false;
32     }
33   }
34   virtual void StartElement(const std::string& name, const char**)
35   {
36     // once the GUID is found do nothing
37     if (!this->GUID.empty()) {
38       return;
39     }
40     if ("ProjectGUID" == name || "ProjectGuid" == name) {
41       this->DoGUID = true;
42     }
43   }
44   int InitializeParser()
45   {
46     this->DoGUID = false;
47     int ret = cmXMLParser::InitializeParser();
48     if (ret == 0) {
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   cmGlobalGenerator* gg, cmMakefile* mf)
62   : cmLocalVisualStudio7Generator(gg, mf)
63 {
64 }
65
66 cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
67 {
68 }
69
70 void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target)
71 {
72   if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
73         ->TargetIsFortranOnly(target)) {
74     this->cmLocalVisualStudio7Generator::GenerateTarget(target);
75   } else {
76     cmVisualStudio10TargetGenerator tg(
77       target,
78       static_cast<cmGlobalVisualStudio10Generator*>(
79         this->GetGlobalGenerator()));
80     tg.Generate();
81   }
82 }
83
84 void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
85   const std::string& name, const char* path)
86 {
87   cmVS10XMLParser parser;
88   parser.ParseFile(path);
89
90   // if we can not find a GUID then we will generate one later
91   if (parser.GUID.empty()) {
92     return;
93   }
94
95   std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
96   // save the GUID in the cache
97   this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
98     guidStoreName, parser.GUID.c_str(), "Stored GUID", cmStateEnums::INTERNAL);
99 }
100
101 const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
102 {
103   return ":VCEnd";
104 }