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