1
# jhbuild - a build script for GNOME 1.x and 2.x
2
# Copyright (C) 2001-2006 James Henstridge
4
# cmake.py: cmake module type definitions.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from jhbuild.errors import BuildStateError
25
from jhbuild.modtypes import \
26
Package, DownloadableModule, get_dependencies, get_branch, register_module_type
28
__all__ = [ 'CMakeModule' ]
30
class CMakeModule(Package, DownloadableModule):
31
"""Base type for modules that use CMake build system."""
34
PHASE_CHECKOUT = DownloadableModule.PHASE_CHECKOUT
35
PHASE_FORCE_CHECKOUT = DownloadableModule.PHASE_FORCE_CHECKOUT
36
PHASE_CONFIGURE = 'configure'
39
PHASE_INSTALL = 'install'
41
def __init__(self, name, branch, dependencies=[], after=[], suggests=[]):
42
Package.__init__(self, name, dependencies, after, suggests)
45
def get_srcdir(self, buildscript):
46
return self.branch.srcdir
48
def get_builddir(self, buildscript):
49
if buildscript.config.buildroot:
50
d = buildscript.config.builddir_pattern % (
51
os.path.basename(self.get_srcdir(buildscript)))
52
return os.path.join(buildscript.config.buildroot, d)
54
return self.get_srcdir(buildscript)
56
def get_revision(self):
57
return self.branch.tree_id()
59
def skip_configure(self, buildscript, last_phase):
60
return buildscript.config.nobuild
62
def do_configure(self, buildscript):
63
buildscript.set_action(_('Configuring'), self)
64
srcdir = self.get_srcdir(buildscript)
65
builddir = self.get_builddir(buildscript)
66
if not os.path.exists(builddir):
68
prefix = os.path.expanduser(buildscript.config.prefix)
69
cmd = ['cmake', '-DCMAKE_INSTALL_PREFIX=%s' % prefix, srcdir]
70
buildscript.execute(cmd, cwd = builddir, extra_env = self.extra_env)
71
do_configure.depends = [PHASE_CHECKOUT]
72
do_configure.error_phases = [PHASE_FORCE_CHECKOUT]
74
def do_build(self, buildscript):
75
buildscript.set_action(_('Building'), self)
76
builddir = self.get_builddir(buildscript)
77
buildscript.execute(os.environ.get('MAKE', 'make'), cwd = builddir,
78
extra_env = self.extra_env)
79
do_build.depends = [PHASE_CONFIGURE]
80
do_build.error_phases = [PHASE_FORCE_CHECKOUT]
82
def do_dist(self, buildscript):
83
buildscript.set_action(_('Creating tarball for'), self)
84
cmd = '%s package_source' % os.environ.get('MAKE', 'make')
85
buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
86
extra_env = self.extra_env)
87
do_dist.depends = [PHASE_CONFIGURE]
88
do_dist.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
90
def do_install(self, buildscript):
91
buildscript.set_action(_('Installing'), self)
92
builddir = self.get_builddir(buildscript)
93
buildscript.execute([os.environ.get('MAKE', 'make'), 'install'],
95
extra_env = self.extra_env)
96
buildscript.packagedb.add(self.name, self.get_revision() or '')
97
do_install.depends = [PHASE_BUILD]
99
def xml_tag_and_attrs(self):
100
return 'cmake', [('id', 'name', None)]
103
def parse_cmake(node, config, uri, repositories, default_repo):
104
id = node.getAttribute('id')
105
dependencies, after, suggests = get_dependencies(node)
106
branch = get_branch(node, repositories, default_repo, config)
108
return CMakeModule(id, branch, dependencies = dependencies, after = after,
111
register_module_type('cmake', parse_cmake)