Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,30 @@ jobs:
ROS_DISTRO: ${{ matrix.ros }}
PIP_BREAK_SYSTEM_PACKAGES: 1
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: ros-tooling/action-ros-ci@v0.4
with:
target-ros2-distro: ${{ matrix.ros }}
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v6
with:
name: colcon-logs-${{ matrix.ros }}
path: ros_ws/log

standalone_cmake:
runs-on: ubuntu-latest
name: Standalone CMake + ctest
steps:
- uses: actions/checkout@v5
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++ catch2 pybind11-dev python3-dev
- name: Configure
# CMAKE_DISABLE_FIND_PACKAGE_ament_cmake forces the non-ament branch.
run: >
cmake -S . -B build -DBUILD_TESTING=ON
-DCMAKE_DISABLE_FIND_PACKAGE_ament_cmake=ON
- name: Build
run: cmake --build build -j
- name: Test
run: ctest --test-dir build --output-on-failure
95 changes: 50 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(polymath_kinematics)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
add_link_options(-Wl,-no-undefined)
endif()

# Ubuntu detection (override with -DBUILD_JAMMY=ON/OFF)
Expand All @@ -43,15 +42,21 @@ if(NOT DEFINED BUILD_JAMMY)
endif()
endif()

# Find packages
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
# Find packages. ament_cmake is QUIET so the wheel build (no ROS2) falls
# through to a plain CMake configuration.
find_package(ament_cmake QUIET)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)
find_package(pybind11 CONFIG REQUIRED)

# C++ library with all kinematic models
add_library(polymath_kinematics SHARED
# C++ library with all kinematic models. SHARED under ROS2 (ament exports a
# linkable .so to downstream packages); STATIC under wheel builds so the
# pybind11 module is self-contained and the wheel ships a single .so.
if(ament_cmake_FOUND)
set(_polymath_kinematics_lib_type SHARED)
else()
set(_polymath_kinematics_lib_type STATIC)
endif()
add_library(polymath_kinematics ${_polymath_kinematics_lib_type}
src/articulated_model.cpp
src/articulated_projector.cpp
src/bicycle_model.cpp
Expand All @@ -63,41 +68,37 @@ target_include_directories(polymath_kinematics PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(polymath_kinematics PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Python bindings
set(PYBIND_TARGET polymath_kinematics_cpp)
pybind11_add_module(${PYBIND_TARGET}
src/kinematics_pybind.cpp
)
set_target_properties(${PYBIND_TARGET} PROPERTIES LINK_OPTIONS "")
target_link_libraries(${PYBIND_TARGET} PRIVATE polymath_kinematics)
_ament_cmake_python_register_environment_hook()
install(TARGETS ${PYBIND_TARGET} DESTINATION "${PYTHON_INSTALL_DIR}")
pybind11_add_module(polymath_kinematics_cpp src/kinematics_pybind.cpp)
target_link_libraries(polymath_kinematics_cpp PRIVATE polymath_kinematics)

# Install C++ library
install(
TARGETS polymath_kinematics
EXPORT ${PROJECT_NAME}_TARGETS
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install(
EXPORT ${PROJECT_NAME}_TARGETS
NAMESPACE ${PROJECT_NAME}::
DESTINATION share/${PROJECT_NAME}/cmake
)
install(
DIRECTORY include/
DESTINATION include/
)
if(ament_cmake_FOUND)
find_package(ament_cmake_python REQUIRED)

# Python module
ament_python_install_package(${PROJECT_NAME})
install(
TARGETS polymath_kinematics
EXPORT ${PROJECT_NAME}_TARGETS
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
install(
EXPORT ${PROJECT_NAME}_TARGETS
NAMESPACE ${PROJECT_NAME}::
DESTINATION share/${PROJECT_NAME}/cmake
)
install(DIRECTORY include/ DESTINATION include/)

ament_python_install_package(${PROJECT_NAME})
install(TARGETS polymath_kinematics_cpp DESTINATION "${PYTHON_INSTALL_DIR}")
else()
# Wheel build: scikit-build-core installs the extension at the wheel root.
install(TARGETS polymath_kinematics_cpp DESTINATION .)
endif()

# Testing
if(BUILD_TESTING)
find_package(ament_cmake_pytest REQUIRED)
include(CTest)

if(BUILD_JAMMY)
Expand Down Expand Up @@ -126,12 +127,16 @@ if(BUILD_TESTING)
add_kinematics_catch2_test(test_bicycle_projector test/test_bicycle_projector.cpp)
add_kinematics_catch2_test(test_articulated_projector test/test_articulated_projector.cpp)
add_kinematics_catch2_test(test_differential_drive_projector test/test_differential_drive_projector.cpp)
ament_add_pytest_test(test_python_bindings test)
endif()

# Export targets
ament_export_targets(${PROJECT_NAME}_TARGETS HAS_LIBRARY_TARGET)
ament_export_include_directories(include)
ament_export_libraries(polymath_kinematics)
if(ament_cmake_FOUND)
find_package(ament_cmake_pytest REQUIRED)
ament_add_pytest_test(test_python_bindings test)
endif()
endif()

ament_package()
if(ament_cmake_FOUND)
ament_export_targets(${PROJECT_NAME}_TARGETS HAS_LIBRARY_TARGET)
ament_export_include_directories(include)
ament_export_libraries(polymath_kinematics)
ament_package()
endif()
9 changes: 6 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<package format="3">
<name>polymath_kinematics</name>
<version>0.1.0</version>
<description>Simple mixed C++/Python kinematics library</description>
<maintainer email="dev@polymathrobotics.com">Polymath Robotics</maintainer>
<description>Mixed C++/Python kinematics library for vehicle models</description>
<maintainer email="engineering@polymathrobotics.com">Polymath Engineering</maintainer>
<license>Apache-2.0</license>
<author email="zeerek@polymathrobotics.com">Zeerek Ahmad</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>

<build_depend>pybind11_vendor</build_depend>
<depend>pybind11_vendor</depend>
<depend>python3-numpy</depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_cmake_test</test_depend>
<test_depend>catch2</test_depend>

<export>
Expand Down
Loading