Commit 103cffc1 authored by saubatn's avatar saubatn

FEATURE 109 : (Quite) Clean Cmake configuration for wrapping CamiTK SDK to Python using Shiboken.

2 CMake targets to use for wrapping the SDK :
* sdk_wrap_to_python : use shiboken on the input typesystem.xml files to decorate the C++ classes.
* sdk_package_to_python : launch sdk_wrap_to_python and then, compile these C++ decorated classes and link them against CamiTK SDK libraries to produce the Python package of CamiTK SDK.

=> The structure is 80% clean, some improvements can be made in the futre (such as CMake variables recursively filled to put in some existing macros ...). It allows now to easily test the Python exposition of CamiTK SDK !

git-svn-id: svn+ssh:// ec899d31-69d1-42ba-9299-647d76f65fb3
parent 54efcc5e
......@@ -23,7 +23,8 @@ if (NOT CAMITK_BINDING_PYTHON_GENERATOR)
message(FATAL_ERROR "Please add Shiboken binary in your PATH or manually point to it using the CAMITK_BINDING_PYTHON_GENERATOR variable")
# And of course PySide, the Python binding of Qt (4.8) using Shiboken.
# And of course Qt and PySide, the Python binding of Qt (4.8) using Shiboken.
find_package(Qt4 REQUIRED)
find_package(PySide REQUIRED)
......@@ -42,12 +43,16 @@ add_subdirectory(components)
# TODO : Remove once debugged
# Custom CMake Python binging targets
# Custom CMake Python binding targets
# Shiboken specific paths
......@@ -56,24 +61,64 @@ set(PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN
# Wrap the CamiTK SDK. Wraping uses Shiboken (PySide binding tool)
# It means it decorate the specified C++ classes to Python by adding
# TODO : Remove once debugged
# Wrap the CamiTK SDK. Wrapping uses Shiboken (PySide binding tool)
# It means it decorates the specified C++ classes to Python by adding
# information in order to convert it into a CPython extension
# Shiboken parses the typesystem.xml files to detect which C++ classes to expose to Python
# For each of them, it create a CPython C++ decorated class in the build directory
add_custom_target( sdk_wrap_to_python
# OUTPUT ${lib_python_SRC}
COMMAND ${CMAKE_COMMAND} -E echo "Wrapping CamiTK SDK for Python exposure."
COMMAND ${CAMITK_BINDING_PYTHON_GENERATOR} --enable-parent-ctor-heuristic --enable-return-value-heuristic --enable-pyside-extensions # --debug-level=full
COMMAND ${CAMITK_BINDING_PYTHON_GENERATOR} --enable-parent-ctor-heuristic --enable-return-value-heuristic --enable-pyside-extensions #--debug-level=full
# COMMENT "Running generator for ${PROJECT_NAME}:"
COMMAND ${CMAKE_COMMAND} -E echo "CamiTK SDK wrapped."
# Build the CPython extension with the original C++ library and the decorated
# Python exposed classes
# The resulting C++ wrapped classes will be listed in the following CMake variable:
file(GLOB_RECURSE SDK_WRAPPED_CLASSES ${CMAKE_BINARY_DIR}/python_sdk/camitk_sdk/*.cpp )
# We list the CamiTK SDK generated dynamic libraries for linking the python package
# TODO do not manually list those libraries, but dynamically create this list at configuration
# step, using CamiTK CMake macros
# This CMake target aims at compiling the C++ Python-wrapped classes of CamiTK and link them against
# the original CamiTK SDK libraries.
# WARNING Do not manually run this target, it requires another configure step wich is run by the sdk_package_to_python
# CMake target.
if(NOT SDK_WRAPPED_CLASSES STREQUAL "") # only create camitk_sdk target if camitk sdk has been wrapped
set(PROJECT_NAME camitk_sdk) # the name of the camitk sdk package once compiled
string(REPLACE ":" ";" CAMITK_SDK_INCLUDE_DIR ${SHIBOKEN_CAMITK_SDK_PATH}) # deduce the list of include directories of CamiTK SDK
string(REPLACE ":" ";" PYSIDE_INCLUDE_ALL_DIR ${PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN}) #deduce the list of include directories provided from PySide / Shiboken
add_library(${PROJECT_NAME} MODULE ${SDK_WRAPPED_CLASSES}) # TODO test if SHARED library type generation works
target_link_libraries(${PROJECT_NAME} ${CAMITK_SDK_LIBRARIES})
# add_dependencies(${PROJECT_NAME} camitkcore)
# Create the Python package of CamiTK SDK
# This package is compiled from the generated C++ classes of the sdk_wrap_to_python target
# and link against the CamiTK SDK libraries.
# Build the custom sdk_package_to_python target in order to compile the wrapped C++ classes and link against
# CamiTK SDK dynamic libraries.
add_custom_target( sdk_package_to_python
COMMAND ${CMAKE_COMMAND} -E echo "Creating Python package of CamiTK SDK."
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target camitk_sdk
COMMAND ${CMAKE_COMMAND} -E echo "CamiTK SDK Python package created."
add_dependencies(sdk_package_to_python sdk_wrap_to_python) # need to wrapp before creating the package
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment