-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add macros for generating pybind11 bindings #400
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Bi0T1N <[email protected]>
if (SKIP_PYBIND11) | ||
message(STATUS "SKIP_PYBIND11 set - disabling python bindings") | ||
else() | ||
find_package(Python3 ${GZ_PYTHON_VERSION} QUIET COMPONENTS Interpreter Development) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gazebosim/gz-math#588 updated the code in gz-math to use OPTIONAL_COMPONENTS
here.
https://github.com/gazebosim/gz-math/blob/ef2211c6292929ea6a8471815cf83315c1b891cb/CMakeLists.txt#L102-L104
Mind updating this to match?
cc @scpeters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I haven't been completely consistent with using COMPONENTS
or OPTIONAL_COMPONENTS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, in gz-math8 and sdformat15, I used made finding the Python3 Interpreter REQUIRED
and used OPTIONAL_COMPONENTS
to find Development, while we didn't apply this logic in gz-transport or gz-sim, probably because I didn't realize the inconsistency
- https://github.com/gazebosim/gz-math/blob/main/CMakeLists.txt#L102-L105
- https://github.com/gazebosim/sdformat/blob/sdf14/CMakeLists.txt#L87-L90
- https://github.com/gazebosim/gz-transport/blob/main/CMakeLists.txt#L61
- https://github.com/gazebosim/gz-sim/blob/main/CMakeLists.txt#L209
I think I do recommend the approach used in gz-math and sdformat, but I also recognize the lack of flexibility in finding packages from a macro. I would suggest calling find_package(Python3 ...)
from within the macro if NOT Python3_Development_FOUND
, which would allow a package to use their own call to find_package(Python3)
but fall back to a good default if it hasn't been searched for yet
# USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION Install modules in default system path if ON | ||
# USE_DIST_PACKAGES_FOR_PYTHON Use dist-package over site-package for module installation if ON | ||
# | ||
macro(gz_add_pybind_project_settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies for not reviewing this sooner
I actually deprecated GzPython
in #431; I think these new macros should be in a new file like GzPybind.cmake
🎉 New feature
Closes #215
Summary
This adds CMake macros to remove code duplication for creating pybind11 bindings.
The only problem that occurs is that it destroys the used structure in
CMakeLists.txt
(e.g. for gz-math):The other two macros are fine:
src/CMakeLists.txt
:Test it
/ws/install
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/ws/install/
make -j && make install
source /ws/install/setup.bash
, changeCMakeLists.txt
to usegz-cmake4
and the new macrosmkdir build && cd build && cmake .. && make -j
Checklist
codecheck
passed (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-by
messages.🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸