From 92784d31c600e9b9eb197cd4154d13985788280e Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 4 Sep 2024 12:06:51 +0200 Subject: [PATCH 1/4] Build Python bindings of manifpy on Windows --- cmake/Buildbipedal-locomotion-framework.cmake | 5 ----- cmake/Buildmanif.cmake | 9 +-------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/cmake/Buildbipedal-locomotion-framework.cmake b/cmake/Buildbipedal-locomotion-framework.cmake index 964219f46..ae419edb8 100644 --- a/cmake/Buildbipedal-locomotion-framework.cmake +++ b/cmake/Buildbipedal-locomotion-framework.cmake @@ -44,11 +44,6 @@ if (ROBOTOLOGY_ENABLE_DYNAMICS_FULL_DEPS) endif() endif() -# For what regards Python installation, the options changes depending -# on whater we are installing blf in the superbuild, or we are 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 set(bipedal-locomotion-framework_OPTIONAL_CMAKE_ARGS "") if(ROBOTOLOGY_USES_PYTHON) list(APPEND bipedal-locomotion-framework_OPTIONAL_CMAKE_ARGS "-DFRAMEWORK_PYTHON_INSTALL_DIR:PATH=${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}") diff --git a/cmake/Buildmanif.cmake b/cmake/Buildmanif.cmake index 0e7f16f4a..71c0e6f88 100644 --- a/cmake/Buildmanif.cmake +++ b/cmake/Buildmanif.cmake @@ -4,13 +4,6 @@ include(YCMEPHelper) -# Workaround for https://github.com/robotology/robotology-superbuild/pull/838#issuecomment-887367047 -if(ROBOTOLOGY_USES_PYTHON AND NOT WIN32) - set(BUILD_PYTHON_BINDINGS ON) -else() - set(BUILD_PYTHON_BINDINGS OFF) -endif() - # We pass CMAKE_CXX_STANDARD=17 as we encountered problems when using -march=native # and mixing libraries compiled with C++11 and C++17, see # https://github.com/artivis/manif/issues/274 @@ -20,7 +13,7 @@ ycm_ep_helper(manif TYPE GIT TAG master COMPONENT external FOLDER src - CMAKE_ARGS -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=${BUILD_PYTHON_BINDINGS} -DMANIFPY_PKGDIR:PATH=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}) + CMAKE_ARGS -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=${ROBOTOLOGY_USES_PYTHON} -DMANIFPY_PKGDIR:PATH=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}) set(manif_CONDA_PKG_NAME manif) set(manif_CONDA_PKG_CONDA_FORGE_OVERRIDE ON) From 950214fa4c6a81ff30006e880bd9db822450d86b Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 4 Sep 2024 13:08:40 +0200 Subject: [PATCH 2/4] Switch manif to use upstream release 0.0.5 --- cmake/Buildmanif.cmake | 6 +----- cmake/ProjectsTagsStable.cmake | 3 +-- cmake/ProjectsTagsUnstable.cmake | 3 +-- releases/latest.releases.yaml | 4 ++-- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cmake/Buildmanif.cmake b/cmake/Buildmanif.cmake index 71c0e6f88..099939305 100644 --- a/cmake/Buildmanif.cmake +++ b/cmake/Buildmanif.cmake @@ -17,8 +17,4 @@ ycm_ep_helper(manif TYPE GIT set(manif_CONDA_PKG_NAME manif) set(manif_CONDA_PKG_CONDA_FORGE_OVERRIDE ON) -# This is a small hack. To avoid incompatibilities between the version tagged in the ami-iit fork -# (something like 0.0.4.x) and the version available in conda-forge when generating conda metapackages -# such as robotology-distro and robotology-distro-all, we override the conda package version of manif -# here. This needs to be removed as soon as we stop using our fork in the superbuild -set(manif_CONDA_VERSION 0.0.4) + diff --git a/cmake/ProjectsTagsStable.cmake b/cmake/ProjectsTagsStable.cmake index a835291d4..5c1b3b930 100644 --- a/cmake/ProjectsTagsStable.cmake +++ b/cmake/ProjectsTagsStable.cmake @@ -7,8 +7,7 @@ endmacro() # External projects set_tag(osqp_REPOSITORY robotology-dependencies/osqp.git) set_tag(osqp_TAG v0.6.3.1) -set_tag(manif_REPOSITORY robotology-dependencies/manif.git) -set_tag(manif_TAG 0.0.4.103) +set_tag(manif_TAG 0.0.5) set_tag(qhull_TAG 2020.2) set_tag(CppAD_TAG 20240000.2) set_tag(proxsuite_TAG v0.6.4) diff --git a/cmake/ProjectsTagsUnstable.cmake b/cmake/ProjectsTagsUnstable.cmake index 17897286f..e61654d32 100644 --- a/cmake/ProjectsTagsUnstable.cmake +++ b/cmake/ProjectsTagsUnstable.cmake @@ -7,8 +7,7 @@ endmacro() # External projects set_tag(osqp_REPOSITORY robotology-dependencies/osqp.git) set_tag(osqp_TAG v0.6.3.1) -set_tag(manif_REPOSITORY robotology-dependencies/manif.git) -set_tag(manif_TAG 0.0.4.103) +set_tag(manif_TAG 0.0.5) set_tag(qhull_TAG 2020.2) set_tag(CppAD_TAG 20240000.2) set_tag(proxsuite_TAG v0.6.4) diff --git a/releases/latest.releases.yaml b/releases/latest.releases.yaml index 5a91d2d1b..0448fe230 100644 --- a/releases/latest.releases.yaml +++ b/releases/latest.releases.yaml @@ -9,8 +9,8 @@ repositories: version: v0.6.3.1 manif: type: git - url: https://github.com/robotology-dependencies/manif.git - version: 0.0.4.103 + url: https://github.com/artivis/manif.git + version: 0.0.5 qhull: type: git url: https://github.com/qhull/qhull.git From e985b689292cea246cc381ad4a694beb1ebd87da Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Wed, 4 Sep 2024 23:44:56 +0200 Subject: [PATCH 3/4] Add workaround to always build manif python bindings with clang-cl --- cmake/Buildmanif.cmake | 26 +++++++++++++++++++++++++- releases/latest.releases.yaml | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cmake/Buildmanif.cmake b/cmake/Buildmanif.cmake index 099939305..ac8fd25b6 100644 --- a/cmake/Buildmanif.cmake +++ b/cmake/Buildmanif.cmake @@ -4,6 +4,29 @@ include(YCMEPHelper) +# Workaround for https://github.com/artivis/manif/issues/311, if use use python bindings +# on Windows with MSVC we need to specify somehow the use of clang-cl +set(manif_CMAKE_GENERATOR_YCM_ARGS "") +set(manif_CLANG_CL_CMAKE_ARGS "") +if(ROBOTOLOGY_USES_PYTHON AND MSVC) + if("${CMAKE_GENERATOR}" MATCHES "Visual Studio") + # If Visual Studio is used, we specify the use of ClangCL via the CMake Generator Toolset option + list(APPEND manif_CMAKE_GENERATOR_YCM_ARGS CMAKE_GENERATOR "${CMAKE_GENERATOR}") + list(APPEND manif_CMAKE_GENERATOR_YCM_ARGS CMAKE_GENERATOR_TOOLSET "ClangCL") + else() + # Otherwise, we specify the use of clang-cl via CMAKE_C_COMPILER and CMAKE_CXX_COMPILER versions + if($ENV{VCINSTALLDIR} STREQUAL "") + message(FATAL_ERROR "Building robotology-superbuild with CMAKE_GENERATOR=${CMAKE_GENERATOR} and ROBOTOLOGY_USES_PYTHON is enabled, but no VCINSTALLDIR env variable defined.") + endif() + set(CANDIDATE_CLANG_CL_LOCATION $ENV{VCINSTALLDIR}\\Tools\\Llvm\\x64\\bin\\clang-cl.exe) + if(NOT EXISTS ${CANDIDATE_CLANG_CL_LOCATION}) + message(FATAL_ERROR "Building robotology-superbuild on Windows ROBOTOLOGY_USES_PYTHON is enabled requires the 'C++ Clang Compiler for Windows' and 'C++ Clang-cl for vXYZ build tools' components of Visual Studio, but ${CANDIDATE_CLANG_CL_LOCATION} was not found. Please install the required components and try again.") + endif() + list(APPEND manif_CLANG_CL_CMAKE_ARGS "-DCMAKE_C_COMPILER=${CANDIDATE_CLANG_CL_LOCATION}") + list(APPEND manif_CLANG_CL_CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CANDIDATE_CLANG_CL_LOCATION}") + endif() +endif() + # We pass CMAKE_CXX_STANDARD=17 as we encountered problems when using -march=native # and mixing libraries compiled with C++11 and C++17, see # https://github.com/artivis/manif/issues/274 @@ -13,7 +36,8 @@ ycm_ep_helper(manif TYPE GIT TAG master COMPONENT external FOLDER src - CMAKE_ARGS -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=${ROBOTOLOGY_USES_PYTHON} -DMANIFPY_PKGDIR:PATH=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR}) + ${manif_CMAKE_GENERATOR_YCM_ARGS} + CMAKE_ARGS -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_PYTHON_BINDINGS:BOOL=${ROBOTOLOGY_USES_PYTHON} -DMANIFPY_PKGDIR:PATH=${YCM_EP_INSTALL_DIR}/${ROBOTOLOGY_SUPERBUILD_PYTHON_INSTALL_DIR} ${manif_CLANG_CL_CMAKE_ARGS}) set(manif_CONDA_PKG_NAME manif) set(manif_CONDA_PKG_CONDA_FORGE_OVERRIDE ON) diff --git a/releases/latest.releases.yaml b/releases/latest.releases.yaml index 0448fe230..49eb3a23b 100644 --- a/releases/latest.releases.yaml +++ b/releases/latest.releases.yaml @@ -26,7 +26,7 @@ repositories: YCM: type: git url: https://github.com/robotology/ycm.git - version: v0.16.7 + version: v0.16.8 YARP: type: git url: https://github.com/robotology/yarp.git From 7625d46439b9d8b03d3365ca8fea2f2dead4d48b Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 5 Sep 2024 09:32:40 +0200 Subject: [PATCH 4/4] Document how to use the ROBOTOLOGY_USES_PYTHON option on Windows --- doc/cmake-options.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/cmake-options.md b/doc/cmake-options.md index ec23984c6..f951a47b5 100644 --- a/doc/cmake-options.md +++ b/doc/cmake-options.md @@ -355,11 +355,28 @@ sudo bash ./scripts/install_apt_python_dependencies.sh ~~~ #### Conda + To install python and the other required dependencies when using `conda-forge` provided dependencies, use: ~~~ conda install -c conda-forge python numpy swig pybind11 pyqt matplotlib h5py tornado u-msgpack-python pyzmq ipython ~~~ +##### Windows + +On Windows, enabling the `ROBOTOLOGY_USES_PYTHON` requires some care. If you need to enable both `ROBOTOLOGY_USES_PYTHON` and `ROBOTOLOGY_ENABLE_DYNAMICS_FULL_DEPS`, you need to make sure that +you have the "C++ Clang Compiler for Windows" and "C++ Clang-cl for vXYZ build tools" components of Visual Studio are installed, you can install them from the Visual Studio Installer: + +![clangclinstall](https://github.com/user-attachments/assets/af1e66e3-910e-4b34-b2e2-f1ef3cdd18d5) + +Furthermore, due to Python ignoring the directories in `PATH`, before running python code that uses the superbuild dependencies you need to run before: + +~~~python +import os +os.add_dll_directory(os.path.join(os.environ['ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX'], bin)) +~~~ + +see https://github.com/robotology/robotology-superbuild/issues/1268 for more details. + ### Check the installation Open a python interpreter and try to import modules, for example verify that `import yarp` works.