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

Permit building python bindings separately from gz-math library #636

Open
wants to merge 8 commits into
base: gz-math8
Choose a base branch
from

Conversation

scpeters
Copy link
Member

🎉 New feature

Part of osrf/homebrew-simulation#2834

Summary

This allows the src/python_pybind11/CMakeLists.txt file to be built as a top-level cmake project against an external gz-math library. The first commit (646de60) is a patch from @traversaro used in conda, and the second commit (d2bae80) replaces the GZ_LIB_INSTALL_DIR cmake variable with CMAKE_INSTALL_LIBDIR (see GzPackaging.cmake:111) since GZ_LIB_INSTALL_DIR is not defined with the minimal cmake project added in 646de60.

Test it

  1. Invoke cmake on the root CMakeLists.txt with using -DSKIP_PYBIND11=ON to build and install the gz-math library without python bindings.
  2. Invoke cmake on src/python_pybind11/CMakeLists.txt with -DPython_EXECUTABLE=/path/to/python to build and install python bindings for a given python version
  3. Repeat 2 with for each desired version of python

I have a draft of an updated homebrew formula using this branch in osrf/homebrew-simulation#2836

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

traversaro and others added 2 commits October 11, 2024 11:23
Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
Use CMAKE_INSTALL_LIBDIR from GNUInstallDirs instead
of GZ_LIB_INSTALL_DIR, which won't be available if
only building python bindings.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind to add some instructions in the source compilation ?

Refer to https://brew.sh instead of duplicating the
brew installation command.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
* Describe Pybind11 as a dependency
* Document how to build bindings separately from the
  main gz-math library

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters
Copy link
Member Author

Do you mind to add some instructions in the source compilation ?

I added some in 54978b9; let me know if there is more that I should add

Copy link
Contributor

@j-rivero j-rivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problems found, just some comments to avoid duplicating code. Great work!

# 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.16)
set(GZ_MATH_VER 8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid about keeping this number in sync with bumps. As a workaround we can put a comment in the main CMakeLists.txt pointing to here. In the mid-term, it would be nice to integrate our CMake code to grab the version/name from git directly, probably using something like https://github.com/LecrisUT/CMakeExtraUtils/blob/main/cmake/DynamicVersion.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of using git for version information as fails for tarballs. Something a bit ugly but effective could be to grep the major version from the parent folder CMakeLists.txt .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we could extract the version numbers from package.xml, since we also have a workflow to keep those versions in sync

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prototype for extracting version numbers from package.xml: #639

cmake_minimum_required(VERSION 3.16)
set(GZ_MATH_VER 8)
project(gz-math${GZ_MATH_VER}-python VERSION ${GZ_MATH_VER})
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we can move the find_package logic from the main CMakeLists.txt to here so we don't have a duplicate logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the find_package(pybind11) call here in 06b8ab8 using the CMAKE_REQUIRE_FIND_PACKAGE_pybind11 variable to support finding it as an optional or required package depending on the context.

It's tricky to move the find_package(Python3) call to this folder because the Development component can be optional or required, depending on the context, but the FindPython3 module doesn't support CMAKE_REQUIRE_FIND_PACKAGE_* for its components. So I just left the find_package(Python3) code as is

src/python_pybind11/CMakeLists.txt Outdated Show resolved Hide resolved
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Moves find_package(pybind11) call to src/python_pybind11
folder. When invoked through the root CMakeLists.txt,
it treats pybind11 as an optional dependency, but when
invoked from that folder, it treats it as required by
setting CMAKE_REQUIRE_FIND_PACKAGE_pybind11 to TRUE.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

4 participants