From 2e4cbaa521ee36b05422469e6569cd85943d79fd Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Mon, 28 Dec 2020 14:38:13 -0500 Subject: cmake-gui: Add a Qt version control variable --- Source/QtDialog/CMakeLists.txt | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index ce55f51..1d3c66e 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -8,15 +8,27 @@ set (QT_COMPONENTS Widgets Gui ) -# Look for Qt6 first -find_package(Qt6Widgets QUIET) -set(INSTALLED_QT_VERSION 6) -if(NOT Qt6Widgets_FOUND) - find_package(Qt5Widgets QUIET) - if(NOT Qt5Widgets_FOUND) - message(FATAL_ERROR "Could not find a valid Qt installation.") + +set(CMake_QT_MAJOR_VERSION "A" CACHE + STRING "Expected Qt major version. Valid values are A (auto-select), 5, 6.") +set(SUPPORTED_QT_VERSIONS "A" 5 6) +set_property(CACHE CMake_QT_MAJOR_VERSION PROPERTY STRINGS ${SUPPORTED_QT_VERSIONS}) +if(NOT CMake_QT_MAJOR_VERSION VERSION_EQUAL "A") + if(NOT CMake_QT_MAJOR_VERSION IN_LIST SUPPORTED_QT_VERSIONS) + message(FATAL_ERROR "Supported Qt versions are \"${SUPPORTED_QT_VERSIONS}\"." + " But CMake_QT_MAJOR_VERSION is set to ${CMake_QT_MAJOR_VERSION}.") + endif() + set(INSTALLED_QT_VERSION ${CMake_QT_MAJOR_VERSION}) +else() + find_package(Qt6Widgets QUIET) + set(INSTALLED_QT_VERSION 6) + if(NOT Qt6Widgets_FOUND) + find_package(Qt5Widgets QUIET) + if(NOT Qt5Widgets_FOUND) + message(FATAL_ERROR "Could not find a valid Qt installation.") + endif() + set(INSTALLED_QT_VERSION 5) endif() - set(INSTALLED_QT_VERSION 5) endif() find_package(Qt${INSTALLED_QT_VERSION} -- cgit v0.12