Skip to content

Commit

Permalink
Merge pull request #1124 from robotology/traversaro-patch-5
Browse files Browse the repository at this point in the history
CMake: Permit to explicitly specify Python installation directory
  • Loading branch information
traversaro authored Oct 29, 2023
2 parents 4459722 + 56ea923 commit f4df648
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- CMake: Permit to explicitly specify Python installation directory by setting the `IDYNTREE_PYTHON_INSTALL_DIR` CMake variable (https://github.com/robotology/idyntree/pull/1124).

## [10.0.0] - 2023-10-16

### Added
Expand Down
20 changes: 12 additions & 8 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ if(IDYNTREE_USES_PYTHON OR IDYNTREE_USES_PYTHON_PYBIND11)
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})
if(NOT DEFINED IDYNTREE_PYTHON_INSTALL_DIR)
if(IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES)
set(IDYNTREE_PYTHON_INSTALL_DIR ${Python3_SITELIB})
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)
endif()
endif()
if(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()
file(TO_CMAKE_PATH "${PYTHON_INSTDIR}" PYTHON_INSTDIR)
Expand Down

0 comments on commit f4df648

Please sign in to comment.