How to Add Git Repository as Submodule in ROS2 Package?

asked 2023-05-10 18:25:09 -0500

omgitsmichael gravatar image

updated 2023-05-11 14:53:27 -0500

Hey! So it's basically as the questions states. I have a C++ repository that I wanted to add to a package as a submodule.

So the structure is something along the lines of:

/Workspace
    /package
        /package stuff
        /git repo submodule

What I've gone ahead and done is inside the CMakeLists.txt file I've added:

add_subdirectory(<git repo folder name>)

This allows the git repository code to compile. Then I added it to the target_include_directories:

target_include_directories(node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${CMAKE_CURRENT_SOURCE_DIR}/<git repo folder name>)

I assumed this would be all I need to do to be able to use the code in the submodule inside of my node, but when I go to include the files from the subdirectory it is unable to find the include. Does anyone by any chance have any ideas on how to do this/steer me in the correct direction on how to do this?

Also would it be possible to get another package that is taking in this package to also use the C++ repository?

Thank you!

EDIT:

I think I was able to get half of this working. It looks like I am able to use the code from the git submodule if I do:

target_link_libraries(node PRIVATE
    <git submodule project name>
)

However, I can only use the submodule code in that one package. Is there any way the other packages can also potentially utilize code from the submodule without having each package have the git repo as a submodule?

For further context. I am essentially trying to create a "third party" package. Where I have a package that has functions/libraries I've created that I would use throughout my workspace and various packages

EDIT2:

I've tried wrapping ament_cmake around the repository cmake and also added a package.xml file, but it doesn't seem to help with finding the files when it has sort of become a package. I can find the package like a package but cant find any of the files.

edit retag flag offensive close merge delete

Comments

I was messing around with my git repository by adding a package.xml and adding a few ament_cmake lines in the CMakeLists file and I was able to get the package to be seen by other packages, however, the code from the repository couldn't be found from the other packages. Does anyone know why? If I can wrap my repository CMake file in some ament things and then add the package.xml file to get it to work that would be fine

omgitsmichael gravatar image omgitsmichael  ( 2023-05-11 13:08:38 -0500 )edit