# The name of the wrapped library.
set(WRAPPED_LIB_NAME core_lib)

# The name of the generated bindings module (as imported in Python). You can
# change the name to something relevant for your project.
set(BINDINGS_LIB_NAME borco_shiboken_example)

# The header file with all the types and functions for which bindings will be
# generated. Usually it simply includes other headers of the library you are
# creating bindings for.
set(WRAPPED_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/bindings.h)

# The typesystem xml file which defines the relationships between the
# C++ types / functions and the corresponding Python equivalents.
set(TYPESYSTEM_FILE ${CMAKE_CURRENT_SOURCE_DIR}/bindings.xml)

# Specify which C++ files will be generated by shiboken. This includes the
# module wrapper and a '.cpp' file per C++ type.
# These are needed for generating the module shared library.
set(GENERATED_SOURCES
    ${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_LIB_NAME}/borco_shiboken_example_module_wrapper.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_LIB_NAME}/dog_wrapper.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_LIB_NAME}/icecream_wrapper.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_LIB_NAME}/truck_wrapper.cpp
)

# ----------------------------------------------------------------------------
# Shiboken target for generating binding C++ files
# ----------------------------------------------------------------------------
get_target_property(WRAPPED_LIB_INCLUDE_DIRS ${WRAPPED_LIB_NAME} INCLUDE_DIRECTORIES)
message(STATUS "WRAPPED_LIB_INCLUDE_DIRS: ${WRAPPED_LIB_INCLUDE_DIRS}")

# Set up the options to pass to shiboken.
set(SHIBOKEN_OPTIONS --generator-set=shiboken --enable-parent-ctor-heuristic
    --enable-return-value-heuristic --use-isnull-as-nb-bool
    --avoid-protected-hack
    -I${WRAPPED_LIB_INCLUDE_DIRS}
    -I${CMAKE_CURRENT_SOURCE_DIR}
    -T${CMAKE_CURRENT_SOURCE_DIR}
    --output-directory=${CMAKE_CURRENT_BINARY_DIR}
)

set(GENERATED_SOURCES_DEPENDENCIES ${WRAPPED_HEADER} ${TYPESYSTEM_FILE})

# Add custom target to run shiboken to generate the binding cpp files.
add_custom_command(OUTPUT ${GENERATED_SOURCES}
    COMMAND ${SHIBOKEN_PATH}
    ${SHIBOKEN_OPTIONS} ${WRAPPED_HEADER} ${TYPESYSTEM_FILE}
    DEPENDS ${GENERATED_SOURCES_DEPENDENCIES}
    IMPLICIT_DEPENDS CXX ${WRAPPED_HEADER}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Running generator for ${TYPESYSTEM_FILE}.")

# ----------------------------------------------------------------------------
# CMake target - BINDINGS_LIB_NAME
# ----------------------------------------------------------------------------
shiboken_add_library(${BINDINGS_LIB_NAME} ${WRAPPED_LIB_NAME} "${GENERATED_SOURCES}")

shiboken_deploy_library(${BINDINGS_LIB_NAME} ${WRAPPED_LIB_NAME})
