Skip to content

Commit

Permalink
Allow specifying an order of Qt versions to consider
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Feb 1, 2024
1 parent 9ee22b9 commit ba70f39
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,24 @@ find_package(OpenGL REQUIRED)

set(CMAKE_AUTOMOC ON)

find_package(Qt6 COMPONENTS Core Widgets OpenGL)
if (NOT Qt6_FOUND)
find_package(Qt5 COMPONENTS Core Widgets OpenGL)
set(QTVERSION ${Qt5_VERSION})
set(QT_LIBRARIES Qt5::Widgets)
else()
set(QTVERSION ${Qt6_VERSION})
set(QT_LIBRARIES Qt6::Widgets)
set(RVIZ_QT_VERSIONS "5;6" CACHE STRING "List of Qt versions to consider (in order)")
set(_versions_list ${RVIZ_QT_VERSIONS})
while(_versions_list)
# Pop first element from list _versions_list
list(GET _versions_list 0 _current_version)
list(REMOVE_AT _versions_list 0)
# Try to find this Qt version
find_package(Qt${_current_version} QUIET COMPONENTS Core Widgets OpenGL)
if (Qt${_current_version}_FOUND)
set(QTVERSION ${Qt${_current_version}_VERSION})
set(QT_LIBRARIES Qt${_current_version}::Widgets)
set(_versions_list) # break from while loop
else()
message(WARNING "Qt${_current_version} not found.")
endif()
endwhile()
if(NOT QTVERSION)
message(FATAL_ERROR "Failed to find a suitable Qt version.")
endif()
message(STATUS "Found Qt ${QTVERSION}")
add_definitions(-DQT_NO_KEYWORDS)
Expand Down

0 comments on commit ba70f39

Please sign in to comment.