ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ament Cmake with header only library

asked 2022-08-04 07:30:17 -0500

Per Edwardsson gravatar image

updated 2022-08-04 08:07:37 -0500

I want to make a header only cpp library for use in ROS nodes and build it with ament such that it is indexed properly and ament_target_dependency finds it and propagates transitive flags. Here's my current setup:

In package foolib, CMakeLists.txt includes the following lines

add_library(foo INTERFACE include/foolib/foo.h)
set_target_properties(foo PROPERTIES CXX_STANDARD 20)
set_target_properties(foo PROPERTIES
  INTERFACE_LINK_DEPENDS stdc++fs
)
ament_export_libraries(
  foo
)

However, the install/foolib/lib folder contains no header files. Nor does any other folder under install/foolib, and the header is not copied (or symlinked) to any dependent projects. The header is nowhere in build/ or install/. The only way I can get the header file to get installed is to manually specify the include folder, which copies the whole include folder. This makes the header file appear, but since it's just a header file and not a CMake target, there's no information on what dependencies it has or what any specializations need to link (in this case, anyone that uses foo needs to link toward stdc++fs). Is this solvable with ament?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-05 13:03:01 -0500

sgermanserrano gravatar image

if you have your hpp file in the package include/package_name folder it's a matter of having the following in the CMakeLists

find_package(ament_cmake REQUIRED)

include_directories( include )

install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION include/${PROJECT_NAME}/)

ament_export_include_directories(include)

ament_package()

you'll be able to find the package and use the header in other packages.

edit flag offensive delete link more

Comments

Then my header will be available for the other packages. However, since it is a header and not built, it requires that however builds it links the correct deps. Which there is no way to declare with ament, afaik.

Per Edwardsson gravatar image Per Edwardsson  ( 2022-08-06 14:43:00 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-08-04 07:30:17 -0500

Seen: 581 times

Last updated: Aug 05 '22