Ask Your Question

how to add non cmake based libraries to a catkin build?

asked 2014-01-15 07:59:34 -0500

brice rebsamen gravatar image

updated 2014-01-15 13:08:18 -0500

I want to use gperftools with several of my packages. Instead of having to build it and install it separately, I'd like to create a package for it so that it's automatically built with the rest of my code. It also allows me to control what version is used.

So I want to create a package for gperftools that would download the archive, configure it, build it and export the headers and libs. And yes I know that it is not recommended to download when building!

The problem is that gperftools not cmake based: it uses the autoconf tools and Make... In rosbuild we add it done with the download_unpack_build macro. What this was doing was:

  • download and check the md5 sum: gperftools/build/gperftools-2.0.tar.gz
  • unpack in the build folder: gperftools/build/gperftools-2.0/
  • configure and build --> create binaries, libs and headers

Then in the manifest, we would export the location of those headers and libs by pointing (-I and -L) to relevant items in gperftools/build/gperftools-2.0/

I would like to recreate that with catkin. I can download, unpack and build using cmake's add_custom_command. But I'm wondering what I should do with the output of the build so that other packages can find the headers and the libs...

In a regular catkin package, exports are listed in the catkin_package command. Usually these are resources in the src space. In my case, these resources are going to be located in the build space. Should I use the install command?

Note: If there is a ready made solution for gperftools I'd like to hear about it. But I'd also like to get an answer to my problem as the same situation is likely to occur with some other more exotic libraries that we are planning to use.

EDIT: following william's recommendation, I set it up using ExternalProject:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED)
#  INCLUDE_DIRS include
#  LIBRARIES gperftools
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib

    PREFIX gperftools_src
    URL <a href=""></a>
    URL_MD5 5e5a981caf9baa9b4afe90a82dcf9882
    CONFIGURE_COMMAND ./configure --enable-frame-pointers --prefix=<INSTALL_DIR>

This results that:

  • the project is built in ~/catkin_ws/build/gperftools/gperftools_src/src/gperftools_src (i.e. the package build space + gperftools_src/src/gperftools_src)
  • header files are installed in ~/catkin_ws/build/gperftools/gperftools_src/include
  • libs are installed in ~/catkin_ws/build/gperftools/gperftools_src/lib
  • pc files are installed in ~/catkin_ws/build/gperftools/gperftools_src/lib/pkgconfig
  • executables are installed in ~/catkin_ws/build/gperftools/gperftools_src/bin

So again, how are other packages going to find those? If I had a variable pointing to the package's build space, maybe I could export the pc files in catkin_package:

catkin_package(CFG_EXTRAS ${catkin_PACKAGE_BUILD_DIR}/gperftools_src/lib/pkgconfig/libprofiler.pc)

But I could not find any variable pointing to the build dir...

edit retag flag offensive close merge delete


You could use the `CMAKE_CURRENT_BINARY_DIR` variable to get `~/catkin_ws/build/gperftools/`. See: Also, this is not going to work for the install case. This is one of the reasons we don't do this normally.

William gravatar image William  ( 2014-01-15 13:32:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-15 08:30:58 -0500

William gravatar image

updated 2014-01-15 12:15:03 -0500

For what you are describing I would recommend CMake's ExternalProject system:

It is functionally equivalent to the download_unpack_build like macros in rosbuild. The best thing to do would be to setup a REP-0136 compliant non-catkin package. That way it can be released and it can be built as part of a catkin workspace without downloading during the build:

However, if you are not going to release this or release things which depend on it, then it probably is fine to use CMake's ExternalProject system.


If you wan to pass along the link flags and include directories to downstream catkin packages, you will need to create a CMake Config file or use catkin to generate one for you. This catkin macro effectively generates a <package_name>-config.cmake file for you based on the parameters, it should look like this:

find_package(catkin REQUIRED)

# Somehow set gpertools_LIBRARIES and gperftools_INCLUDE_DIRS

edit flag offensive delete link more


+1 for pointing to CMake's ExternalProject. But the main part of my question is still unanswered.

brice rebsamen gravatar image brice rebsamen  ( 2014-01-15 11:40:35 -0500 )edit

`gperftools` should provide some mechanism for discovery, like `pkg-config` or a CMake `FindGperftools.cmake` module.

William gravatar image William  ( 2014-01-15 12:11:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-01-15 07:59:34 -0500

Seen: 1,759 times

Last updated: Jan 15 '14