[cig-commits] commit: OpenGL wasn't correctly determining if it

Mercurial hg at geodynamics.org
Mon Nov 24 11:27:48 PST 2008


changeset:   6:6d19af17c83f
user:        LukeHodkinson
date:        Wed Jun 25 03:09:08 2008 +0000
files:       SConfig/Configuration.py SConfig/Installation.py SConfig/Package.py SConfig/packages/OpenGL.py
description:
OpenGL wasn't correctly determining if it
contains a valid glx implementation.


diff -r d5a17843a952 -r 6d19af17c83f SConfig/Configuration.py
--- a/SConfig/Configuration.py	Tue Jun 24 04:17:12 2008 +0000
+++ b/SConfig/Configuration.py	Wed Jun 25 03:09:08 2008 +0000
@@ -17,6 +17,14 @@ class Configuration:
         # static/shared libraries available.
         self.has_static = None
         self.has_shared = None
+
+        # Preprocessor definitions.
+        self.cpp_defines = []
+
+        # This list provides a way of modifying the printed output of
+        # a configuration without needing to replace the print method.
+        self.outputs = [('Static libraries: %s', 'has_static'),
+                        ('Shared libraries: %s', 'has_shared')]
 
     def __eq__(self, cfg):
         if not (self.inst == cfg.inst):
@@ -46,6 +54,11 @@ class Configuration:
                          libs=self.libs,
                          has_shared=self.has_shared,
                          lib_exclude=lib_exclude)
+
+        # Throw in any preprocessor stuff.
+        if self.cpp_defines:
+            self.inst.pkg.backup_variable(scons_env, 'CPPDEFINES', old_state)
+            scons_env.AppendUnique(CPPDEFINES=self.cpp_defines)
 
     def enable_dependencies(self, scons_env, old_state={}, lib_exclude=[]):
         """Enables all available dependencies."""
@@ -84,11 +97,11 @@ class Configuration:
         # Get the installation's string first.
         txt = str(self.inst)
 
-        # Add information about libraries.
-        if self.has_static is not None:
-            txt += '  Static libraries: %s\n' % str(self.has_static)
-        if self.has_shared is not None:
-            txt += '  Shared libraries: %s\n' % str(self.has_shared)
+        # Print out our outputs.
+        for out in self.outputs:
+            line = out[0]
+            vals = tuple([getattr(self, v) for v in out[1:]])
+            txt += ('  ' + line + '\n') % vals
 
         # Now produce the dependency text.
         dep_txt = ''
diff -r d5a17843a952 -r 6d19af17c83f SConfig/Installation.py
--- a/SConfig/Installation.py	Tue Jun 24 04:17:12 2008 +0000
+++ b/SConfig/Installation.py	Wed Jun 25 03:09:08 2008 +0000
@@ -209,6 +209,19 @@ class Installation:
                     if os.path.exists(path):
                         found_libs += [path]
         return found_libs
+
+    def find_header(self, hdr):
+        """Using the search paths we know about, try and locate the files corresponding
+        to the header name(s) given."""
+
+        hdrs = self.pkg.env.make_list(hdr)
+        found_hdrs = []
+        for h in hdrs:
+            for hdr_dir in self.hdr_dirs:
+                path = os.path.join(self.base_dir, hdr_dir, h)
+                if os.path.exists(path):
+                    found_hdrs += [path]
+        return found_hdrs
 
     def __str__(self):
         """Convert to printable string."""
diff -r d5a17843a952 -r 6d19af17c83f SConfig/Package.py
--- a/SConfig/Package.py	Tue Jun 24 04:17:12 2008 +0000
+++ b/SConfig/Package.py	Wed Jun 25 03:09:08 2008 +0000
@@ -77,8 +77,10 @@ class Package(SConfig.Node):
         # platform we're running on.
         self.platform = self.dependency(SConfig.Platform, True) 
 
-        # We have one configuration check.
+        # We have one configuration check. We also have the option of adding
+        # candidate checks.
         self.checks = [self.check_candidates]
+        self.candidate_checks = [self.check_headers, self.check_libraries]
 
         # Setup search defaults for the platform we're on.
         self.setup_search_defaults()
@@ -316,8 +318,13 @@ class Package(SConfig.Node):
             print '  Trialing candidate %d of %d ...\r' % (cur, len(self.cand_cfgs)),
             cur = cur + 1
 
-            # Check for the headers and libraries.
-            if self.check_headers(cfg) and self.check_libraries(cfg):
+            # Run all the candidate checks.
+            okay = True
+            for cand_check in self.candidate_checks:
+                if not cand_check(cfg):
+                    okay = False
+                    break
+            if okay:
 
                 # If the checks passed, include the 'have_define' if there and add
                 # this installation to the list.
diff -r d5a17843a952 -r 6d19af17c83f SConfig/packages/OpenGL.py
--- a/SConfig/packages/OpenGL.py	Tue Jun 24 04:17:12 2008 +0000
+++ b/SConfig/packages/OpenGL.py	Wed Jun 25 03:09:08 2008 +0000
@@ -4,7 +4,27 @@ class OpenGL(SConfig.Package):
 class OpenGL(SConfig.Package):
     def __init__(self, scons_env, scons_opts, required=False, **kw):
         SConfig.Package.__init__(self, scons_env, scons_opts, required, **kw)
+        self.base_dirs += ['/usr/X11R6']
         self.header_sub_dir = ['GL']
         self.headers = [['gl.h', 'glu.h']]
         self.libraries = [['GL', 'GLU']]
         self.frameworks = ['OpenGL']
+        self.candidate_checks += [self.check_glx]
+
+        self.require_glx = kw.get('require_glx', False)
+        self.x11 = self.dependency(SConfig.packages.X11, required=self.require_glx)
+
+    def check_glx(self, cfg):
+        """Check if this configuration comes with a glX implementation."""
+
+        # For now we just have a silly header check.
+        paths = cfg.inst.find_header('glx.h')
+        cfg.has_glx = (len(paths) > 0)
+        if cfg.has_glx:
+            cfg.hdrs += ['glx.h']
+            cfg.outputs += [('Has glx: %s', 'has_glx')]
+            cfg.cpp_defines += ['HAVE_GLX']
+
+        if self.require_glx and not paths:
+            return False
+        return True



More information about the CIG-COMMITS mailing list