gazebosim / gz-cmake

A set of CMake modules that are used by the C++-based Gazebo projects.
https://gazebosim.org/libs/cmake
Apache License 2.0
27 stars 31 forks source link

Add macros for generating pybind11 bindings #400

Open Bi0T1N opened 11 months ago

Bi0T1N commented 11 months ago

🎉 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):

#============================================================================
# Set project-specific options
#============================================================================

option(SKIP_SWIG
      "Skip generating ruby bindings via Swig"
      OFF)

include(GzPython) <-- here we don't only set project-specific options - we search for Python
gz_add_pybind_project_settings()

The other two macros are fine:

########################################
# Python bindings
gz_search_for_pybind()

src/CMakeLists.txt:

# Bindings subdirectories
gz_add_pybind_directory(python_pybind11)

Test it

  1. Compile packages up to gz-math7 to /ws/install
  2. In gz-cmake project, run mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/ws/install/
  3. Run make -j && make install
  4. Open a new terminal and change directory to gz-math
  5. Run source /ws/install/setup.bash, change CMakeLists.txt to use gz-cmake4 and the new macros
  6. Run mkdir build && cd build && cmake .. && make -j

Checklist

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.

🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸

azeey commented 11 months ago

LGTM! but I'll hold off merging so @j-rivero can take a look since he commented on #215.

azeey commented 3 months ago

To focus our efforts on the Ionic release, I'll go ahead and remove the beta label from this. I don't think this is a breaking change, so we can merge it after Ionic.