Permit building python bindings separately from gz-math library#636
Permit building python bindings separately from gz-math library#636
Conversation
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>
ahcorde
left a comment
There was a problem hiding this comment.
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>
I added some in 54978b9; let me know if there is more that I should add |
j-rivero
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
or we could extract the version numbers from package.xml, since we also have a workflow to keep those versions in sync
There was a problem hiding this comment.
prototype for extracting version numbers from package.xml: #639
There was a problem hiding this comment.
I've also opened gazebosim/gz-cmake#456 adding the python script from #639 and a cmake helper function. If you don't mind approving this PR for now so we can start to fix CI, I will follow-up by using the gz-cmake helper once it has been merged and released
src/python_pybind11/CMakeLists.txt
Outdated
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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>
|
https://github.com/Mergifyio backport gz-math7 |
✅ Backports have been createdDetails
|
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 <silvio.traversaro@iit.it> Signed-off-by: Steve Peters <scpeters@openrobotics.org> Co-authored-by: Silvio Traversaro <silvio.traversaro@iit.it> (cherry picked from commit 17deea2) # Conflicts: # CMakeLists.txt # src/python_pybind11/CMakeLists.txt
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 <silvio.traversaro@iit.it> Signed-off-by: Steve Peters <scpeters@openrobotics.org> Co-authored-by: Silvio Traversaro <silvio.traversaro@iit.it> (cherry picked from commit 17deea2)
The ability to build python bindings separately from the core library was added in #636 and is currently used when building the homebrew formulae but is not directly tested in CI. This adds a quick test to the Ubuntu GitHub actions workflow to compile the python bindings after compiling example code. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
The ability to build python bindings separately from the core library was added in #636 and is currently used when building the homebrew formulae but is not directly tested in CI. This adds a quick test to the Ubuntu GitHub actions workflow to compile the python bindings after compiling example code. Signed-off-by: Steve Peters <scpeters@openrobotics.org>
🎉 New feature
Part of osrf/homebrew-simulation#2834
Summary
This allows the
src/python_pybind11/CMakeLists.txtfile 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 theGZ_LIB_INSTALL_DIRcmake variable withCMAKE_INSTALL_LIBDIR(see GzPackaging.cmake:111) sinceGZ_LIB_INSTALL_DIRis not defined with the minimal cmake project added in 646de60.Test it
CMakeLists.txtwith using-DSKIP_PYBIND11=ONto build and install the gz-math library without python bindings.src/python_pybind11/CMakeLists.txtwith-DPython_EXECUTABLE=/path/to/pythonto build and install python bindings for a given python versionI have a draft of an updated homebrew formula using this branch in osrf/homebrew-simulation#2836
Checklist
codecheckpassed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-bymessages.