From d91dd0cff1641d7c50f7cde13f7528130e60ab66 Mon Sep 17 00:00:00 2001 From: dlyr Date: Sat, 16 Jul 2022 08:28:14 +0200 Subject: [PATCH] use qt-version --- Config.cmake.in | 2 ++ cmake/findQtPackage.cmake | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Config.cmake.in b/Config.cmake.in index 2466e42..184c994 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -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) diff --git a/cmake/findQtPackage.cmake b/cmake/findQtPackage.cmake index 8337507..17101cd 100644 --- a/cmake/findQtPackage.cmake +++ b/cmake/findQtPackage.cmake @@ -1,3 +1,14 @@ +cmake_minimum_required(VERSION 3.16) + +# Find Qt5 or Qt6 packages Parameters: COMPONENTS : 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) @@ -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( @@ -27,3 +40,8 @@ macro(find_qt_package) endif() endif() endmacro() + +# see find_qt_package +macro(find_qt_dependency) + find_qt_package(${ARGN}) +endmacro()