Subject: [UFC-dev] Another try for build system

From: Johan Hake <[email-masked]>
Date: Wed, 14 Jan 2009 14:20:32 +0100

Hello!

Please try the handed patch. It relates to the latest ufc version from the 
repository.

Johan
# HG changeset patch
# User "Johan Hake <[email-masked]>"
# Date 1231939081 -3600
# Node ID c9922973b3beab4f2405c75d7ddcfa863add463f
# Parent  52f3e7878563b1fbc3b68d0e7b10a976fae601cc
Added a more robus test for both swig and boost.
Added new features to Changelog

diff -r 52f3e7878563 -r c9922973b3be AUTHORS
--- a/AUTHORS	Wed Jan 14 08:37:50 2009 +0100
+++ b/AUTHORS	Wed Jan 14 14:18:01 2009 +0100
@@ -10,3 +10,4 @@
 
     Asmund Odegard         <[email-masked]>
     Kristian Oelgaard      <[email-masked]>
+    Johan Hake             <[email-masked]>
diff -r 52f3e7878563 -r c9922973b3be ChangeLog
--- a/ChangeLog	Wed Jan 14 08:37:50 2009 +0100
+++ b/ChangeLog	Wed Jan 14 14:18:01 2009 +0100
@@ -1,3 +1,7 @@
+ - The swig generated extension module will be compiled with shared_ptr support if boost is found on system and swig is of version 1.3.35 or higher
+ - The swig generated extension module is named ufc.py and expose all ufc base classes to python
+ - Added a swig generated extention module to ufc. UFC now depends on swig
+ - Changed name of the python utility module from "ufc" to "ufc_utils"
 1.1 [2008-02-18]
  - Add new function ufc::finite_element::evaluate_dofs
  - Add new function ufc::finite_element::evaluate_basis_all
diff -r 52f3e7878563 -r c9922973b3be setup.py
--- a/setup.py	Wed Jan 14 08:37:50 2009 +0100
+++ b/setup.py	Wed Jan 14 14:18:01 2009 +0100
@@ -4,7 +4,7 @@
 from distutils import sysconfig
 from os.path import join as pjoin
 from os.path import pardir
-import sys, os
+import sys, os, re
 
 # Taken from http://ivory.idyll.org/blog/mar-07/replacing-commands-with-subprocess
 from subprocess import Popen, PIPE, STDOUT
@@ -40,35 +40,64 @@
 # FIXME: better way for this? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 file.close()
 
-# Checking for boost installation uses pkg-config
-# If no boost installation is found compiled the ufc extension module
-# without shared_ptr support
+# Check for swig installation
+result, output = get_status_output("swig -version")
+if result == 1:
+    raise OSError, "Could not find swig installation. Please install swig version 1.3.35 or higher"
 
-# Set pkg-config to always include system flags
-env = os.environ.copy()
-try:
-    assert env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] == "0"
-except:
-    env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "1"
+# Check swig version
+swig_version = re.findall(r"SWIG Version ([0-9.]+)",output)[0]
+swig_enough = True
+swig_correct_version = [1,3,35]
+for i, v in enumerate([int(v) for v in swig_version.split(".")]):
+    if swig_correct_version[i] < v:
+        break
+    elif swig_correct_version[i] == v:
+        continue
+    else:
+        swig_enough = False
+        print """*** Warning: Your swig version need to be 1.3.35 or higher.
+Python extension module will be compiled without shared_ptr support"""
+    
+# Set a default swig command and boost include directory
+swig_cmd = "swig -python -c++ -O -I. -DNO_SHARED_PTR ufc.i"
+boost_include_dir = []
 
-# Check if pkg-config is installed
-result, output = get_status_output("pkg-config --version ")
-if result != 0: 
-    raise OSError("The pkg-config package is not installed on the system.")
+# If swig version 1.3.35 or higher we check for boost installation
+if swig_enough:
+    # Set a default directory for the boost installation
+    if sys.platform == "darwin":
+        # use fink as default
+        default = os.path.join(os.path.sep,"sw")
+    else:
+        default = os.path.join(os.path.sep,"usr")
+    
+    # If BOOST_DIR is not set use default directory
+    boost_dir = os.getenv("BOOST_DIR", default)
+    boost_is_found = False
+    for inc_dir in ["", "include"]:
+        if os.path.isfile(pjoin(boost_dir, inc_dir, "boost", "version.hpp")):
+            boost_include_dir = [pjoin(boost_dir, inc_dir)]
+            boost_is_found = True
+            break
+    
+    if boost_is_found:
+        print "Using Boost installation in: %s"%boost_include_dir[0]
+        swig_cmd = "swig -python -c++ -O -I. ufc.i"
+    else:
+        # If no boost installation is found compile the ufc extension module
+        # without shared_ptr support
+        print """*** Warning: Boost was not found.
+--------------------------------------------------------------    
+Python extension module compiled without shared_ptr support
 
-# Check if boost is installed
-result, output = get_status_output("pkg-config --exists boost")
-if result == 0:
-    boost_include_dir = [get_status_output("pkg-config --cflags-only-I boost",env=env)[1][2:]]
-    swig_cmd = "swig -python -c++ -fcompact -O -I. -small ufc.i"
-else:
-    print "*** Warning: Boost was not found. Python extension module compiled without shared_ptr support"
-    boost_include_dir = []
-    swig_cmd = "swig -python -c++ -fcompact -O -I. -DNO_SHARED_PTR -small ufc.i"
+If boost is installed on your system you can specify the path
+by setting the environment variable BOOST_DIR.
+--------------------------------------------------------------"""
     
 # Run swig on the ufc.i file
 os.chdir(pjoin("src","ufc"))
-print "Running swig command"
+print "running swig command"
 print swig_cmd
 os.system(swig_cmd)
 os.chdir(os.pardir); os.chdir(os.pardir)
diff -r 52f3e7878563 -r c9922973b3be src/ufc/ufc.i
--- a/src/ufc/ufc.i	Wed Jan 14 08:37:50 2009 +0100
+++ b/src/ufc/ufc.i	Wed Jan 14 14:18:01 2009 +0100
@@ -2,13 +2,20 @@
 
 %{
 #include <ufc.h>
+%}
+#ifndef NO_SHARED_PTR
+// Handle shared_ptr only available for swig version >= 1.3.34
+#if SWIG_VERSION >= 0x010334
 // If using std::tr1::shared_ptr comment out this line
+%{
 #include <boost/shared_ptr.hpp>
 // Un comment these lines to use std::tr1, only works with swig version  >= 1.3.37
 //#include <tr1/memory>
 %}
+#endif
+#endif
 
-
+#ifndef NO_SHARED_PTR
 // Handle shared_ptr only available for swig version >= 1.3.34
 #if SWIG_VERSION >= 0x010334
 // Un comment these lines to use std::tr1, only works with swig version  >= 1.3.37
@@ -22,7 +29,8 @@
 SWIG_SHARED_PTR(cell_integral,ufc::cell_integral)
 SWIG_SHARED_PTR(exterior_facet_integral,ufc::exterior_facet_integral)
 SWIG_SHARED_PTR(interior_facet_integral,ufc::interior_facet_integral)
+#endif
+#endif
 
 %include ufc.h
 
-#endif

---

From: "Garth N. Wells" <[email-masked]>
Date: Wed, 14 Jan 2009 18:48:08 +0000

> Please try the handed patch. It relates to the latest ufc version from the 

Works for me.

Garth

> Johan
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> UFC-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufc-dev

-- 
Dr Garth N Wells
Department of Engineering
University of Cambridge
Trumpington Street
Cambridge CB2 1PZ
United Kingdom

tel.   +44 1223 3 32743
fax.   +44 1223 3 32662
e-mail [email-masked]

---

From: Johan Hake <[email-masked]>
Date: Wed, 14 Jan 2009 19:55:20 +0100

On Wednesday 14 January 2009 19:48:08 Garth N. Wells wrote:
> Johan Hake wrote:
> > Hello!
> >
> > Please try the handed patch. It relates to the latest ufc version from
> > the repository.
>
> Works for me.

Good! 

Can someone push it so we can see what the mac buildbot says?

Johan