[jhbuild] Support for passing custom arguments to CMake projects (GNOME bug 628339)



commit aa564775b5c26527c5ff1d5ad8db8a3565d4dff2
Author: Nicolas Dufresne <nicolas dufresne collabora co uk>
Date:   Wed Sep 1 09:53:15 2010 +0200

    Support for passing custom arguments to CMake projects (GNOME bug 628339)
    
    This adds a possible cmakeargs attribute to cmake nodes, as well as
    cmakeargs and module_cmakeargs as configuration options.

 jhbuild/config.py          |    3 +-
 jhbuild/defaults.jhbuildrc |    2 +
 jhbuild/modtypes/cmake.py  |   63 +++++++++++++++++++++++++++++++++++++-------
 modulesets/moduleset.dtd   |    1 +
 modulesets/moduleset.rnc   |    1 +
 5 files changed, 59 insertions(+), 11 deletions(-)
---
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 225d9d0..1565568 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -55,7 +55,8 @@ _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'jhbuildbot_slaves_dir', 'jhbuildbot_dir',
                 'jhbuildbot_mastercfg', 'use_local_modulesets',
                 'ignore_suggests', 'modulesets_dir', 'mirror_policy',
-                'module_mirror_policy', 'dvcs_mirror_dir', 'build_targets' ]
+                'module_mirror_policy', 'dvcs_mirror_dir', 'build_targets',
+                'cmakeargs', 'module_cmakeargs' ]
 
 env_prepends = {}
 def prependpath(envvar, path):
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index 9e97726..54242b6 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -45,6 +45,7 @@ builddir_pattern = '%s'
 
 # override environment variables, command line arguments, etc
 autogenargs = '--disable-static --disable-gtk-doc'
+cmakeargs = ''
 makeargs = ''
 cflags = ''
 
@@ -62,6 +63,7 @@ cvsroots = {}
 svnroots = {}
 branches = {}
 module_autogenargs = {}
+module_cmakeargs = {}
 module_makeargs = {}
 module_extra_env = {}
 module_makecheck = {}
diff --git a/jhbuild/modtypes/cmake.py b/jhbuild/modtypes/cmake.py
index 4b628cb..0c86a49 100644
--- a/jhbuild/modtypes/cmake.py
+++ b/jhbuild/modtypes/cmake.py
@@ -38,9 +38,12 @@ class CMakeModule(Package, DownloadableModule):
     PHASE_DIST = 'dist'
     PHASE_INSTALL = 'install'
 
-    def __init__(self, name, branch, dependencies=[], after=[], suggests=[]):
+    def __init__(self, name, branch, cmakeargs='', makeargs='',
+                 dependencies=[], after=[], suggests=[]):
         Package.__init__(self, name, dependencies, after, suggests)
         self.branch = branch
+        self.cmakeargs = cmakeargs
+        self.makeargs  = makeargs
 
     def get_srcdir(self, buildscript):
         return self.branch.srcdir
@@ -56,6 +59,27 @@ class CMakeModule(Package, DownloadableModule):
     def get_revision(self):
         return self.branch.tree_id()
 
+    def eval_args(self, args):
+        args = args.replace('${prefix}', self.config.prefix)
+        libsubdir = 'lib'
+        if self.config.use_lib64:
+            libsubdir = 'lib64'
+        libdir = os.path.join(self.config.prefix, libsubdir)
+        args = args.replace('${libdir}', libdir)
+        return args
+
+    def get_cmakeargs(self):
+        args = '%s %s' % (self.cmakeargs,
+                          self.config.module_cmakeargs.get(
+                              self.name, self.config.cmakeargs))
+        return self.eval_args(args)
+
+    def get_makeargs(self):
+        args = '%s %s' % (self.makeargs,
+                          self.config.module_makeargs.get(
+                              self.name, self.config.makeargs))
+        return self.eval_args(args)
+
     def skip_configure(self, buildscript, last_phase):
         return buildscript.config.nobuild
 
@@ -66,10 +90,9 @@ class CMakeModule(Package, DownloadableModule):
         if not os.path.exists(builddir):
             os.mkdir(builddir)
         prefix = os.path.expanduser(buildscript.config.prefix)
-        cmd = ['cmake', '-DCMAKE_INSTALL_PREFIX=%s' % prefix,
-               '-DLIB_INSTALL_DIR=%s' % buildscript.config.libdir,
-               '-Dlibdir=%s' % buildscript.config.libdir,
-               srcdir]
+        baseargs = '-DCMAKE_INSTALL_PREFIX=%s -DLIB_INSTALL_DIR=%s -Dlibdir=%s' % (
+                        prefix, buildscript.config.libdir, buildscript.config.libdir)
+        cmd = 'cmake %s %s %s' % (baseargs, self.get_cmakeargs(), srcdir)
         if os.path.exists(os.path.join(builddir, 'CMakeCache.txt')):
             # remove that file, as it holds the result of a previous cmake
             # configure run, and would be reused unconditionnaly
@@ -79,17 +102,27 @@ class CMakeModule(Package, DownloadableModule):
     do_configure.depends = [PHASE_CHECKOUT]
     do_configure.error_phases = [PHASE_FORCE_CHECKOUT]
 
+    def do_clean(self, buildscript):
+        buildscript.set_action(_('Cleaning'), self)
+        cmd = '%s %s clean' % (os.environ.get('MAKE', 'make'), makeargs)
+        buildscript.execute(cmd, cwd = builddir,
+                extra_env = self.extra_env)
+    do_clean.depends = [PHASE_CONFIGURE]
+    do_clean.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
+
     def do_build(self, buildscript):
         buildscript.set_action(_('Building'), self)
         builddir = self.get_builddir(buildscript)
-        buildscript.execute(os.environ.get('MAKE', 'make'), cwd = builddir,
+        cmd = '%s %s' % (os.environ.get('MAKE', 'make'), self.get_makeargs())
+        buildscript.execute(cmd, cwd = builddir,
                 extra_env = self.extra_env)
     do_build.depends = [PHASE_CONFIGURE]
     do_build.error_phases = [PHASE_FORCE_CHECKOUT]
 
     def do_dist(self, buildscript):
         buildscript.set_action(_('Creating tarball for'), self)
-        cmd = '%s package_source' % os.environ.get('MAKE', 'make')
+        cmd = '%s %s package_source' % (os.environ.get('MAKE', 'make'),
+                self.get_makeargs())
         buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
                 extra_env = self.extra_env)
     do_dist.depends = [PHASE_CONFIGURE]
@@ -98,7 +131,9 @@ class CMakeModule(Package, DownloadableModule):
     def do_install(self, buildscript):
         buildscript.set_action(_('Installing'), self)
         builddir = self.get_builddir(buildscript)
-        buildscript.execute([os.environ.get('MAKE', 'make'), 'install'],
+        cmd = '%s %s install' % (os.environ.get('MAKE', 'make'),
+                self.get_makeargs())
+        buildscript.execute(cmd,
                 cwd = builddir,
                 extra_env = self.extra_env)
         buildscript.packagedb.add(self.name, self.get_revision() or '')
@@ -110,11 +145,19 @@ class CMakeModule(Package, DownloadableModule):
 
 def parse_cmake(node, config, uri, repositories, default_repo):
     id = node.getAttribute('id')
+    cmakeargs = ''
+    makeargs = ''
+    if node.hasAttribute('cmakeargs'):
+        cmakeargs = node.getAttribute('cmakeargs')
+    if node.hasAttribute('makeargs'):
+        makeargs = node.getAttribute('makeargs')
+
     dependencies, after, suggests = get_dependencies(node)
     branch = get_branch(node, repositories, default_repo, config)
 
-    return CMakeModule(id, branch, dependencies = dependencies, after = after,
-            suggests = suggests)
+    return CMakeModule(id, branch, cmakeargs, makeargs,
+                       dependencies = dependencies, after = after,
+                       suggests = suggests)
 
 register_module_type('cmake', parse_cmake)
 
diff --git a/modulesets/moduleset.dtd b/modulesets/moduleset.dtd
index cda42c8..b7f5794 100644
--- a/modulesets/moduleset.dtd
+++ b/modulesets/moduleset.dtd
@@ -80,6 +80,7 @@
 <!ELEMENT cmake (branch?,dependencies?,after?)>
 <!ATTLIST cmake
 	id		CDATA	#REQUIRED
+	cmakeargs	CDATA	#IMPLIED>
 	makeargs	CDATA	#IMPLIED>
 
 <!ELEMENT perl (branch?,dependencies?,after?)>
diff --git a/modulesets/moduleset.rnc b/modulesets/moduleset.rnc
index 8901dec..2c75b6b 100644
--- a/modulesets/moduleset.rnc
+++ b/modulesets/moduleset.rnc
@@ -128,6 +128,7 @@ attlist.distutils &=
 cmake = element cmake { attlist.cmake, branch?, dependencies?, after? }
 attlist.cmake &=
   attribute id { text },
+  attribute cmakeargs { text }?
   attribute makeargs { text }?
 perl = element perl { attlist.perl, branch?, dependencies?, after? }
 attlist.perl &=



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]