fix gecode version detection
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Sep 2009 16:33:37 +0200
changeset 457 734a8a5abf98
parent 456 42004883d4cd
child 461 86df7aef75ea
fix gecode version detection
MANIFEST.in
__pkginfo__.py
data/gecode_version.cc
--- a/MANIFEST.in	Wed Aug 26 14:30:33 2009 +0200
+++ b/MANIFEST.in	Tue Sep 08 16:33:37 2009 +0200
@@ -11,5 +11,6 @@
 include TODO 
 include ChangeLog
 include DEPENDS
+include data/gecode_version.cc
 
 recursive-include tools *.py *.rql
--- a/__pkginfo__.py	Wed Aug 26 14:30:33 2009 +0200
+++ b/__pkginfo__.py	Tue Sep 08 16:33:37 2009 +0200
@@ -32,11 +32,32 @@
 pyversions = ['2.4']
 
 
+import os, subprocess
 from distutils.core import Extension
 
 include_dirs = []
 
-ext_modules = [ Extension('rql_solve',
-                          ['gecode_solver.cpp'],
-                          libraries=['gecodeint', 'gecodekernel', 'gecodesearch'],
-                          ) ]
+def gecode_version():
+    import os, subprocess
+    version = [0,0,0]
+    if os.path.exists('data/gecode_version.cc'):
+        try:
+            res = os.system("g++ -o gecode_version data/gecode_version.cc")
+            p = subprocess.Popen("./gecode_version",stdout=subprocess.PIPE)
+            vers = p.stdout.read()
+            version = [int(c) for c in vers.strip().split('.')]
+        except OSError:
+            pass
+    return version
+
+def encode_version(a,b,c):
+    return ((a<<16)+(b<<8)+c)
+
+GECODE_VERSION = encode_version(*gecode_version())
+
+ext_modules = [Extension('rql_solve',
+                         ['gecode_solver.cpp'],
+                         libraries=['gecodeint', 'gecodekernel', 'gecodesearch'],
+                         extra_compile_args=['-DGE_VERSION=%s' % GECODE_VERSION],
+                         )
+               ]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/gecode_version.cc	Tue Sep 08 16:33:37 2009 +0200
@@ -0,0 +1,10 @@
+#include "gecode/support.hh"
+#include <stdio.h>
+
+int main() {
+#ifndef GECODE_VERSION
+    printf("2.1.2\n");
+#else
+    printf("%s\n", GECODE_VERSION);
+#endif
+}