Find non-ROS package in rosbuild CMakeLists

asked 2017-03-09 04:35:04 -0600

OMC gravatar image

updated 2017-03-09 08:03:33 -0600

Hello,

I was trying to run the art_vehicle stack from the UTexas, so I installed ROS Fuerte over Ubuntu 12.04 in a Virtual Machine. I got a run-time error when trying to launch the simulator, I think it was because the art_vehicle stack was designed to be used with Stage 3 and I was using Stage 4 (which has some minor changes in format). I tried to migrate the models format to the new version, but I still got some errors I couldn't fix, so I thought it would be easier to simply work with Stage 3 (I was mistaken about it, see edit below).

As you can only install Stage 4 from repositories, I had to install Stage-3.2.1 from source.

Now I have to tell the simulator_art package to be aware of the Stage libraries I have manually installed when linking the executable inside the CMakeLists.

I have tried two things so far:

1) Using pkg-config to find an external dependency:

Something like

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()

include($ENV{ROS_ROOT}/core/rosbuild/FindPkgConfig.cmake)
pkg_check_modules(STAGE REQUIRED Stage-3.2)

include_directories(${STAGE_INCLUDE_DIRS})
link_directories(${STAGE_LIBRARY_DIRS})


rosbuild_add_executable(artstage src/artstage.cc src/vehicle_model.cc)
rosbuild_add_executable(obstacles src/obstacles.cc)

but the compiler still complains that it lacks the file "stage.hh".

2) Have a .cmake module that searches for the library and have CMakeLists call it:

Now my CMakeLists looks like:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
find_package(Stage 3 REQUIRED)

rosbuild_add_executable(artstage src/artstage.cc src/vehicle_model.cc)
rosbuild_add_executable(obstacles src/obstacles.cc)

and inside simulator_art/cmake/Modules I have this .cmake file:

include_directories(
${STAGE_INCLUDE_DIRS}
)

find_path(STAGE_INCLUDE_DIR
    NAMES Stage-3.2/stage.hh
    PATHS /usr/local/include
)

find_library(STAGE_LIBRARY
    NAMES libstage.so
    PATHS /usr/local/lib
)

if(STAGE_INCLUDE_DIR)
    set(STAGE_INCLUDE_DIRS ${STAGE_INCLUDE_DIR})
    message(${STAGE_INCLUDE_DIR})
endif()

if(STAGE_LIBRARY)
    set(STAGE_LIBRARIES ${STAGE_LIBRARY})
    message(${STAGE_LIBRARY})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(STAGE DEFAULT_MSG
    STAGE_LIBRARY
    STAGE_INCLUDE_DIR
)

mark_as_advanced(
    STAGE_INCLUDE_DIR
    STAGE_LIBRARY
)

if(NOT STAGE_FOUND)
    message(FATAL_ERROR "Stage not found.")
endif()

But the compiler still can't find "stage.hh". I must be missing something in the CMakeLists.

Any help is appreciated.

Regards.

--------------------------------------------------------------------

EDIT:

OK, I have just seen in the code of the simulator_art that it is actually using Stage 4 in Fuerte, so the origin of the errors I saw must be somewhere else. I still want to understand the cmake problem, so the question remains. I found out that if I hard-code the include path, i.e:

include_directories(
    /usr/local/include/Stage-3.2
)

the library does get loaded, so I printed STAGE_INCLUDE_DIRS and it only showed "/usr/local/include/", that's why it didn't get loaded... any explanation?

edit retag flag offensive close merge delete