Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions navmap_rviz_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ project(navmap_rviz_plugin)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
# Use the same Qt as rviz (Qt5 up to Kilted, Qt6 from Lyrical): mixing both breaks the plugin.
# Read it from rviz_common's exported dependencies before find_package(rviz_common): a Qt5 rviz
# 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()

if(rviz_common_deps MATCHES "Qt6")

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.

Nit: MATCHES "Qt6" looks at the whole file. It works with today's content, but matching the list item (e.g. MATCHES "[\";]Qt6[\";]") would not be fooled by a comment or another package name containing Qt6.

set(qt_major 6)
else()
set(qt_major 5)
set(CMAKE_DISABLE_FIND_PACKAGE_Qt6 TRUE)
endif()
find_package(rviz_common REQUIRED)
find_package(rviz_rendering REQUIRED)
find_package(rviz_default_plugins REQUIRED)
Expand All @@ -12,14 +24,6 @@ find_package(navmap_ros_interfaces REQUIRED)
find_package(navmap_ros REQUIRED)
find_package(navmap_core REQUIRED)

# Same Qt as rviz (Qt5 up to Kilted, Qt6 from Lyrical): mixing both breaks loading the plugin.
# Ask rviz_common: other deps (e.g. VTK via PCL) may bring the other Qt along
get_target_property(rviz_common_libs rviz_common::rviz_common INTERFACE_LINK_LIBRARIES)
if("${rviz_common_libs}" MATCHES "Qt6::")
set(qt_major 6)
else()
set(qt_major 5)
endif()
find_package(Qt${qt_major} REQUIRED COMPONENTS Widgets)

qt_wrap_cpp(NAVMAP_MOC_SRCS
Expand Down
Loading