Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Qt6 #170

Open
wants to merge 13 commits into
base: rolling
Choose a base branch
from
39 changes: 33 additions & 6 deletions turtlesim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.20)
project(turtlesim)

if(NOT CMAKE_CXX_STANDARD)
Expand All @@ -13,35 +13,54 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)

find_package(Qt6 COMPONENTS Widgets QUIET)
set(QT_VERSION_MAJOR 6)
if(NOT Qt6_FOUND)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
set(QT_VERSION_MAJOR 5)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm somewhat concerned about this logic.

In particular, I think we want to continue to use Qt5 right now, but have everything in place so that we could switch to Qt6 in the future.

Because of the way we build binary packages, we will only install Qt5 libraries, and thus we'll continue to build against Qt5 for binaries.

But in from-source builds, it depends on what the user has installed. Thus, I'm a bit afraid that we'll get bug reports from users saying things won't compile properly due to Qt6 being installed. And I don't think we are quite ready for that.

So my suggestion here is to hide this whole thing behind a CMake option, something like USE_QT6. The the logic would be something like:

if (USE_QT6)
  find_package(Qt6 REQUIRED COMPONENTS Widgets)
  set(QT_VERSION_MAJOR 6)
else()
  find_package(Qt5 REQUIRED COMPONENTS Widgets)
  set(QT_VERSION_MAJOR 5)
endif()

What do you think?


find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(turtlesim_msgs REQUIRED)

include_directories(include ${Qt5Widgets_INCLUDE_DIRS})

qt5_wrap_cpp(turtlesim_node_MOCS include/turtlesim/turtle_frame.hpp)
if(${QT_VERSION_MAJOR} GREATER "5")
qt_standard_project_setup()
qt_wrap_cpp(turtlesim_node_MOCS include/turtlesim/turtle_frame.hpp)
else()
qt5_wrap_cpp(turtlesim_node_MOCS include/turtlesim/turtle_frame.hpp)
endif()

add_executable(turtlesim_node
src/turtlesim.cpp
src/turtle.cpp
src/turtle_frame.cpp
${turtlesim_node_MOCS}
)
target_include_directories(turtlesim_node PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}
)
target_link_libraries(turtlesim_node PRIVATE
ament_index_cpp::ament_index_cpp
${cpp_typesupport_target}
${geometry_msgs_TARGETS}
${turtlesim_msgs_TARGETS}
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
rclcpp::rclcpp
rclcpp_action::rclcpp_action
${std_srvs_TARGETS}
)

add_executable(turtle_teleop_key tutorials/teleop_turtle_key.cpp)
target_include_directories(turtle_teleop_key PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
target_link_libraries(turtle_teleop_key PRIVATE
${turtlesim_msgs_TARGETS}
${geometry_msgs_TARGETS}
Expand All @@ -50,6 +69,10 @@ target_link_libraries(turtle_teleop_key PRIVATE
)

add_executable(draw_square tutorials/draw_square.cpp)
target_include_directories(draw_square PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
target_link_libraries(draw_square PRIVATE
${turtlesim_msgs_TARGETS}
${geometry_msgs_TARGETS}
Expand All @@ -58,6 +81,10 @@ target_link_libraries(draw_square PRIVATE
)

add_executable(mimic tutorials/mimic.cpp)
target_include_directories(mimic PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
target_link_libraries(mimic PRIVATE
${turtlesim_msgs_TARGETS}
${geometry_msgs_TARGETS}
Expand Down