From 52f51c40b92df245c1c35d1e85274c4d4594d9e2 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi <giulio.romualdi@gmail.com> Date: Thu, 25 Nov 2021 18:11:06 +0100 Subject: [PATCH] Create idyntree-pybind11 library --- CMakeLists.txt | 4 +-- bindings/pybind11/CMakeLists.txt | 28 +++++++++++++++++-- bindings/pybind11/idyntree_core.cpp | 2 +- bindings/pybind11/idyntree_model.cpp | 2 +- bindings/pybind11/idyntree_modelio_urdf.cpp | 3 +- bindings/pybind11/idyntree_sensors.cpp | 2 +- .../iDynTree/pybind11/VectorCasters.h} | 0 7 files changed, 33 insertions(+), 8 deletions(-) rename bindings/pybind11/{idyntree_vector_casters.h => include/iDynTree/pybind11/VectorCasters.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index df85a8b77da..68781cc3f0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,8 @@ if(NOT IDYNTREE_ONLY_DOCS) list(APPEND _IDYNTREE_EXPORTED_DEPENDENCIES_ONLY_STATIC assimp) endif() + add_subdirectory(bindings) + include(InstallBasicPackageFiles) install_basic_package_files(iDynTree VARS_PREFIX ${VARS_PREFIX} VERSION ${${VARS_PREFIX}_VERSION} @@ -78,8 +80,6 @@ if(NOT IDYNTREE_ONLY_DOCS) PRIVATE_DEPENDENCIES ${_IDYNTREE_EXPORTED_DEPENDENCIES_ONLY_STATIC}) include(AddUninstallTarget) - - add_subdirectory(bindings) endif() # add a dox target to generate doxygen documentation diff --git a/bindings/pybind11/CMakeLists.txt b/bindings/pybind11/CMakeLists.txt index 94b0cae5648..19dc8ebf5d1 100644 --- a/bindings/pybind11/CMakeLists.txt +++ b/bindings/pybind11/CMakeLists.txt @@ -1,3 +1,26 @@ +set(libraryname idyntree-pybind11) + +add_library(${libraryname} INTERFACE) +target_link_libraries(${libraryname} INTERFACE idyntree-core) + +# Specify include directories for both compilation and installation process. +# The $<INSTALL_PREFIX> generator expression is useful to ensure to create +# relocatable configuration files, see https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html +# creating-relocatable-packages +target_include_directories(${libraryname} INTERFACE + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" + "<INSTALL_INTERFACE:<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") + +# Specify installation targets, typology and destination folders. +install(TARGETS ${libraryname} + EXPORT ${PROJECT_NAME}) + +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/iDynTree/pybind11/VectorCasters.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/iDynTree/pybind11") + +add_library(iDynTree::${libraryname} ALIAS ${libraryname}) +set_property(GLOBAL APPEND PROPERTY ${VARS_PREFIX}_TARGETS ${libraryname}) + pybind11_add_module(pybind11_idyntree SYSTEM idyntree.cpp error_utilities.h error_utilities.cpp idyntree_core.h idyntree_core.cpp @@ -5,12 +28,13 @@ pybind11_add_module(pybind11_idyntree SYSTEM idyntree.cpp idyntree_model.h idyntree_model.cpp idyntree_sensors.h idyntree_sensors.cpp idyntree_modelio_urdf.h idyntree_modelio_urdf.cpp - idyntree_vector_casters.h) + ) target_link_libraries(pybind11_idyntree PUBLIC idyntree-core idyntree-model idyntree-sensors - idyntree-modelio) + idyntree-modelio + iDynTree::idyntree-pybind11) # The generated Python dynamic module must have the same name as the pybind11 # module, i.e. `bindings`. diff --git a/bindings/pybind11/idyntree_core.cpp b/bindings/pybind11/idyntree_core.cpp index ec7fe8e8a30..35185798ff6 100644 --- a/bindings/pybind11/idyntree_core.cpp +++ b/bindings/pybind11/idyntree_core.cpp @@ -1,6 +1,6 @@ #include "idyntree_core.h" -#include "idyntree_vector_casters.h" +#include <iDynTree/pybind11/VectorCasters.h> #include <iDynTree/Core/Axis.h> #include <iDynTree/Core/Direction.h> #include <iDynTree/Core/MatrixDynSize.h> diff --git a/bindings/pybind11/idyntree_model.cpp b/bindings/pybind11/idyntree_model.cpp index fad4c994772..3e0face3c7f 100644 --- a/bindings/pybind11/idyntree_model.cpp +++ b/bindings/pybind11/idyntree_model.cpp @@ -1,5 +1,5 @@ #include "idyntree_model.h" -#include "idyntree_vector_casters.h" +#include <iDynTree/pybind11/VectorCasters.h> #include "error_utilities.h" diff --git a/bindings/pybind11/idyntree_modelio_urdf.cpp b/bindings/pybind11/idyntree_modelio_urdf.cpp index 7a25441e305..be71a0b1bcd 100644 --- a/bindings/pybind11/idyntree_modelio_urdf.cpp +++ b/bindings/pybind11/idyntree_modelio_urdf.cpp @@ -1,5 +1,6 @@ +#include <iDynTree/pybind11/VectorCasters.h> + #include "idyntree_modelio_urdf.h" -#include "idyntree_vector_casters.h" #include "error_utilities.h" diff --git a/bindings/pybind11/idyntree_sensors.cpp b/bindings/pybind11/idyntree_sensors.cpp index c771e2aee66..189d787895d 100644 --- a/bindings/pybind11/idyntree_sensors.cpp +++ b/bindings/pybind11/idyntree_sensors.cpp @@ -1,5 +1,5 @@ -#include "idyntree_vector_casters.h" +#include <iDynTree/pybind11/VectorCasters.h> #include "idyntree_sensors.h" #include "error_utilities.h" diff --git a/bindings/pybind11/idyntree_vector_casters.h b/bindings/pybind11/include/iDynTree/pybind11/VectorCasters.h similarity index 100% rename from bindings/pybind11/idyntree_vector_casters.h rename to bindings/pybind11/include/iDynTree/pybind11/VectorCasters.h