cmake: add python support

FindCython.cmake was taken from
https://github.com/thewtex/cython-cmake-example. The UseCython module
works, but since it is lacking an installation target setup.py will be
used instead.
This commit is contained in:
Peter Wu
2016-02-16 12:17:49 +01:00
parent f407f7f406
commit 9bc6dc7113
6 changed files with 102 additions and 60 deletions

View File

@@ -1,33 +1,34 @@
# EXTRA_DIST = cnghttp2.pxd nghttp2.pyx
# XXX consider https://github.com/thewtex/cython-cmake-example
if(ENABLE_PYTHON_BINDINGS)
# XXX add ALL? Will always be invoked as target is always out-of-date though.
add_custom_target(python
COMMAND ${PYTHON_EXECUTABLE} setup.py build
add_custom_target(python ALL
COMMAND "${PYTHON_EXECUTABLE}" setup.py build
VERBATIM
DEPENDS nghttp2.c
)
add_custom_target(python-install
COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix=${DESTDIR}${CMAKE_INSTALL_PREFIX}
)
configure_file(install-python.cmake.in install-python.cmake ESCAPE_QUOTES @ONLY)
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-python.cmake")
# XXX cmake does not have an uninstall target, do not bother with this then.
# XXX glob patterns like this will probably not work
#add_custom_target(python-uninstall
# COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/nghttp2.so
# COMMAND ${CMAKE} -E remove -f ${DESTDIR}${CMAKE_INSTALL_FULL_LIBDIR}/python*/site-packages/python_nghttp2-*.egg
#)
# XXX cleaner way to advertise the build artifacts? (note nghttp2.c is cleaned automatically)
add_custom_target(python-clean
COMMAND ${PYTHON_EXECUTABLE} setup.py clean --all
)
# XXX CYTHON_EXECUTABLE is not set!
add_custom_command(OUTPUT nghttp2.c
COMMAND ${CYTHON_EXECUTABLE} -o nghttp2.c nghttp2.pyx
COMMAND "${CYTHON_EXECUTABLE}" -o nghttp2.c
"${CMAKE_CURRENT_SOURCE_DIR}/nghttp2.pyx"
VERBATIM
DEPENDS nghttp2.pyx
)
## This works also, except that the installation target is missing...
# include(UseCython)
# cython_add_module(python_nghttp2 nghttp2.pyx)
# set_target_properties(python_nghttp2 PROPERTIES
# OUTPUT_NAME nghttp2
# )
# target_include_directories(python_nghttp2 PRIVATE
# "${CMAKE_SOURCE_DIR}/lib"
# "${CMAKE_SOURCE_DIR}/lib/includes"
# "${CMAKE_BINARY_DIR}/lib/includes"
# )
# target_link_libraries(python_nghttp2
# nghttp2
# )
endif()

View File

@@ -0,0 +1,10 @@
get_filename_component(rootdir "$ENV{DESTDIR}" ABSOLUTE)
if(rootdir STREQUAL "")
set(rootdir /)
endif()
execute_process(
COMMAND "@PYTHON_EXECUTABLE@" setup.py install
--skip-build
--root=${rootdir} --prefix=${CMAKE_INSTALL_PREFIX}
WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@"
)

View File

@@ -39,6 +39,7 @@ setup(
'@top_srcdir@/lib/includes',
'@top_builddir@/lib/includes'],
library_dirs=['@top_builddir@/lib/.libs',
'@top_builddir@/lib',
'@top_builddir@'],
libraries=LIBS)],
long_description='TBD'