Skip to content

Fix navmap_rviz_plugin build with Qt5 rviz_common and Qt6 installed - #44

Merged
fmrico merged 2 commits into
EasyNavigation:rollingfrom
Butakus:fix_qt5_qt6
Nov 6, 2026
Merged

fmrico merged 2 commits into
EasyNavigation:rollingfrom
Butakus:fix_qt5_qt6

Conversation

@Butakus

@Butakus Butakus commented Nov 4, 2026

Copy link
Copy Markdown
Member

Hi, it seems the Qt5/Qt6 issue is never resolved...

On Ubuntu 24.04, navmap_rviz_plugin fails to configure when the Qt6 development files are installed:

CMake Error at /opt/ros/rolling/share/rviz_common/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package):
  Found package configuration file:
    /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake
  but it set Qt5_FOUND to FALSE so package "Qt5" is considered to be NOT FOUND.
  Reason given by package:
  The Qt5 package requires at least one component

rviz_common 15.2.2 is built against Qt5, but its rviz_common-extras.cmake looks for Qt6 first and only falls back to Qt5 if Qt6 is missing. With Qt6 installed, Qt5 is never loaded, and the exported-dependencies step then runs a bare find_package(Qt5), which fails.

The existing Qt detection that we have in the CMakeLists.txt for the plugin (get_target_property on rviz_common::rviz_common) runs after find_package(rviz_common), so CMake never reaches it. CMake aborts with an error when calling find_package(rviz_common).

Fix

Before find_package(rviz_common), read rviz_common's exported dependencies to work out whether it uses Qt5 or Qt6:

  • set qt_major, which is used for find_package(Qt${qt_major} ...) and linking, as before;
  • when rviz uses Qt5, set CMAKE_DISABLE_FIND_PACKAGE_Qt6 so rviz's extras don't pick up Qt6.

@fmrico fmrico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the diagnosis is right: a Qt5 rviz_common (Kilted and older) looks for Qt6 first in its extras, so with Qt6 installed Qt5 is never loaded, and the old get_target_property check came after find_package(rviz_common), too late. Reading the exported dependencies first, and disabling Qt6 when rviz uses Qt5, follows rviz's own Qt as we want.

CI only builds on Rolling (Qt6), so I checked the Qt5 side in Docker (ros:kilted-ros-base and ros:jazzy-ros-base, with qt6-base-dev installed):

  • With the released rviz_common (Kilted 15.0.15, Jazzy 14.1.24) the extras ask for Qt5 directly, so both rolling and this PR build: the PR does not break the released distros.
  • With the Qt6-first extras of rviz_common 15.2.x (patched into Kilted's install), rolling fails with exactly the error in the description, and this PR builds; the plugin links only libQt5Core, libQt5Gui and libQt5Widgets.

Besides the inline comments:

  • Minor: find_file caches RVIZ_COMMON_DEPS_FILE, so a build directory reused with another distro keeps the old path. Unlikely with colcon (one build dir per distro), just noting it.

Comment thread navmap_rviz_plugin/CMakeLists.txt Outdated
# looks for Qt6 first if installed and then fails to find Qt5, so Qt6 must be disabled.
find_file(RVIZ_COMMON_DEPS_FILE ament_cmake_export_dependencies-extras.cmake
PATHS ENV AMENT_PREFIX_PATH PATH_SUFFIXES share/rviz_common/cmake NO_DEFAULT_PATH)
file(READ "${RVIZ_COMMON_DEPS_FILE}" rviz_common_deps)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If AMENT_PREFIX_PATH is not set or does not contain rviz_common (e.g. a build that only passes CMAKE_PREFIX_PATH), find_file gives RVIZ_COMMON_DEPS_FILE-NOTFOUND and file(READ) aborts the configure with "failed to open for reading", which does not say what is wrong. Before this change that case worked.

Could it also search CMAKE_PREFIX_PATH, and when the file is not found skip the read and keep the previous detection (get_target_property on rviz_common::rviz_common after find_package(rviz_common))? Something like:

find_file(RVIZ_COMMON_DEPS_FILE ament_cmake_export_dependencies-extras.cmake
  PATHS ENV AMENT_PREFIX_PATH ${CMAKE_PREFIX_PATH}
  PATH_SUFFIXES share/rviz_common/cmake NO_DEFAULT_PATH)
if(RVIZ_COMMON_DEPS_FILE)
  ...
endif()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this comment for the description of the fix. I also added a NO_CACHE just in case a build directory is reused with another distro.

Comment thread navmap_rviz_plugin/CMakeLists.txt Resolved
@Butakus

Butakus commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review and for the extra testing with the containers!

I think these changes should cover everything to make the find more robust:

  1. rviz_common not found: find_file now searches CMAKE_PREFIX_PATH first and then AMENT_PREFIX_PATH, the same order find_package uses. If the file still isn't found, configure stops with a clear FATAL_ERROR instead of the file(READ) error.
    I didn't add the get_target_property fallback: without AMENT_PREFIX_PATH the build already fails at find_package(rclcpp) (No 'rosidl_typesupport_c' found), before and after this PR. The case it would cover is an rviz_common reached only through rviz_common_DIR or PATH. Searching CMAKE_PREFIX_PATH first also stops us reading a different rviz_common than the one find_package uses, when two are installed.
  2. Qt6 match: now matches only the list item: MATCHES "[\";]Qt6[\";]".
  3. Cached path: added NO_CACHE to find_file, so a reused build directory doesn't keep an old path.

@fmrico

fmrico commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @Butakus

Merging 🚀

@fmrico
fmrico merged commit d7cb288 into EasyNavigation:rolling Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants