0
$\begingroup$

Rosanswers logo

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)
project(gperftools)

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

include(ExternalProject)
ExternalProject_Add(
    gperftools_src
    PREFIX gperftools_src
    URL http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
    URL_MD5 5e5a981caf9baa9b4afe90a82dcf9882
    CONFIGURE_COMMAND ./configure --enable-frame-pointers --prefix=<INSTALL_DIR>
    BUILD_IN_SOURCE 1
)

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...


Originally posted by brice rebsamen on ROS Answers with karma: 1001 on 2014-01-15

Post score: 4


Original comments

Comment by William on 2014-01-15:
You could use the CMAKE_CURRENT_BINARY_DIR variable to get ~/catkin_ws/build/gperftools/. See: http://www.cmake.org/Wiki/CMake_Useful_Variables Also, this is not going to work for the install case. This is one of the reasons we don't do this normally.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html

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:

http://www.ros.org/reps/rep-0136.html

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.

EDIT:

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

catkin_package(
  INCLUDE_DIRS ${gperftools_INCLUDE_DIRS}
  LIBRARIES ${gperftools_LIBRARIES}
)

Originally posted by William with karma: 17335 on 2014-01-15

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by brice rebsamen on 2014-01-15:
+1 for pointing to CMake's ExternalProject. But the main part of my question is still unanswered.

Comment by William on 2014-01-15:
gperftools should provide some mechanism for discovery, like pkg-config or a CMake FindGperftools.cmake module.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.