Hi!

This is a request for comments. I have implemented bindings only
build for OB Python bindings and would like to hear what others
think about this.

So that don't have to rebuild OB just to add bindings. It allows to,
e.g., test Python bindings against multiple Python versions without
requiring to rebuild OB for each version.

Bindings form separate component to enable their installation using
command like this:
cmake -DCOMPONENT=bindings_python -P cmake_install.cmake

I have not looked at other bindings yet, but I think they should follow
similar approach.

--
In Gentoo we are providing separate packages for bindings and with
distutils it was very simple to build against system installation of OB
with a small change to setup.py:
 obExtension = Extension('_openbabel',
                  [os.path.join(srcdir, "openbabel-python.cpp")],
-                 include_dirs=[os.path.join(srcdir, "..", "..", "include"),
-                               os.path.join("..", "include")],
-                 library_dirs=[os.path.join(srcdir, "..", "..", "lib"),
-                               os.path.join(srcdir, "..", "..", "lib64"),
-                               os.path.join("..", "lib")],
+                 include_dirs=[os.path.join("/usr", "include", 
"openbabel-2.0")],
                  libraries=['openbabel']
                  )

With new build system for bindings it is not quite that straightforward.
---
 CMakeLists.txt         | 13 +++++++++++--
 scripts/CMakeLists.txt | 24 +++++++++++++++++++-----
 test/CMakeLists.txt    | 11 ++++++++---
 3 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 449f4b4..1c9ad00 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -252,7 +252,8 @@ if(NOT MSVC)
     }
    " SCANDIR_NEEDS_CONST)
 
-  set(OB_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${OB_PLUGIN_INSTALL_DIR}")
+  set(OB_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${OB_PLUGIN_INSTALL_DIR}"
+      CACHE PATH "Set to system install for bindings only build")
   add_definitions(-DOB_MODULE_PATH="\\"${OB_MODULE_PATH}\\"")
 
   # Add some visibility support when using GCC
@@ -380,7 +381,8 @@ if(UNIX AND BUILD_SHARED)
   if(APPLE)
     set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR})
   else()
-    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
+    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}"
+        CACHE PATH "Set sane rpath")
     set(CMAKE_SKIP_BUILD_RPATH FALSE)
     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
@@ -477,6 +479,13 @@ endif()
 # Should the language bindings be regenereted?
 option(RUN_SWIG "Generate language bindings with SWIG" OFF)
 
+# Build bindings only
+option(BINDINGS_ONLY "Build bindings only" OFF)
+
+# Point to library if building bindings only
+set(BABEL_SYSTEM_LIBRARY ${BABEL_LIBRARY}
+    CACHE PATH "Point to openbabel library if building bindings only")
+
 # Should all bindings be built?
 option(ALL_BINDINGS "Build all languages bindings" OFF)
 
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index 16e9000..ecd2295 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -92,16 +92,30 @@ if (DO_PYTHON_BINDINGS)
     endif(RUN_SWIG)
 
     add_library(bindings_python MODULE 
${openbabel_SOURCE_DIR}/scripts/python/openbabel-python.cpp)
-    target_link_libraries(bindings_python ${PYTHON_LIBRARIES} ${BABEL_LIBRARY})
+    if(BINDINGS_ONLY)
+        target_link_libraries(bindings_python ${PYTHON_LIBRARIES} 
${BABEL_SYSTEM_LIBRARY})
+    else()
+        target_link_libraries(bindings_python ${PYTHON_LIBRARIES} 
${BABEL_LIBRARY})
+    endif()
+
     if(NOT WIN32)
         set_target_properties(bindings_python PROPERTIES
             OUTPUT_NAME _openbabel
             PREFIX ""
             SUFFIX .so )
-        add_dependencies(bindings_python openbabel)
-        install(TARGETS bindings_python LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-        install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel.py 
DESTINATION ${LIB_INSTALL_DIR})
-        install(FILES ${openbabel_SOURCE_DIR}/scripts/python/pybel.py 
DESTINATION ${LIB_INSTALL_DIR})
+        if(NOT BINDINGS_ONLY)
+            add_dependencies(bindings_python openbabel)
+        endif()
+
+        install(TARGETS bindings_python
+                LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+                COMPONENT bindings_python)
+        install(FILES ${openbabel_SOURCE_DIR}/scripts/python/openbabel.py
+                DESTINATION ${LIB_INSTALL_DIR}
+                COMPONENT bindings_python)
+        install(FILES ${openbabel_SOURCE_DIR}/scripts/python/pybel.py
+                DESTINATION ${LIB_INSTALL_DIR}
+                COMPONENT bindings_python)
     else(NOT WIN32)
         set_target_properties(bindings_python PROPERTIES
             OUTPUT_NAME _openbabel
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index b629c9f..6f3495f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -2,7 +2,12 @@
 add_definitions(-DTESTDATADIR="\\"${CMAKE_SOURCE_DIR}/test/files/\\"")
 
 # define FORMATDIR for location of format plugin binaries
-add_definitions(-DFORMATDIR="\\"${openbabel_BINARY_DIR}/lib${LIB_SUFFIX}/\\"")
+if(BINDINGS_ONLY)
+  set(FORMATDIR "${OB_MODULE_PATH}/")
+else()
+  set(FORMATDIR "${openbabel_BINARY_DIR}/lib${LIB_SUFFIX}/")
+endif()
+add_definitions(-DFORMATDIR="\\"${FORMATDIR}/\\"")
 
 ###########################################################
 #  new tests using obtest.h
@@ -200,7 +205,7 @@ if(NOT MINGW AND NOT CYGWIN)
     foreach(pytest ${pytests})
     SET_SOURCE_FILES_PROPERTIES(test${pytest}.py PROPERTIES
       PYTHONPATH 
"${CMAKE_SOURCE_DIR}/scripts/python:${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}"
-      BABEL_LIBDIR "${CMAKE_BINARY_DIR}/lib${LIB_SYFFIX}"
+      BABEL_LIBDIR "${FORMATDIR}"
       BABEL_DATADIR "${CMAKE_SOURCE_DIR}/data"
       LD_LIBRARY_PATH "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}"
     )
@@ -222,7 +227,7 @@ if (PYTHON_BINDINGS)
   foreach(pybindtest ${pybindtests})
     SET_SOURCE_FILES_PROPERTIES(test${pybindtest}.py PROPERTIES
         PYTHONPATH 
"${CMAKE_SOURCE_DIR}/scripts/python:${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}"
-        BABEL_LIBDIR "${CMAKE_BINARY_DIR}/lib${LIB_SYFFIX}"
+        BABEL_LIBDIR "${FORMATDIR}"
         BABEL_DATADIR "${CMAKE_SOURCE_DIR}/data"
         LD_LIBRARY_PATH "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}"
     )
-- 
1.7.12.3

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to