Catkin Tools: How to include source file from another package?
[Ubuntu 14.04, ROS Hydro, Catkin Tools]
I have a number of packages in my source tree and catkin_make
successfully builds all of them, but takes a long time. So whilst I'm continuing with my developments, I'm using catkin build
instead.
The package I'm trying to build with catkin tools
(package3) has a couple dependencies (package1 & package2) which are successfully built. package3 itself, however, fails because the ${package2_SOURCE_DIR} variable returns an empty string and the source file I need from package2 can't be located. The associated header files are found successfully because ${package2_INCLUDE_DIR} mentions the correct path (along with a number of other paths). I'm not sure why _INCLUDE_DIR is working, but _SOURCE_DIR isn't.
What I've discovered is that under catkin_make
, CMake variables are global across the whole build. (Though this might not be an entirely correct statement.) Under catkin build
, package variables are kept local (even when I use find_package(package2)
).
I would like to avoid hard coding an absolute path into my add_executable() statement, but I don't know how to get the <package_name>_SOURCE_DIR
for package2. My add_executable()
statement, which works with catkin_make
is:
add_executable(programA
/src/programA.cpp
${Package2_SOURCE_DIR}/src/common.cpp
)
Is there a variable I can use that points to the catkin workspace? I don't mind using a line like:
${catkin_ws_BASE_DIR}/src/package2/src/common.cpp
Anyone able to help me solve this in an elegant way?
Cheers,
Nap
Have you tried
${Package2_DIR}
(note: not SOURCE_DIR)?${package2_DIR}
returns: "/home/me/catkin_ws/devel/share/package2/cmake"