packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmIncludeExternalMSProjectCommand.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 "cmIncludeExternalMSProjectCommand.h"
13
14 // cmIncludeExternalMSProjectCommand
15 bool cmIncludeExternalMSProjectCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
17 {
18   if(args.size() < 2)
19   {
20   this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
21                  "number of arguments");
22   return false;
23   }
24 // only compile this for win32 to avoid coverage errors
25 #ifdef _WIN32
26   if(this->Makefile->GetDefinition("WIN32"))
27     {
28     enum Doing { DoingNone, DoingType, DoingGuid, DoingPlatform };
29
30     Doing doing = DoingNone;
31
32     std::string customType;
33     std::string customGuid;
34     std::string platformMapping;
35
36     std::vector<std::string> depends;
37     for (unsigned int i=2; i<args.size(); ++i)
38       {
39       if (args[i] == "TYPE")
40         {
41         doing = DoingType;
42         }
43       else if (args[i] == "GUID")
44         {
45         doing = DoingGuid;
46         }
47       else if (args[i] == "PLATFORM")
48         {
49         doing = DoingPlatform;
50         }
51       else
52         {
53         switch (doing)
54           {
55           case DoingNone: depends.push_back(args[i]);    break;
56           case DoingType: customType = args[i];          break;
57           case DoingGuid: customGuid = args[i];          break;
58           case DoingPlatform: platformMapping = args[i]; break;
59           }
60         doing = DoingNone;
61         }
62       }
63
64     // Hack together a utility target storing enough information
65     // to reproduce the target inclusion.
66     std::string utility_name = args[0];
67
68     std::string path = args[1];
69     cmSystemTools::ConvertToUnixSlashes(path);
70
71     if (!customGuid.empty())
72       {
73       std::string guidVariable = utility_name + "_GUID_CMAKE";
74       this->Makefile->GetCMakeInstance()->AddCacheEntry(
75         guidVariable.c_str(), customGuid.c_str(),
76         "Stored GUID", cmCacheManager::INTERNAL);
77       }
78
79     // Create a target instance for this utility.
80     cmTarget* target=this->Makefile->AddNewTarget(cmTarget::UTILITY,
81                                                   utility_name.c_str());
82
83     target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
84     target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
85     target->SetProperty("EXCLUDE_FROM_ALL", "FALSE");
86
87     if (!customType.empty())
88       target->SetProperty("VS_PROJECT_TYPE",customType.c_str());
89     if (!platformMapping.empty())
90       target->SetProperty("VS_PLATFORM_MAPPING",platformMapping.c_str());
91
92     for (std::vector<std::string>::const_iterator it = depends.begin();
93          it != depends.end();
94          ++it)
95       {
96       target->AddUtility(it->c_str());
97       }
98     }
99 #endif
100   return true;
101 }