Skip to content

Commit

Permalink
use qt-version
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyr committed Jul 16, 2022
1 parent 4743322 commit d91dd0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ if(NOT TARGET @PROJECT_NAME@)
set(MY_OPTIONS_COMPONENTS "")
endif()

if(NOT QT_DEFAULT_MAJOR_VERSION OR QT_DEFAULT_MAJOR_VERSION STREQUAL "6")
find_package(Qt6 COMPONENTS ${MY_OPTIONS_COMPONENTS} QUIET)
endif()
if(NOT Qt6_FOUND)
if(${MY_OPTIONS_REQUIRED})
find_package(Qt5 5.15 COMPONENTS ${MY_OPTIONS_COMPONENTS} REQUIRED)
Expand Down
26 changes: 22 additions & 4 deletions cmake/findQtPackage.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
cmake_minimum_required(VERSION 3.16)

# Find Qt5 or Qt6 packages Parameters: COMPONENTS <component_list>: optional
# parameter listing the Qt packages (e.g. Core, Widgets REQUIRED: optional
# parameter propagated to find_package
#
# Usage: find_qt_package(COMPONENTS Core Widgets OpenGL Xml REQUIRED) which is
# equivalent to: find_package(Qt6 COMPONENTS Core Widgets OpenGL Xml REQUIRED)
# if Qt6 is available, or: find_package(Qt5 COMPONENTS Core Widgets OpenGL Xml
# REQUIRED) otherwise.
#
# Qt5 and Qt6 can be retrieved using versionless targets introduced in Qt5.15:
# https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#versionless-targets
macro(find_qt_package)
Expand All @@ -12,10 +23,12 @@ macro(find_qt_package)
set(MY_OPTIONS_COMPONENTS "")
endif()

find_package(
Qt6
COMPONENTS ${MY_OPTIONS_COMPONENTS}
QUIET)
if(NOT QT_DEFAULT_MAJOR_VERSION OR QT_DEFAULT_MAJOR_VERSION STREQUAL "6")
find_package(
Qt6
COMPONENTS ${MY_OPTIONS_COMPONENTS}
QUIET)
endif()
if(NOT Qt6_FOUND)
if(${MY_OPTIONS_REQUIRED})
find_package(
Expand All @@ -27,3 +40,8 @@ macro(find_qt_package)
endif()
endif()
endmacro()

# see find_qt_package
macro(find_qt_dependency)
find_qt_package(${ARGN})
endmacro()

0 comments on commit d91dd0c

Please sign in to comment.