Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES CMake option #852

Merged
merged 2 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add the possibility to use `MatrixView` and `Span` as input/output objects for `InverseKinematics` class (https://github.com/robotology/idyntree/pull/822).
- Add the possibility to get frame trasform from the visualizer, and to use frame/link name in place of indices (https://github.com/robotology/idyntree/pull/849).
- Add `IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES` CMake option (default value: OFF) to detect and install in the active site-package directory the Python bindings (https://github.com/robotology/idyntree/pull/852).

### Changed
- The wheels uploaded to PyPI are now `manylinux_2_24` compliant (https://github.com/robotology/idyntree/pull/844)
Expand Down
21 changes: 17 additions & 4 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ option(IDYNTREE_USES_LUA "Do you want to create the Lua bindings" FALSE)
option(IDYNTREE_USES_MATLAB "Do you want to create the MATLAB bindings" FALSE)
option(IDYNTREE_USES_OCTAVE "Do you want to create the OCTAVE bindings" FALSE)
option(IDYNTREE_GENERATE_MATLAB "Enable if you have the experimental version of SWIG necessary for generating the Matlab wrapper" FALSE)
option(IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES "Do you want iDynTree to detect and install in the active site-package directory? (it could be a system dir)" FALSE)

find_package(SWIG)

# Setup installation directory for Python bindings.
if (IDYNTREE_USES_PYTHON_PYBIND11 OR IDYNTREE_USES_PYTHON)
if(IDYNTREE_PACKAGE_FOR_PYPI)
set(PYTHON_INSTDIR ${CMAKE_INSTALL_PREFIX})
if(IDYNTREE_USES_PYTHON OR IDYNTREE_USES_PYTHON_PYBIND11)
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
set(IDYNTREE_SEARCHED_Python_Development_Component "Development")
else()
set(IDYNTREE_SEARCHED_Python_Development_Component "Development.Module")
endif()
find_package(Python3 COMPONENTS Interpreter ${IDYNTREE_SEARCHED_Python_Development_Component} NumPy REQUIRED)

if (IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES)
set(PYTHON_INSTDIR ${Python3_SITELIB}/idyntree)
elseif(IDYNTREE_PACKAGE_FOR_PYPI)
set(PYTHON_INSTDIR ${CMAKE_INSTALL_PREFIX})
else()
execute_process(COMMAND ${Python3_EXECUTABLE}
-c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
string(STRIP ${_PYTHON_INSTDIR} IDYNTREE_PYTHON_INSTALL_DIR)
set(PYTHON_INSTDIR ${IDYNTREE_PYTHON_INSTALL_DIR}/idyntree)
endif()
endif()
Expand Down
6 changes: 0 additions & 6 deletions bindings/pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
else()
find_package(Python3 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
endif()

pybind11_add_module(pybind11_idyntree SYSTEM idyntree.cpp
error_utilities.h error_utilities.cpp
idyntree_core.h idyntree_core.cpp
Expand Down
8 changes: 0 additions & 8 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
else()
find_package(Python3 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
endif()

message(STATUS "Using Python: ${Python3_EXECUTABLE}")

cmake_policy(SET CMP0078 NEW)
cmake_policy(SET CMP0086 NEW)

Expand Down
12 changes: 1 addition & 11 deletions cmake/iDynTreeOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,7 @@ if(IDYNTREE_COMPILE_BINDINGS)
add_definitions(-DIDYNTREE_COMPILE_BINDINGS)
endif(IDYNTREE_COMPILE_BINDINGS)

if(IDYNTREE_USES_PYTHON OR IDYNTREE_USES_PYTHON_PYBIND11)
find_package(Python3 COMPONENTS Interpreter QUIET)
if (Python3_FOUND)
execute_process(COMMAND ${Python3_EXECUTABLE}
-c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))"
OUTPUT_VARIABLE _PYTHON_INSTDIR)
string(STRIP ${_PYTHON_INSTDIR} IDYNTREE_PYTHON_INSTALL_DIR)
# Bindings are installed in `idyntree` subdirectory.
list(APPEND IDYNTREE_BINARY_DIRS "${IDYNTREE_PYTHON_INSTALL_DIR}/idyntree")
endif()
endif()


#set default build type to "Release" in single-config generators
if(NOT CMAKE_CONFIGURATION_TYPES)
Expand Down