On 11/21/2012 10:27 PM, Ben wrote:
Hello,

A couple thoughts related to building python bindings with cmake:

1. <build dir>/bindings/swig/python/setup.py has the following line:
#!/usr/bin/python python
Looks like that should just be /usr/bin/python, or /usr/bin/env python?

2. It'd be nice to be able to install the python module to some
non-standard location, so as to not require root access or conflict with
system packages.
<source dir>/bindings/swig/python/install.cmake - I added --user to the
python setup.py install command, and that installed it just to my user
directory. That doesn't require root access, although it still might
conflict some with a system package. Another option might be to just
install the python bindings to the same custom prefix as the sword
library? Not sure what the best way is to implement this option.

I'm attaching a patch that corrects number 1. For number 2, I set it up to allow installing the python Sword module to the user's directory, if -DPYTHON_USER_INSTALL=Yes is passed to the cmake command. If the option's not there, it just operates as normal.

I tried to set it up with running "python setup.py install --home=<dir>", but I didn't get it working with directories with spaces in the path.

Feedback and suggestions are welcome.

Thanks,
-Ben

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (revision 2746)
+++ CMakeLists.txt      (working copy)
@@ -13,7 +13,7 @@
 
 FIND_PACKAGE(PythonInterp REQUIRED)
 
-SET(PY_SCRIPT "#!${PYTHON_EXECUTABLE} python
+SET(PY_SCRIPT "#!${PYTHON_EXECUTABLE}
 
 from distutils.core import setup, Extension
 setup(name='sword',version='${SWORD_VERSION}',
@@ -38,6 +38,28 @@
        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Sword.cxx ${SWORD_LINK_NAME}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 
-INSTALL(SCRIPT install.cmake)
+#add error/output variables
+IF(PYTHON_USER_INSTALL STREQUAL "Yes")
+    SET(INSTALL_CODE 
+        "
+        MESSAGE(\"Running python setup.py install to user directory...\")
+        EXECUTE_PROCESS(COMMAND python setup.py install --user
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+        )
+        "
+    )
+ELSE()
+    SET(INSTALL_CODE 
+        "
+        MESSAGE(\"Running python setup.py install to system directory...\")
+        EXECUTE_PROCESS(COMMAND python setup.py install
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+        )
+        "
+    )
+ENDIF()
+FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/install_script.cmake "${INSTALL_CODE}")
 
+INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/install_script.cmake)
+
 MESSAGE(STATUS "Python: yes")
Index: install.cmake
===================================================================
--- install.cmake       (revision 2746)
+++ install.cmake       (working copy)
@@ -1,4 +0,0 @@
-EXECUTE_PROCESS(COMMAND
-       python setup.py install
-       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bindings/swig/python"
-)
_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Reply via email to