After some months, I am revisiting this question, and I found a solution. For completeness sake, I post my solution here. It turned out that using ExternalProject_Add
was still the easiest solution, after all.
The package contains only CMakeLists.txt, package.xml, readme, and license files.
Relevant parts of package.xml:
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>autoconf</depend>
<depend>libtool</depend>
The CMakeLists looks like this:
cmake_minimum_required(VERSION 3.5)
project(igh_eml)
find_package(ament_cmake REQUIRED)
include(ExternalProject)
ExternalProject_Add(upstream_igh_eml # Name for custom target
#--Download step--------------
GIT_REPOSITORY https://github.com/ribalda/ethercat.git
#The following TAG should correspond to the same version as your installed kernel modules
GIT_TAG 7d73d5b2b372b37b95ce5d7bf16aa5b032190004
TIMEOUT 30 # Time allowed for file download operations
#--Update/Patch step----------
UPDATE_COMMAND touch <SOURCE_DIR>/config.h COMMAND mkdir -p <SOURCE_DIR>/include <SOURCE_DIR>/lib # Source work-tree update command
#--Configure step-------------
CONFIGURE_COMMAND touch <SOURCE_DIR>/ChangeLog COMMAND autoreconf -i <SOURCE_DIR> COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-kernel --enable-hrtimer --enable-tool # Build tree configuration command
#--Build step-----------------
BUILD_IN_SOURCE 1 # Use source dir for build dir
#--Install step---------------
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}" # Installation prefix
BUILD_COMMAND cd <SOURCE_DIR> COMMAND make -j8
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX})
ament_export_include_directories(include)
ament_export_libraries(ethercat)
ament_package()
For understanding: ethercat
is a library built by that project and it resides in ${CMAKE_CURRENT_BINARY_DIR}/lib
after ExternalProject_Add
completed. Headers are in ${CMAKE_CURRENT_BINARY_DIR}/include
after the macro. I was surprised that ament_export_include_directories(include)
actually did the right thing even though I neither specified an absolute path nor is there such a directory in the source repository.
I would actually expect this to still be the preferred way to do this in ROS 2 (as essentially 'nothing' has changed afaik).
At least on
github.com/ros2
, the*_vendor
packages useExternalProject_Add(..)
quite a bit. See ros2/yaml_cpp_vendor/CMakeLists.txt for instance.It would be good if you could describe the issues you encountered with
ExternalProject_Add
in your ROS 2 port.@gvdhoorn Thank you for the fast response and the link to yamlccp. That looks great! I will provide a more detailed description of my issues. For the moment, we continued work by making our own debian for the upstream library, and installing that on the system.
Another possible option would be to implement a
colcon-automake/autoconf
extension which invokes these tools directly. That would avoid the need to use CMake /ExternalProject
. It would require more effort for the first package but any following packages would work out-of-the-box. Feel free to ask questions if you want to go that route. E.g.colcon-cmake
is also just an extension to support CMake based packages in colcon.