Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build against Qt5 if Qt6 is installed #1097

Closed
klemensn opened this issue Jul 18, 2022 · 8 comments
Closed

Cannot build against Qt5 if Qt6 is installed #1097

klemensn opened this issue Jul 18, 2022 · 8 comments

Comments

@klemensn
Copy link
Contributor

klemensn commented Jul 18, 2022

#991 introduced

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.9.0 REQUIRED COMPONENTS Core Widgets Network PrintSupport Svg LinguistTools)

which effectively prevents using Qt5 if Qt6 is installed.

Usually -D CMAKE_DISABLE_FIND_PACKAGE_<PackageName>=ON can be used to hide installed packages,
but REQUIRED prevents this.

Even without REQUIRED, due to the use of NAMES one had to pass
-D CMAKE_DISABLE_FIND_PACKAGE_QT=ON instead of
-D CMAKE_DISABLE_FIND_PACKAGE_Qt6=ON to neuter

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)

which in turn would cause QT_VERSION_MAJOR to be undefined and thus break
find_package(Qt${QT_VERSION_MAJOR} 5.9.0 REQUIRED COMPONENTS Core Widgets Network PrintSupport Svg LinguistTools)

Passing -D CMAKE_DISABLE_FIND_PACKAGE_Qt6=ON would equally break line 18, as can be seen here:

[...]
CMake Error at CMakeLists.txt:18 (find_package):
  find_package for module Qt6 called with REQUIRED, but
  CMAKE_DISABLE_FIND_PACKAGE_Qt6 is enabled.  A REQUIRED package cannot be
  disabled.
[...]
CMake Error at common/CMakeLists.txt:14 (qt_add_translation):
  Unknown CMake command "qt_add_translation".
[...]
-- Configuring incomplete, errors occurred!

So to buid against Qt5 one must either remove Qt6 from their system or patch line 17, e.g.

-find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
+find_package(Qt5 COMPONENTS Core REQUIRED)
+set(QT_VERSION ${Qt5_VERSION})
+set(QT_VERSION_MAJOR ${Qt5_VERSION_MAJOR)

One way to fix this is to introduce a CMake option like so:

set(DEFAULT_QT_VER 6)
option(QT_VERSION "Qt version to use (default: ${DEFAULT_QT_VER})" ${DEFAULT_QT_VER})
...

I have not opened a PR for this approach yet as there may be other ways.
Qt5 support is probably not going away soon, so it should keep working regardless of whether Qt6 is installed or not.

This was referenced Jul 18, 2022
@metsma
Copy link
Contributor

metsma commented Jul 19, 2022

Can you test #1082

@klemensn
Copy link
Contributor Author

Can you test #1082

This PR contains no Qt related CMake changes, so it won't fix the Qt5 issue described here.

@metsma
Copy link
Contributor

metsma commented Jul 19, 2022

This is how Qt suggests to support QT 5 and 6
https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions

@klemensn
Copy link
Contributor Author

This is how Qt suggests to support QT 5 and 6 https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions

Do you need support for Qt<5.15?
If not, https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#versionless-targets would be the way to go.

@klemensn
Copy link
Contributor Author

OK, I see, at least Windows is stuck behind:

@metsma
Copy link
Contributor

metsma commented Jul 19, 2022

Currently yes. Ubuntu 18.04 (Qt 5.9) is still supported target.
Windows moves now to Qt 6.3. Qt 5.12 LTS support ended last year.

@klemensn
Copy link
Contributor Author

Currently yes. Ubuntu 18.04 (Qt 5.9) is still supported target. Windows moves now to Qt 6.3.

It still seems off to effectively force Qt6 usage if both Qt6 and Qt5 are installed, but since Qt6 works (for me on OpenBSD) I'll just stick to that and refrain from changing the CMake detection logic.

Maybe the versionless approach can be adapted once support for the last Qt<5.14 platform (Ubuntu 18.04) has been dropped?

@metsma
Copy link
Contributor

metsma commented Jul 19, 2022

Currently yes. Ubuntu 18.04 (Qt 5.9) is still supported target. Windows moves now to Qt 6.3.

It still seems off to effectively force Qt6 usage if both Qt6 and Qt5 are installed, but since Qt6 works (for me on OpenBSD) I'll just stick to that and refrain from changing the CMake detection logic.

Maybe the versionless approach can be adapted once support for the last Qt<5.14 platform (Ubuntu 18.04) has been dropped?

I am also looking forward for this day. Ubuntu 18.04 LTS has standard support until April 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants