From 178e59503513da006fda072909cb8f0ddedeee61 Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Thu, 22 Aug 2024 12:59:58 -0400 Subject: [PATCH] improve Qt5/Qt6 package searching --- CMakeLists.txt | 26 ++++++++++++++++++++++---- VERSIONS | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 716992cc..91132891 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,13 +328,31 @@ if(BUILD_SLIMGUI) # Default to Qt6 if available, fall back to Qt5; this defines QT_VERSION_MAJOR to be either 5 or 6 # This is complicated slightly by the modules needed differing between Qt5 and Qt6 # see https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html - find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets) - if(${QT_VERSION_MAJOR} EQUAL 5) - find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets) + # I found that find_package(QT NAMES Qt6 Qt5 ...) was behaving oddly, so I shifted to the below + find_package(Qt6 COMPONENTS Core Gui Widgets OpenGLWidgets) + if(Qt6_FOUND) + set(QT_VERSION_MAJOR 6) + message(STATUS "Found Qt6 (${Qt6_VERSION}) at ${QT6_INSTALL_PREFIX}") else() - find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets OpenGLWidgets) + find_package(Qt5 COMPONENTS Core Gui Widgets) + if(Qt5_FOUND) + set(QT_VERSION_MAJOR 5) + message(STATUS "Could not find Qt6; if this is unexpected, you may wish to set Qt6_DIR and/or CMAKE_PREFIX_PATH") + message(STATUS "Found Qt5 (${Qt5_VERSION}) at ${Qt5_DIR}") + # note that on macOS, Qt5 has only the x86_64 architecture, so if you are on macOS-arm64 your build will fail + # you can supply -D CMAKE_OSX_ARCHITECTURES="x86_64" at the command line and it should build for x86_64 + else() + message(FATAL_ERROR "Could not find Qt5 or Qt6; you may wish to set Qt6_DIR, Qt5_DIR, and/or CMAKE_PREFIX_PATH") + endif() endif() + # a useful bit of debugging code that prints all defined variables + #get_cmake_property(_variableNames VARIABLES) + #list (SORT _variableNames) + #foreach (_variableName ${_variableNames}) + # message(STATUS "${_variableName}=${${_variableName}}") + #endforeach() + if(WIN32) set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME_SLIMGUI}_autogen/mocs_compilation.cpp" PROPERTIES COMPILE_FLAGS "-include config.h -DGNULIB_NAMESPACE=gnulib") endif() diff --git a/VERSIONS b/VERSIONS index e02dab48..f536cd9b 100644 --- a/VERSIONS +++ b/VERSIONS @@ -24,7 +24,7 @@ development head (in the master branch): extend deviatePositions(), pointDeviated(), sampleNearbyPoint(), and sampleImprovedNearbyPoint() to allow vectorization with a different spatial kernel for each iteration fix a line-ending bug in readFile(); a CRLF file from Windows, read on macOS/Linux, would not strip the CR off the ends of the lines shift to supporting Qt6 and C++17 to build SLiMgui; Qt5 with C++11 is still supported - for macOS, Qt6 is now the supported plaform for macOS 11/12/13/14; Qt5 should only be used on macOS 10.15 + for macOS, Qt6 is now the supported platform for macOS 11/12/13/14; Qt5 should only be used on macOS 10.15 for Windows, Qt6 is now the supported platform for Windows 10 (1809 or later) and Windows 11 for Linux, Qt6 is now the supported platform for Red Hat 8.6/8.8/9.2, openSUSE 15.5, and Ubuntu 22.04 among others these recommendations are based on Qt6's recommended platforms; earlier platforms should use Qt5