From 5072602c5ea8b8434a11d42f296aeedf1b695498 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 23 Aug 2024 17:47:08 -0500 Subject: [PATCH 1/2] Prepare for 7.5.1 (#623) Signed-off-by: Addisu Z. Taddese --- CMakeLists.txt | 2 +- Changelog.md | 14 ++++++++++++++ package.xml | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ab62586..992d1b04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) #============================================================================ # Initialize the project #============================================================================ -project(gz-math7 VERSION 7.5.0) +project(gz-math7 VERSION 7.5.1) #============================================================================ # Find gz-cmake diff --git a/Changelog.md b/Changelog.md index cf15b24c..73823d0b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,19 @@ ## Gazebo Math 7.x +### Gazebo Math 7.5.1 (2024-08-23) + +1. Fix tolerance for axis-angle conversion of quaternions + * [Pull request #620](https://github.com/gazebosim/gz-math/pull/620) + +1. Added box examples in C++ and Python + * [Pull request #584](https://github.com/gazebosim/gz-math/pull/584) + +1. Check for 0 stddev when generating a random number using normal distribution + * [Pull request #615](https://github.com/gazebosim/gz-math/pull/615) + +1. Clean up nested namespaces + * [Pull request #603](https://github.com/gazebosim/gz-math/pull/603) + ### Gazebo Math 7.5.0 (2024-06-18) 1. Backport: Adding cone primitives. diff --git a/package.xml b/package.xml index 7d94fa1d..c182135c 100644 --- a/package.xml +++ b/package.xml @@ -2,7 +2,7 @@ gz-math7 - 7.5.0 + 7.5.1 Gazebo Math : Math classes and functions for robot applications Steve Peters Aditya Pande From 255f118f7972d37a8230971d17e4dcf3b57ea16f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:06:05 -0700 Subject: [PATCH 2/2] Permit building python bindings separately from gz-math library (#640) Backport of #636 with adapted package finding logic and a note about requiring cmake 3.22.1. This allows the src/python_pybind11/CMakeLists.txt file to be built as a top-level cmake project against an external gz-math library, with documentation added to the installation tutorial. The logic for finding pybind11 is also moved from the root CMakeLists.txt to src/python_pybind11/CMakeLists.txt to reduce code duplication. When invoked through the root CMakeLists.txt, pybind11 is treated as an optional dependency, but when invoked from the src/python_pybind11 folder, pybind11 is treated it as required by setting CMAKE_REQUIRE_FIND_PACKAGE_pybind11 to TRUE. Signed-off-by: Silvio Traversaro Signed-off-by: Steve Peters Co-authored-by: Silvio Traversaro (cherry picked from commit 17deea2ba86948c3a92aeed7cb541d05c9492c56) --- CMakeLists.txt | 14 ++-------- src/CMakeLists.txt | 2 +- src/python_pybind11/CMakeLists.txt | 26 +++++++++++++++++-- tutorials/installation.md | 41 ++++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 992d1b04..851d2a98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,28 +111,18 @@ else() set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) find_package(PythonLibs QUIET) # we found the interpreter but did we also find the libs? both are required - set(Python3_FOUND ${PYTHONLIBS_FOUND}) + set(Python3_Development_FOUND ${PYTHONLIBS_FOUND}) set(Python3_VERSION ${PYTHONLIBS_VERSION_STRING}) endif() else() find_package(Python3 QUIET COMPONENTS Interpreter Development) endif() - if (NOT Python3_FOUND) + if (NOT Python3_Development_FOUND) GZ_BUILD_WARNING("Python3 is missing: Python interfaces are disabled.") message (STATUS "Searching for Python3 - not found.") else() message (STATUS "Searching for Python3 - found version ${Python3_VERSION}.") - - set(PYBIND11_PYTHON_VERSION 3) - find_package(pybind11 2.2 QUIET) - - if (${pybind11_FOUND}) - message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") - else() - GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.") - message (STATUS "Searching for pybind11 - not found.") - endif() endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0adbed14..85582b6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}) add_subdirectory(graph) # Bindings subdirectories -if (pybind11_FOUND AND NOT SKIP_PYBIND11) +if (Python3_Development_FOUND AND NOT SKIP_PYBIND11) add_subdirectory(python_pybind11) endif() diff --git a/src/python_pybind11/CMakeLists.txt b/src/python_pybind11/CMakeLists.txt index c382557a..da63b305 100644 --- a/src/python_pybind11/CMakeLists.txt +++ b/src/python_pybind11/CMakeLists.txt @@ -1,4 +1,16 @@ -if(${CMAKE_VERSION} VERSION_LESS "3.12.0") +# Detect if we are doing a standalone build of the bindings, using an external gz-math +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + cmake_minimum_required(VERSION 3.22.1) + set(GZ_MATH_VER 7) + project(gz-math${GZ_MATH_VER}-python VERSION ${GZ_MATH_VER}) + find_package(gz-math${PROJECT_VERSION_MAJOR} REQUIRED) + set(PROJECT_LIBRARY_TARGET_NAME "gz-math${PROJECT_VERSION_MAJOR}::gz-math${PROJECT_VERSION_MAJOR}") + # require python dependencies to be found + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + set(CMAKE_REQUIRE_FIND_PACKAGE_pybind11 TRUE) + include(GNUInstallDirs) + include(CTest) +elseif(${CMAKE_VERSION} VERSION_LESS "3.12.0") # TODO: remove once the minimum CMake version is increased if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") # pybind11 logic for setting up a debug build when both a debug and release @@ -8,6 +20,16 @@ if(${CMAKE_VERSION} VERSION_LESS "3.12.0") endif() endif() +set(PYBIND11_PYTHON_VERSION 3) +find_package(pybind11 2.2 QUIET) + +if (${pybind11_FOUND}) + message(STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") +else() + message(WARNING "pybind11 is missing: Python interfaces are disabled.") + return() +endif() + message(STATUS "Building pybind11 interfaces") set(BINDINGS_MODULE_NAME "math${PROJECT_VERSION_MAJOR}") # Split from main extension and converted to pybind11 @@ -96,7 +118,7 @@ if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) endif() else() # If not a system installation, respect local paths - set(GZ_PYTHON_INSTALL_PATH ${GZ_LIB_INSTALL_DIR}/python) + set(GZ_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/python) endif() set(GZ_PYTHON_INSTALL_PATH "${GZ_PYTHON_INSTALL_PATH}/gz") diff --git a/tutorials/installation.md b/tutorials/installation.md index 94e77b5d..37ac71cc 100644 --- a/tutorials/installation.md +++ b/tutorials/installation.md @@ -38,9 +38,9 @@ you should use `ign-math<#>`. ### macOS -On macOS, add OSRF packages: +On macOS, after installing the [Homebrew package manager](https://brew.sh), +add OSRF packages: ``` - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew tap osrf/simulation ``` @@ -92,6 +92,13 @@ The optional Eigen component of Gazebo Math requires: sudo apt-get install libeigen3-dev ``` +The optional Python bindings of Gazebo Math require: + +* [Pybind11](https://pybind11.readthedocs.io/en/stable/index.html). Refer to the [Pybind11 Documentation](https://pybind11.readthedocs.io/en/stable/installing.html) for installation instructions. On Ubuntu systems, `apt-get` can be used to install Pybind11: + ``` + sudo apt-get install python3-pybind11 + ``` + The optional Ruby tests of Gazebo Math require: * [Ruby](https://www.ruby-lang.org/). Refer to the [Ruby Documentation](https://www.ruby-lang.org/downloads/) for installation instructions. On Ubuntu systems `apt-get` can be used to install Ubuntu Package `ruby-dev`: @@ -228,6 +235,36 @@ The optional Eigen component of Gazebo Math requires: cmake --install . --config Release ``` +### cmake parameters + +| Name | Type | Default | Description | +|-----------------|------|---------|--------------------------------------------| +| `SKIP_PYBIND11` | BOOL | OFF | Set to ON to skip building python bindings | + +### Building Python bindings separately from main library + +If you want to build Python bindings separately from the main gz-math library +(for example if you want to build Python bindings for multiple versions of Python), +you can invoke cmake on the `src/python_pybind11` folder instead of the root folder. +This requires cmake version 3.22.1 due to the use of a `CMAKE_REQUIRE_FIND_PACKAGE_*` +variable, which is newer than the minimum required version of cmake for gz-math7. +Specify the path to the python executable with which you wish to build bindings +in the `Python3_EXECUTABLE` cmake variable. +Specify the install path for the bindings in the `CMAKE_INSTALL_PREFIX` +variable, and be sure to set your `PYTHONPATH` accordingly after install. + +```bash +cd gz-math +mkdir build_python3 +cd build_python3 +cmake ../src/python_pybind11 \ + -DPython3_EXECUTABLE=/usr/local/bin/python3.12 \ + -DCMAKE_INSTALL_PREFIX= +``` + +See the homebrew [gz-math8 formula](https://github.com/osrf/homebrew-simulation/blob/ccda47647ed9aeb38f0ea1ec8804fd1501058de1/Formula/gz-math8.rb#L12-L52) +for an example of building bindings for multiple versions of Python. + # Documentation API and tutorials can be found at [https://gazebosim.org/libs/math](https://gazebosim.org/libs/math).