From 2c5e0894671b99fdbabd1a58af6a4f5d6e5c1554 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Oct 2023 19:27:56 +0200 Subject: [PATCH] Explicitly set Python install directory in subprojects Instead of just "hoping" they install in the same directory used by the superbuild. --- cmake/BuildICUB.cmake | 11 +++++++++-- cmake/BuildYARP.cmake | 9 ++------- cmake/Buildbipedal-locomotion-framework.cmake | 4 ++-- cmake/BuildiDynTree.cmake | 4 ++-- cmake/Buildicub-models.cmake | 1 + cmake/Buildwearables.cmake | 4 ++++ cmake/RobSupPurePythonYCMEPHelper.cmake | 9 ++------- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cmake/BuildICUB.cmake b/cmake/BuildICUB.cmake index 64e6eee4f..a9bdeb2eb 100644 --- a/cmake/BuildICUB.cmake +++ b/cmake/BuildICUB.cmake @@ -48,6 +48,12 @@ else() set(ICUB_COMPILE_BINDINGS OFF) endif() +if(ROBOTOLOGY_USES_PYTHON AND NOT ROBOTOLOGY_GENERATE_CONDA_RECIPES) + set(ICUB_PYTHON_INSTALL_CMAKE_ARGS "-DCMAKE_INSTALL_PYTHONDIR=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") +else() + set(ICUB_PYTHON_INSTALL_CMAKE_ARGS "") +endif() + ycm_ep_helper(ICUB TYPE GIT STYLE GITHUB REPOSITORY robotology/icub-main.git @@ -56,7 +62,7 @@ ycm_ep_helper(ICUB TYPE GIT FOLDER src CMAKE_ARGS -DICUB_INSTALL_WITH_RPATH:BOOL=ON CMAKE_CACHE_ARGS -DENABLE_icubmod_cartesiancontrollerserver:BOOL=ON - -DENABLE_icubmod_cartesiancontrollerclient:BOOL=ON + -DENABLE_icubmod_cartesiancontrollerclient:sBOOL=ON -DENABLE_icubmod_gazecontrollerclient:BOOL=ON -DENABLE_icubmod_serial:BOOL=${ROBOTOLOGY_ENABLE_ICUB_HEAD} -DENABLE_icubmod_serialport:BOOL=${ROBOTOLOGY_ENABLE_ICUB_HEAD} @@ -91,7 +97,8 @@ ycm_ep_helper(ICUB TYPE GIT -DICUBMAIN_COMPILE_SIMULATORS:BOOL=${ICUBMAIN_COMPILE_SIMULATORS} -DICUB_COMPILE_BINDINGS:BOOL=${ICUB_COMPILE_BINDINGS} -DCREATE_PYTHON:BOOL=${ROBOTOLOGY_USES_PYTHON} - -DCREATE_LUA:BOOL=${ROBOTOLOGY_USES_LUA}) + -DCREATE_LUA:BOOL=${ROBOTOLOGY_USES_LUA} + ${ICUB_PYTHON_INSTALL_CMAKE_ARGS}) set(ICUB_CONDA_DEPENDENCIES ace libopencv gsl ipopt libode qt-main sdl) diff --git a/cmake/BuildYARP.cmake b/cmake/BuildYARP.cmake index dfc8e577d..6f4b0e375 100644 --- a/cmake/BuildYARP.cmake +++ b/cmake/BuildYARP.cmake @@ -35,13 +35,8 @@ else() set(YARP_USE_I2C OFF) endif() -# For what regards Python installation, the options changes depending -# on whether we are installing YARP from source, or generating a -# conda package on Windows as in that case the installation location -# will need to be outside of CMAKE_INSTALL_PREFIX -# See https://github.com/robotology/robotology-superbuild/issues/641 -if(ROBOTOLOGY_USES_PYTHON AND ROBOTOLOGY_GENERATE_CONDA_RECIPES AND WIN32) - list(APPEND YARP_OPTIONAL_CMAKE_ARGS "-DCMAKE_INSTALL_PYTHON3DIR:PATH=%SP_DIR%") +if(ROBOTOLOGY_USES_PYTHON) + list(APPEND YARP_OPTIONAL_DEPS "-DCMAKE_INSTALL_PYTHON3DIR=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") endif() ycm_ep_helper(YARP TYPE GIT diff --git a/cmake/Buildbipedal-locomotion-framework.cmake b/cmake/Buildbipedal-locomotion-framework.cmake index 241218039..69d36ebd9 100644 --- a/cmake/Buildbipedal-locomotion-framework.cmake +++ b/cmake/Buildbipedal-locomotion-framework.cmake @@ -50,8 +50,8 @@ endif() # will need to be outside of CMAKE_INSTALL_PREFIX # See https://github.com/robotology/robotology-superbuild/issues/641 set(bipedal-locomotion-framework_OPTIONAL_CMAKE_ARGS "") -if(ROBOTOLOGY_USES_PYTHON AND ROBOTOLOGY_GENERATE_CONDA_RECIPES) - list(APPEND bipedal-locomotion-framework_OPTIONAL_CMAKE_ARGS "-DFRAMEWORK_DETECT_ACTIVE_PYTHON_SITEPACKAGES:BOOL=ON") +if(ROBOTOLOGY_USES_PYTHON) + list(APPEND bipedal-locomotion-framework_OPTIONAL_CMAKE_ARGS "-DFRAMEWORK_PYTHON_INSTALL_DIR:BOOL=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") endif() if(ROBOTOLOGY_USES_PCL_AND_VTK) diff --git a/cmake/BuildiDynTree.cmake b/cmake/BuildiDynTree.cmake index 48787129e..15f40327c 100644 --- a/cmake/BuildiDynTree.cmake +++ b/cmake/BuildiDynTree.cmake @@ -16,8 +16,8 @@ list(APPEND iDynTree_DEPENDS OsqpEigen) # will need to be outside of CMAKE_INSTALL_PREFIX # See https://github.com/robotology/robotology-superbuild/issues/641 set(iDynTree_OPTIONAL_CMAKE_ARGS "") -if(ROBOTOLOGY_USES_PYTHON AND ROBOTOLOGY_GENERATE_CONDA_RECIPES AND WIN32) - list(APPEND iDynTree_OPTIONAL_CMAKE_ARGS "-DIDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES:BOOL=ON") +if(ROBOTOLOGY_USES_PYTHON) + list(APPEND iDynTree_OPTIONAL_CMAKE_ARGS "-DIDYNTREE_PYTHON_INSTALL_DIR=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") endif() # Hack for disabling IDYNTREE_USES_IRRLICHT on Ubuntu 18.04, diff --git a/cmake/Buildicub-models.cmake b/cmake/Buildicub-models.cmake index d5b844921..32b2202b1 100644 --- a/cmake/Buildicub-models.cmake +++ b/cmake/Buildicub-models.cmake @@ -6,6 +6,7 @@ include(YCMEPHelper) set(icub-models_OPTIONAL_CMAKE_ARGS "") list(APPEND icub-models_OPTIONAL_CMAKE_ARGS "-DICUB_MODELS_COMPILE_PYTHON_BINDINGS:BOOL=${ROBOTOLOGY_USES_PYTHON}") list(APPEND icub-models_OPTIONAL_CMAKE_ARGS "-DICUB_MODELS_USES_PYTHON:BOOL=${ROBOTOLOGY_USES_PYTHON}") +list(APPEND icub-models_OPTIONAL_CMAKE_ARGS "-DICUB_MODELS_PYTHON_INSTALL_DIR=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") ycm_ep_helper(icub-models TYPE GIT diff --git a/cmake/Buildwearables.cmake b/cmake/Buildwearables.cmake index 1b487b03e..69a954029 100644 --- a/cmake/Buildwearables.cmake +++ b/cmake/Buildwearables.cmake @@ -15,6 +15,10 @@ endif() list(APPEND WEARABLES_CMAKE_ARGS "-DWEARABLES_COMPILE_PYTHON_BINDINGS:BOOL=${ROBOTOLOGY_USES_PYTHON}") +if(ROBOTOLOGY_USES_PYTHON AND NOT ROBOTOLOGY_GENERATE_CONDA_RECIPES) + list(APPEND WEARABLES_CMAKE_ARGS "-DWEARABLES_PYTHON_INSTALL_DR=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") +endif() + ycm_ep_helper(wearables TYPE GIT STYLE GITHUB REPOSITORY robotology/wearables.git diff --git a/cmake/RobSupPurePythonYCMEPHelper.cmake b/cmake/RobSupPurePythonYCMEPHelper.cmake index 36a3a1aff..6e73692c4 100644 --- a/cmake/RobSupPurePythonYCMEPHelper.cmake +++ b/cmake/RobSupPurePythonYCMEPHelper.cmake @@ -26,11 +26,6 @@ function(ROB_SUP_PURE_PYTHON_YCM_EP_HELPER _name) # Dependencies find_package(Python3 COMPONENTS Interpreter REQUIRED) - 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} ROBSUB_PYTHON_INSTALL_DIR) - # Check arguments set(_options) set(_oneValueArgs COMPONENT @@ -59,6 +54,6 @@ function(ROB_SUP_PURE_PYTHON_YCM_EP_HELPER _name) # See https://stackoverflow.com/questions/55708589/how-to-pass-an-environment-variable-to-externalproject-add-configure-command # See https://github.com/robotology/robotology-superbuild/issues/1118 # To avoid the complexity of handling two commands, we just use the build step to uninstall any existing package - BUILD_COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${YCM_EP_INSTALL_DIR}/${ROBSUB_PYTHON_INSTALL_DIR} pip uninstall -y ${_PYH_${_name}_PYTHON_PACKAGE_NAME} - INSTALL_COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade --no-deps --target=${YCM_EP_INSTALL_DIR}/${ROBSUB_PYTHON_INSTALL_DIR} -VV ) + BUILD_COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR} pip uninstall -y ${_PYH_${_name}_PYTHON_PACKAGE_NAME} + INSTALL_COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade --no-deps --target=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR} -VV ) endfunction()