Ament Cmake with header only library
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 amenttargetdependency 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?
Asked by Per Edwardsson on 2022-08-04 07:30:17 UTC
Answers
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.
Asked by sgermanserrano on 2022-08-05 13:03:01 UTC
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.
Asked by Per Edwardsson on 2022-08-06 14:43:00 UTC
Comments