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://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1176 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")
endif()
# 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)
add_subdirectory(libraries)
# TODO : Remove once debugged
# message(WARNING "PYSIDE_INCLUDE_DIR = ${PYSIDE_INCLUDE_DIR}")
# message(WARNING "SHIBOKEN_TYPESYSTEM_PATH = ${SHIBOKEN_TYPESYSTEM_PATH}")
# message(WARNING "SHIBOKEN_GLOBAL_H_PATH = ${SHIBOKEN_GLOBAL_H_PATH}")
# message(WARNING "QT_INCLUDE_DIR = ${QT_INCLUDE_DIR}")
# message(WARNING "QT_QTCORE_INCLUDE_DIR = ${QT_QTCORE_INCLUDE_DIR}")
# message(WARNING "SHIBOKEN_CAMITK_SDK_PATH = ${SHIBOKEN_CAMITK_SDK_PATH}")
#--------------------------------------------
#
# Custom CMake Python binging targets
# Custom CMake Python binding targets
#
#--------------------------------------------
# Shiboken specific paths
......@@ -56,24 +61,64 @@ set(PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN
# :${PYSIDE_INCLUDE_DIR}/QtHelp:${PYSIDE_INCLUDE_DIR}/QtNetwork:${PYSIDE_INCLUDE_DIR}/QtOpenGL:${PYSIDE_INCLUDE_DIR}/QtScript:${PYSIDE_INCLUDE_DIR}/QtScriptTools:${PYSIDE_INCLUDE_DIR}/QtSql:${PYSIDE_INCLUDE_DIR}/QtSvg:${PYSIDE_INCLUDE_DIR}/QtTest:${PYSIDE_INCLUDE_DIR}/QtUiTools:${PYSIDE_INCLUDE_DIR}/QtWebKit:${PYSIDE_INCLUDE_DIR}/QtXml:${PYSIDE_INCLUDE_DIR}/QtXmlPatterns:${PYSIDE_INCLUDE_DIR}/QtDeclarative
)
# 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
# message(WARNING "PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN = ${PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN}")
# 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
${CMAKE_CURRENT_SOURCE_DIR}/global_sdk.h
--include-paths=${PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN}:${QT_INCLUDE_DIR}:${QT_QTCORE_INCLUDE_DIR}:${SHIBOKEN_GLOBAL_H_PATH}
--include-paths=${PYSIDE_INCLUDE_ALL_DIR_SHIBOKEN}:${QT_INCLUDE_DIR}:${QT_QTCORE_INCLUDE_DIR}:${SHIBOKEN_GLOBAL_H_PATH}:${SHIBOKEN_CAMITK_SDK_PATH}
--typesystem-paths=${PYSIDE_TYPESYSTEMS}:${SHIBOKEN_TYPESYSTEM_PATH}
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/typesystem_sdk.xml
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# 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
file(GLOB_RECURSE CAMITK_SDK_LIBRARIES ${CMAKE_BINARY_DIR}/*.so)
# message(WARNING "CAMITK_SDK_LIBRARIES = ${CAMITK_SDK_LIBRARIES}")
# 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
# message(WARNING "CAMITK_SDK_INCLUDE_DIR = ${CAMITK_SDK_INCLUDE_DIR}")
# message(WARNING "PYSIDE_INCLUDE_ALL_DIR = ${PYSIDE_INCLUDE_ALL_DIR}")
include_directories(${PROJECT_NAME} ${CAMITK_SDK_INCLUDE_DIR} ${PYSIDE_INCLUDE_ALL_DIR} ${SHIBOKEN_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH} ${PYSIDE_INCLUDE_ALL_DIR_CPP} ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR})
add_library(${PROJECT_NAME} MODULE ${SDK_WRAPPED_CLASSES}) # TODO test if SHARED library type generation works
# # set_property(TARGET ${PROJECT_NAME} PROPERTY PREFIX "")
target_link_libraries(${PROJECT_NAME} ${CAMITK_SDK_LIBRARIES})
# add_dependencies(${PROJECT_NAME} camitkcore)
endif()
# 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} ${CMAKE_BINARY_DIR}
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
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment