Skip to content

Setting QT_DEFAULT_MAJOR_VERSION to 6 doesn't select Qt6 over Qt5

This code:

cmake_minimum_required(VERSION 3.28)
cmake_policy(VERSION 3.28)
project(X)

set(QT_DEFAULT_MAJOR_VERSION 6)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
message(STATUS "QT Major Version: " ${QT_VERSION_MAJOR})

is supposed to select QT6 in the mixed Qt5/Qt6 environment, but it selects Qt5:

-- QT Major Version: 5

$ cmake --version
cmake version 3.28.2

Qt-6.6.1 + Qt-5.15.11

clang-16

FreeBSD 14.0

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information