colcon / colcon-ros

Extension for colcon to support ROS packages
http://colcon.readthedocs.io
Apache License 2.0
13 stars 26 forks source link

build_type=cmake packages are not added to CMAKE_PREFIX_PATH #126

Closed asherikov closed 2 years ago

asherikov commented 3 years ago

Example (https://github.com/asherikov/colcon_workspace/tree/as_colcon_debug/src):

colcon adds package_b to CMAKE_PREFIX_PATH when building package_c, but not package_a:

DEBUG:colcon.colcon_core.event_handler.log_command:Invoking command in '/home/aleks/git/colcon_workspace/build/reldebug/package_c': CMAKE_PREFIX_PATH=/home/aleks/git/colcon_workspace/install/reldebug/package_b:${CMAKE_PREFIX_PATH} PKG_CONFIG_PATH=/home/aleks/git/colcon_workspace/install/reldebug/package_b/lib/x86_64-linux-gnu/pkgconfig:/home/aleks/git/colcon_workspace/install/reldebug/package_b/lib/pkgconfig:${PKG_CONFIG_PATH} ROS_PACKAGE_PATH=/home/aleks/git/colcon_workspace/install/reldebug/package_b/share:${ROS_PACKAGE_PATH} /usr/bin/cmake /home/aleks/git/colcon_workspace/src/package_c -DCMAKE_TOOLCHAIN_FILE=/home/aleks/git/colcon_workspace/profiles/reldebug/toolchain.cmake -DCATKIN_INSTALL_INTO_PREFIX_ROOT=0 -DCMAKE_INSTALL_PREFIX=/home/aleks/git/colcon_workspace/install/reldebug/package_c

versions: python3-colcon-ros: Installed: 0.3.21-2 python3-colcon-core: Installed: 0.6.1-2

cottsay commented 2 years ago

The CMAKE_PREFIX_PATH hook creation happens in colcon-cmake: https://github.com/colcon/colcon-cmake/blob/master/colcon_cmake/environment/cmake_prefix_path.py

The code skips the hook creation if it doesn't think it will do anything, and indeed your package_a doesn't install any CMake config files that would be found using CMAKE_PREFIX_PATH, so the hook isn't created.

If you modify package_a to install a CMake config, the hook is executed as you expect.

If there is another way to use CMAKE_PREFIX_PATH that the CmakePrefixPathEnvironment hook isn't aware of, please open a PR to support it.

asherikov commented 2 years ago

CMAKE_PREFIX_PATH is used not only by find_package(), but also by find_program(), find_library(), find_file(), and find_path() (https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html). While in general the right thing to do is to install properly generated config file, most of third party packages I deal with are not quite there, and I dont want to fix them all. I believe CMAKE_PREFIX_PATH should simply include all cmake packages.

This issue however can be avoided using --merge-install, which is currently good enough for me, so I dont think it is important.

miquelmassot commented 7 months ago

Just came across this rabbit hole - wanting to use colcon for a bunch of pure cmake projects so that I could easily find_package()-them and depend one on another. I've also tried --merge-install and that does not fix it for me, I am not able to find the packages - colcon does not add them to CMAKE_PREFIX_PATH.

Does anyone have a minimal working example of two cmake packages in a colcon workspace?

asherikov commented 7 months ago

With merged installation you get a common path prefix, which you can specify using an environment variable or toolchain file.