diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-16 18:39:35 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-16 18:39:35 +0200 |
commit | 1139fc0aa0869485566c0c3ed0c9f2d2ecf00cb4 (patch) | |
tree | 9dd6022290a92803be4de438aaed7b70290a08cd /include/ouroboros/wrap/CMakeLists.txt | |
parent | fbc0b71d3947cb6047e3e710d606ffc6a39778bc (diff) | |
download | ouroboros-1139fc0aa0869485566c0c3ed0c9f2d2ecf00cb4.tar.gz ouroboros-1139fc0aa0869485566c0c3ed0c9f2d2ecf00cb4.zip |
lib: Add wrappers for Python
This adds SWIG to the build and wraps the Ouroboros library so that it
can be called through Python scripts. If either SWIG or Python cannot
be found, no bindings are generated.
Diffstat (limited to 'include/ouroboros/wrap/CMakeLists.txt')
-rw-r--r-- | include/ouroboros/wrap/CMakeLists.txt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/ouroboros/wrap/CMakeLists.txt b/include/ouroboros/wrap/CMakeLists.txt new file mode 100644 index 00000000..39737bbc --- /dev/null +++ b/include/ouroboros/wrap/CMakeLists.txt @@ -0,0 +1,42 @@ +find_package(SWIG) + +if (NOT SWIG_FOUND) + message("-- SWIG not found: Bindings for other languages disabled.") +else () + include(${SWIG_USE_FILE}) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + set(CMAKE_SWIG_FLAGS "") + + find_package(PythonLibs) + if (NOT PYTHONLIBS_FOUND) + message("-- Python not found: Python bindings will not be built.") + else () + include_directories(${PYTHON_INCLUDE_PATH}) + + swig_add_module(ouroboros python ouroboros.i) + swig_link_libraries(ouroboros ${PYTHON_LIBRARIES} ouroboros) + + # Installation directives + if (CMAKE_INSTALL_PREFIX STREQUAL "") + execute_process( + COMMAND python -c "from distutils import sysconfig; print(sysconfig.get_python_lib())" + OUTPUT_VARIABLE PYTHON_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) + else () + execute_process( + COMMAND python -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" + OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) + get_filename_component(_ABS_PYTHON_MODULE_PATH + ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) + file(RELATIVE_PATH PYTHON_MODULE_PATH + ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) + endif () + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${SWIG_MODULE_ouroboros_REAL_NAME}.so + DESTINATION ${PYTHON_MODULE_PATH}) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ouroboros.py + DESTINATION ${PYTHON_MODULE_PATH}) + endif () +endif () |