how to add non cmake based libraries to a catkin build?
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 <a href="http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz">http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz</a>
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...
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.