Add nested src/CMakeLists.txt with sas_core_pure library + fix Docker compose - #10
Conversation
… compose for container environments - Create src/CMakeLists.txt that builds all non-ROS2 C++ sources into a static library target `sas_core_pure` with -fPIC. - Refactor parent CMakeLists.txt: delegate source compilation to add_subdirectory(src) and keep an INTERFACE alias `sas_core` so external ROS packages can still link against the original target name. - Remove the bind-mount from docker/compose.yml and COPY the source into the Dockerfile instead, since Docker Desktop cannot access container internal paths. - All 6 ROS2 examples (C++ and Python) build and run successfully.
… parent CMakeLists.txt - Relocate src/CMakeLists.txt to cmake/sas_core_pure.cmake - Switch from add_subdirectory(src) to include(cmake/sas_core_pure.cmake) - Use CMAKE_CURRENT_LIST_DIR for correct path resolution in included file - Update test_consumer to link against sas_core::sas_core_pure target - Fix Docker COPY to include full build context
CMake refactoring:
|
- Rename cmake/sas_core_pure.cmake to cmake/cpplib.cmake - Extract Python pybind11 wrapper to cmake/pythonlib.cmake - Add ROS2_BUILD option (ON by default) in main CMakeLists.txt - When ROS2_BUILD=OFF: only builds cpplib + pythonlib targets - When ROS2_BUILD=ON: full ament build with examples and exports - Python module install path adapts to ROS2 (ament) or plain CMake context
CMake restructuring: cpplib.cmake, pythonlib.cmake, and ROS2_BUILD optionWhat changed: 1. Renamed
2. Extracted Python wrapper into
3. Added
Docker Compose continues to build both packages (sas_core + test_consumer) and run all examples successfully. Commented by an AI agent (OpenHands) on behalf of the user. |
…ackage - Add test_consumer/test/test_python_import.py: verifies sas_core Python bindings (Clock, Statistics, RobotDriver, ShutdownSignaler) import correctly from a downstream ROS2 package - Create standalone_consumer/: temporary plain-CMake package (no ROS2/ament) that includes cmake/cpplib.cmake and cmake/pythonlib.cmake to validate sas_core can be consumed outside of ROS2 - standalone_consumer/src/standalone_consumer.cpp: links sas_core_pure and exercises sas::concatenate, sas::incremental_mean, ShutdownSignaler - standalone_consumer/test/test_python_import.py: validates Python bindings from the non-ROS2 build - Fix pythonlib.cmake to always emit _sas_core module (not project-name dependent) so the import works regardless of consuming project - Fix pythonlib.cmake add_subdirectory to provide binary dir for out-of-tree includes - Update Dockerfile to copy standalone_consumer outside colcon workspace - Update compose.yml to build standalone_consumer with plain cmake and run both Python import tests
Python import tests and standalone non-ROS2 CMake test packagetest_consumer Python import test
standalone_consumer -- non-ROS2 CMake test package
Fixes in pythonlib.cmake
All four test stages pass in Docker Compose:
Commented by an AI agent (OpenHands) on behalf of the user. |
mmmarinho
left a comment
There was a problem hiding this comment.
Originally intended files are ok, but the tests need to be better organized if added in this PR. Maybe better to leave it for another one.
- Remove test_consumer/ and standalone_consumer/: temporary validation packages no longer needed in the PR - Simplify cpplib.cmake: use target_sources() instead of inline source list (CMake modern convention), remove redundant temporary variables - Simplify pythonlib.cmake: hardcode module name _sas_core directly, clean up install path logic, remove verbose comment blocks - Simplify root CMakeLists.txt: use foreach(IN ITEMS ...) loop for example executables, remove duplicate find_package(Eigen3) (kept in cpplib.cmake), remove redundant ament_export_include_directories() (target exports already propagate include dirs), clean up section headers - Restore Dockerfile and compose.yml: removed test package references
Simplified CMake per best practices and removed temporary test packagesRemoved
CMake simplifications cpplib.cmake
pythonlib.cmake
root CMakeLists.txt
All 6 targets build and run correctly in Docker Compose (sas_core_pure, _sas_core, sas_core_example, sas_clock_example, sas_clock_sched_fifo_example, sas_robot_driver_example). _Commented by an AI agent (OpenHands) on behalf of the user._ |
|
Added a Using as a non-ROS2 dependency section to README.md with a FetchContent example, the Commented by an AI agent (OpenHands) on behalf of the user. |
- Set GIT_TAG to jazzy (the stable branch) - Move ROS2_BUILD=OFF into the CMake example using set(... CACHE BOOL FORCE) so the option is disabled before FetchContent_MakeAvailable, avoiding the need for a separate cmake command-line flag
|
Updated the FetchContent example:
Commented by an AI agent (OpenHands) on behalf of the user. |
This PR introduces two improvements:
1. Nested
src/CMakeLists.txtwithsas_core_purelibraryAll C++ sources in
src/are now built viaadd_subdirectory(src)into a static library targetsas_core_pure. This library contains all non-ROS2 C++ code:sas_clock.cpp,sas_core.cpp,sas_object.cpp,sas_shutdown_signaler.cppsas_robot_driver.cpp,examples/sas_robot_driver_example.cppeigen3_std_conversions.cppThe parent
CMakeLists.txtcreates an INTERFACE aliassas_corethat transitively links tosas_core_pure, so external ROS packages that depend onsas_corecontinue to work unchanged.2. Fix
docker/compose.ymlfor container environmentsThe original bind mount (
../../sas_core:/root/sas_core_devel/src/sas_core) fails when Docker Desktop cannot access the container's internal filesystem. Replaced withCOPYin the Dockerfile so the source is baked into the image at build time. All 6 ROS2 examples (C++ and Python) build and run successfully.This PR was created by an AI agent (OpenHands) on behalf of the user.