> vcpkg
yep, it's great. I prefer it over conan. Unfortunately Qt package for Linux is barely usable, it ships only static version and has a bazillion dependencies on system-packages (at least that was the case a year ago).
I made some progress with my issue:
Default generated finding of Qt is this:
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
To copy to clipboard, switch view to plain text mode
Where the first findpackage() finds either Qt6 or Qt5 (prefers 6, if that doesnt exist looks for 5) and the second call does the actual importing/configuring.
I can (and do) force the major version to 5 by setting QT_VERSION_MAJOR to 5 and skipping the first call.
The reason why CMake prefers vcpkg's Qt package over QtCreators Kits is because the ONLY way QtCreator selects between Kits is setting CMAKE_PREFIX_PATH to the full path of the Kit. Hence if I select Qt5Kit in QtCreator find_package() only gets a path to Qt5, thus Qt6 cant be found and will default to Qt5.
There are two issues with that:
1. If vcpkg joins the party, CMAKE_PREFIX_PATH will contain paths to the Kit as well as to vcpkg packages. Now there is always a Qt6 found (the vcpkg one), and the path to the Qt5 Kit passed by QtCreator is ignored.
2. Actually QtCreator appends the Kit path to CMAKE_PREFIX_PATH, vcpkg is faster, and its path comes before the Kit path. Thus if both vcpkg and QtCreator offer a Qt6 package, vcpkg satisfies find_package() first.
Problem 2 can be worked around like so:
list(POP_BACK CMAKE_PREFIX_PATH XX)
list(PREPEND CMAKE_PREFIX_PATH ${XX})
list(POP_BACK CMAKE_PREFIX_PATH XX)
list(PREPEND CMAKE_PREFIX_PATH ${XX})
To copy to clipboard, switch view to plain text mode
Unfortunately I see no good way around Problem 1, besides very ugly string matching against the path to find out if the path is Qt5 or Qt6...
If someone sees a good solution, please let me know...
Added after 1 39 minutes:
Ah, QtCreator sets Qt5_DIR or Qt6_DIR variables, depending on which one you select. If the project is built directly from CMake then neither of them is set.
This should solve the second problem as well, I will check which variable is defined, and set QT_VERSION_MAJOR accordingly. If both are undefined I let find_package do its thing.
edit: Nope, it will happily set both variables if it finds both version.... the search continues ...
Bookmarks