# find_package() on ROS_PACKAGE_PATH?

Sorry in advance if this is a poorly constructed idea/question.

I have strict orders that I can't use caktin build and that I should only use basic make/cmake commands to control the build process.

I am building a package of messages and then trying to find_package() that message package from another package that needs to use them. I provide the config files below for the message package amrl_msgs. If there is a fundamentally better way to try to do what I want to do, I am eager to hear, as long as it doesn't involve using catkin build/make :)

When I try to find_package(amrl_msgs) in another project I get a

  Could not find a package configuration file provided by "amrl_msgs" with
any of the following names:

amrl_msgsConfig.cmake
amrl_msgs-config.cmake


error, even though the amrl_msgsConfig.cmake is found in amrl_msgs/build/devel/share/amrl_msgs/cmake and I have both the of the packages on the ROS_PACKAGE_PATH. I am assuming the way to solve this problem is not with the ROS_PACKAGE_PATH, but I also don't want to have to hardcode the absolute path to amrl_msgsConfig.cmake every time I use it. How do I direct the system to be able to find the messages without hardcoding the path?

cmake_minimum_required(VERSION 2.8.3)
project(amrl_msgs)

## Compile as C++11, supported in ROS Kinetic and newer

find_package(catkin REQUIRED COMPONENTS
std_msgs
message_generation
)

FILES
Point2D.msg
ColoredArc2D.msg
ColoredLine2D.msg
ColoredPoint2D.msg
Localization2DMsg.msg
PathVisualization.msg
Point2D.msg
Pose2Df.msg
RobofleetStatus.msg
RobofleetSubscription.msg
VisualizationMsg.msg
)

generate_messages(
DEPENDENCIES
std_msgs
)

catkin_package(
INCLUDE_DIRS build/devel/include
CATKIN_DEPENDS std_msgs message_runtime
)

edit retag close merge delete

am assuming the way to solve this problem is not with the ROS_PACKAGE_PATH [..]

afaik CMake does not look at that variable for locations where it should look for *Config.cmake files.

You'll probably want/need to set CMAKE_PREFIX_PATH, which is one of the jobs Catkin (the tool) takes care of for you.

There is no magic, it's all just CMake.

Edit:

INCLUDE_DIRS build/devel/include


are you sure this is correct? Afaik paths passed to INCLUDE_DIRS should be relative to the CMakeLists.txt / package root. You appear to be referring to a directory generated during the build. And pure message packages typically don't export any include directories. That gets taken care of by generate_messages(..) and message_runtime et al.

( 2021-02-02 12:23:57 -0500 )edit

I also don't want to have to hardcode the absolute path to amrl_msgsConfig.cmake every time I use it

CMake will crawl the FS to some extent, but unfortunately if you're not using Catkin, you're now responsible for updating the CMAKE_PREFIX_PATH such that it contains the locations CMake should crawl to look for *Config.cmake files.

That's again CMake, not Catkin.

( 2021-02-02 12:38:50 -0500 )edit
( 2021-02-02 12:47:23 -0500 )edit

using the following command " catkin_make --only-pkg-with-deps <target_package> " you can build the specific package instead of building all the packages in your system. Also if you have the package path you can put it in bashrc file so it will be loaded at all the times. you also can make a new enviorment and build your package there and source it into the bashrc file this will requires catkin_make however since it is in diffrent enviorment it will not make any issue for your current packages.

( 2021-02-02 20:32:09 -0500 )edit

@AmirSaman: the OP stated he cannot/is not allowed to use Catkin (the tool) in any way.

It's not clear to me how your comment addresses the issue and takes that into account.

( 2021-02-03 02:54:29 -0500 )edit

@gvdhoorn I am just suggesting those ways in case if OP not aware of it which could enable him to do the catkin_make and solve his problem else what you have suggested earlier could help to settle this issue.

( 2021-02-03 04:26:47 -0500 )edit

Thanks for the feedback guys! That reading on Atomic Workspaces was very helpful to put the problem into context. I think there is not a good way to do what I want without hard coding paths in the CMake, or using make install to put the config files in more friendly locations (which isn't useful because often this will require sudo privileges). Thanks again!

( 2021-02-03 12:16:20 -0500 )edit

Sort by » oldest newest most voted

I'm not sure I understand why you need to "hard code paths in the CMake".

CMAKE_PREFIX_PATH is an environment variable. As long as the *Config.cmake files are in the appropriate location, CMake will find them.

Note: it's a prefix path, not a full path. CMake searches a few standard locations in each path on the CMAKE_PREFIX_PATH.

more

You are 100% right! That is honestly exactly the solution I was looking for. We can just add the CMAKE_PREFIX_PATH of each package to the .bashrc or export it in each terminal session. Thanks so much!

( 2021-02-04 08:08:08 -0500 )edit
1

Yes, as I explained before: that's what Catkin does for you (among other things).

( 2021-02-04 08:15:05 -0500 )edit