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

How can I reference an external project with Catkin?

asked 2014-08-06 18:11:18 -0600

wpd gravatar image

I would like to build a ROS node that uses some code from an external project. I certainly need to reference some header files from that project, and will probably also need to "pull in" some C++ source code from that project.

The simplest, dumbest, least maintainable way I could to this would be to simply copy the header file(s) and source file(s) into my ROS project.

I feel like there should be some way to tell Catkin or Cmake "Add this directory to the list of includes" and "Add that directory to VPATH". But, as Catkin and Cmake are totally new to me (as of about a week ago), I haven't the foggiest idea how to ask the Google to find the answer to my question. So I'll ask the community instead :-)

Thanks for any tips you can give me.

edit retag flag offensive close merge delete


Do the external projects use cmake? If they provide a cmake config file, you can find_package them just like opencv:

jbinney gravatar image jbinney  ( 2014-08-06 19:53:35 -0600 )edit

Unfortunately, it does not. It is a traditional Make based project. I would like to pull a few header files and source files from that project into mine.

wpd gravatar image wpd  ( 2014-08-06 20:15:19 -0600 )edit

So far, I have started down the path of writing my own "Findtrunk.cmake" file to find the project in my source tree (which I keep separate from my budding ROS source tree... for the moment) ,defining ${TRUNK_DIR} in Findtrunk.cmake, and adding ${TRUNK_DIR}/include to include_directories().

wpd gravatar image wpd  ( 2014-08-06 20:18:11 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-06 20:53:41 -0600

wpd gravatar image

All right, here is what I did. I feel like it is tremendously hacky, but it appears to work.

I created a cmake_modules/Findtrunk.cmake file containing:

#invented based on what I found in libfreenect/cmake_modules/Findlibusb-1.0.cmake
  # in cache already
else (TRUNK_DIR)

  if (TRUNK_DIR)
  endif (TRUNK_DIR)

    if (NOT trunk_FIND_QUIETLY)
      message(STATUS "Found trunk:")
      message(STATUS " - ${TRUNK_DIR}")
    endif (NOT trunk_FIND_QUIETLY)
  else (TRUNK_FOUND)
    if (trunk_FIND_REQUIRED)
      message(FATAL_ERROR "Could not find trunk")
    endif (trunk_FIND_REQUIRED)
  endif (TRUNK_FOUND)

endif (TRUNK_DIR)

I added the following 2 snippets to my CMakeLists.txt file:

find_package(trunk REQUIRED)


set_source_files_properties(${BBR_FILES} PROPERTIES LANGUAGE CXX)


and that seems to work. I'm not sure it's the most straightforward thing to do. I like the idea of creating a Findtrunk.cmake file so that others on my team might edit it to reflect the location of their trunk directory. We'll see if that ever comes to pass.

I would appreciate any questions, comments, or snide remarks more experienced folks would care to make regarding this approach. I'm certain that I'm not following any number of standard Cmake conventions (I noticed that other Findxxx.cmake files define INCLUDE_XXX_DIRS, for example), but this seems to work for me so far.

edit flag offensive delete link more


This seems like a good approach. Thanks for posting this!

jbinney gravatar image jbinney  ( 2014-08-07 02:06:33 -0600 )edit

Setting CMAKE_MODULE_PATH is forbidden in the ROS CMake Coding Standards document, although it doesn't say what folks should do in this case.

zultron gravatar image zultron  ( 2018-07-18 19:05:36 -0600 )edit

I don't recall why that was added to the docs ( ). Maybe the original author remembers?

Dirk Thomas gravatar image Dirk Thomas  ( 2018-08-03 13:11:40 -0600 )edit

The approach to extend the CMAKE_MODULE_PATH locally in your CMake seems fine to me.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-08-03 13:12:14 -0600 )edit

answered 2014-08-07 04:25:20 -0600

Chrissi gravatar image

If you want to use an external project you should never pull in c++ code. Just make it a library and use pkg-config. Have a look at this page on how to write pc files (very easy).

Afterwards you can just use:

pkg_check_modules(ARBITRARYNAME my_library-1.0)
edit flag offensive delete link more


Thanks for the idea. Unfortunately, I cannot easily modify the external project right now. Hence the reason I'm trying to just pull in a few of the source files into my project.

wpd gravatar image wpd  ( 2014-08-07 07:35:37 -0600 )edit

This is a good approach for most libraries, because they usually do support pkg-config.

joq gravatar image joq  ( 2014-08-13 11:24:34 -0600 )edit

Question Tools



Asked: 2014-08-06 18:11:18 -0600

Seen: 1,427 times

Last updated: Aug 07 '14