Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / build / buildman / bin / bmplugins / CreateSolutionPlugIn.py @ 27363

History | View | Annotate | Download (4.51 KB)

1 27363 rgaitan
from bmbase.IPlugIn import IPlugIn
2
from bmbase.PlugInManager import PlugInManager
3
from bmcore.BMUtil import BMUtil
4
import os
5
6
class CreateSolutionPlugIn(IPlugIn):
7
        def __init__(self):
8
                IPlugIn.__init__(self)
9
                self._buildType = "Release"
10
                self._supportedGenerators = dict()
11
                self._supportedGenerators["vs8"] = "Visual Studio 8 2005"
12
                self._supportedGenerators["vs7"] = "Visual Studio 7 .NET 2003"
13
                self._supportedGenerators["unix"] = "Unix Makefiles"
14
                self._supportedGenerators["xcode"] = "Xcode"
15
                self._cmakeGenerator = ""
16
                self._projectPath = ""
17
                self._projectGenerationPath = ""
18
                self._installPath = ""
19
                self._cmakeOtherOptions = ""
20
21
22
        def init(self):
23
                self.addGoal("create-solution", "Creates the solution Makefiles/VisualStudio for Win/Linux/Mac based on CMake")
24
                self.addGoalOption("create-solution","--build-type", "sets the build path (Release/Debug). default=Release.")
25
                self.addGoalOption("create-solution","--generator", "selects the generator (vs8,vs7,unix,xcode).")
26
                self.addGoalOption("create-solution","--project-path", "sets the path of the project.")
27
                self.addGoalOption("create-solution","--project-gen-path", "sets the path to generate project files. default=${project-path}/CMake")
28
                self.addGoalOption("create-solution","--install", "sets the path to generate the product installation. default=${project-path}/../install")
29
                self.addGoalOption("create-solution","--cmake-options", "Adds other cmake command line options.")
30
                execute = False
31
                if self._arguments.read("create-solution"):
32
                        execute = True
33
                if execute:
34
                        args = [""]
35
                        if self._arguments.read("--build-type",args):
36
                                self._buildType = args[0]
37
38
                        args = [""]
39
                        if self._arguments.read("--generator",args):
40
                                if args[0] in self._supportedGenerators:
41
                                        self._cmakeGenerator = self._supportedGenerators[args[0]]
42
43
                        args = [""]
44
                        if self._arguments.read("--project-path",args):
45
                                self._projectPath=args[0]
46
47
                        args = [""]
48
                        if self._arguments.read("--project-gen-path",args):
49
                                self._projectGenerationPath=args[0]
50
51
                        args = [""]
52
                        if self._arguments.read("--install",args):
53
                                self._installPath=args[0]
54
55
                        args = [""]
56
                        if self._arguments.read("--cmake-options",args):
57
                                self._cmakeOtherOptions=args[0]
58
59
                        self.setExecute(True)
60
61
        def initFromXML(self,node):
62
                if node.localName=="create-solution":
63
                        if node.hasAttributes():
64
                                if node.attributes.has_key("build-type"):
65
                                        self._buildType = node.attributes.get("build-type").value
66
                                if node.attributes.has_key("generator"):
67
                                        gen = node.attributes.get("generator").value
68
                                        if gen in self._supportedGenerators:
69
                                                self._cmakeGenerator = self._supportedGenerators[gen]
70
                                if node.attributes.has_key("project-path"):
71
                                        self._projectPath = node.attributes.get("project-path").value
72
                                if node.attributes.has_key("project-gen-path"):
73
                                        self._projectGenerationPath = os.path.abspath(node.attributes.get("project-gen-path").value)
74
                                if node.attributes.has_key("install"):
75
                                        self._installPath = os.path.abspath(node.attributes.get("install").value)
76
                                if node.attributes.has_key("cmake-options"):
77
                                        self._cmakeOtherOptions = node.attributes.get("cmake-options").value
78
79
        def execute(self):
80
                if self._cmakeGenerator=="":
81
                        self.reportError("Missing valid generator option")
82
                        return False
83
                if self._projectPath=="":
84
                        self.reportError("Missing required project path option")
85
                        return False
86
87
                if self._cmakeGenerator!="" and self._projectPath!="":
88
                        self._projectPath = os.path.abspath(self._projectPath)
89
                        projectName = os.path.basename(self._projectPath)
90
                        if self._projectGenerationPath=="":
91
                                self._projectGenerationPath=os.path.abspath(os.path.join(self._projectPath,"BMCMake"))
92
                        if self._installPath=="":
93
                                self._installPath=os.path.abspath(self._projectPath+os.path.sep+".."+os.path.sep+projectName+"-install")
94
                        if self._buildType=="":
95
                                self._buildType="Release"
96
97
                print "Executing Plugin:" + str(self.__class__)
98
                bmutil = BMUtil()
99
                print " * Creating Project Generation Path: "+self._projectGenerationPath
100
                bmutil.mkdir(self._projectGenerationPath)
101
                olddir = os.getcwd()
102
                os.chdir(self._projectGenerationPath)
103
                if os.path.exists("CMakeCache.txt"):
104
                        os.remove("CMakeCache.txt")
105
                cmakeCommand = "cmake "+self._cmakeOtherOptions+" -G\""+self._cmakeGenerator+"\" -DCMAKE_BUILD_TYPE="+self._buildType+" -DCMAKE_INSTALL_PREFIX="+self._installPath+" "+self._projectPath
106
                print " * Running CMAKE: " + cmakeCommand
107
                os.system(cmakeCommand)
108
                os.chdir(olddir)
109
                return True
110
111
PlugInManager().registerPlugIn("CreateSolutionPlugIn",CreateSolutionPlugIn())
112