GammaRay icon indicating copy to clipboard operation
GammaRay copied to clipboard

Building for Qt versions prior to 5.15 fails when Qt 5.15 is installed on the system

Open fuzun opened this issue 3 years ago • 5 comments

When there is Qt 5.15 installed on the system, even if CMAKE_PREFIX_PATH is set to correct Qt directory, cmake autogen fails during building because Qt MOC binaries before 5.15 does not accept parameter "--output-dep-file" and throws Unknown option 'output-dep-file'. error.

This can be fixed by changing "QT_VERSION_MINOR" value from 15 to anything below 15, preferably the target Qt minor version in all AutogenInfo.json files in the build directory before executing make.

The reason is the correct Qt version is not set when CMAKE_PREFIX_PATH points to a specific Qt path and system Qt version is used. I'm not sure if this is a bug of cmake or this project.

See https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmQtAutoMocUic.cxx#L2391 & https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmQtAutoMocUic.cxx#L2020

As a temporary solution, this command may be used to automatically change the value in all AutogenInfo.json files: (Make sure you are in the build directory)

find . -name 'AutogenInfo.json' -print0 | xargs -0 sed -i 's/"QT_VERSION_MINOR" : 15/"QT_VERSION_MINOR" : 14/g'

The bug also prevents doing probe-only builds for older Qt versions.

fuzun avatar May 19 '21 22:05 fuzun

I have the feeling something else is wrong for you. Likely CMake picked up the Qt5 core module from the wrong location and defers the moc binary path from there?

Could you post the output of: grep "Qt5.*:PATH" $YOUR_BUILD_DIR/CMakeCache.txt here?

krf avatar May 20 '21 09:05 krf

Yeah cmake picks up the Qt5 core and gui from a different location, but why? I assumed its a bug. See the ss below:

The output of the command: (Qt5Core and Qt5Gui are picked up from the system unlike others.)

CMAKE_PREFIX_PATH is set to /opt/Qt/5.11.3/gcc_64

Qt53DAnimation_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DAnimation
Qt53DCore_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DCore
Qt53DExtras_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DExtras
Qt53DInput_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DInput
Qt53DLogic_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DLogic
Qt53DQuick_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DQuick
Qt53DRender_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt53DRender
Qt5AndroidExtras_DIR:PATH=Qt5AndroidExtras_DIR-NOTFOUND
Qt5Bluetooth_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Bluetooth
Qt5Concurrent_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Concurrent
Qt5Core_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt5Core
Qt5Designer_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Designer
Qt5Gamepad_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Gamepad
Qt5Gui_DIR:PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt5Gui
Qt5IviCore_DIR:PATH=Qt5IviCore_DIR-NOTFOUND
Qt5IviMedia_DIR:PATH=Qt5IviMedia_DIR-NOTFOUND
Qt5IviVehicleFunctions_DIR:PATH=Qt5IviVehicleFunctions_DIR-NOTFOUND
Qt5Location_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Location
Qt5Network_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Network
Qt5OpenGL_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5OpenGL
Qt5PositioningQuick_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5PositioningQuick
Qt5Positioning_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Positioning
Qt5Qml_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Qml
Qt5QuickWidgets_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5QuickWidgets
Qt5Quick_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Quick
Qt5ScriptTools_DIR:PATH=Qt5ScriptTools_DIR-NOTFOUND
Qt5Script_DIR:PATH=Qt5Script_DIR-NOTFOUND
Qt5Scxml_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Scxml
Qt5Svg_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Svg
Qt5Test_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Test
Qt5UiPlugin_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5UiPlugin
Qt5WaylandCompositor_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5WaylandCompositor
Qt5WebEngineWidgets_DIR:PATH=Qt5WebEngineWidgets_DIR-NOTFOUND
Qt5Widgets_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Widgets
Qt5Xml_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5Xml
Qt5_DIR:PATH=/opt/Qt/5.11.3/gcc_64/lib/cmake/Qt5

fuzun avatar May 20 '21 15:05 fuzun

Oh, wow. I think I understand why this is happening. By running cmake --trace-expand I see the following:

(...)
/usr/lib/x86_64-linux-gnu/cmake/KF5SyntaxHighlighting/KF5SyntaxHighlightingConfig.cmake(38):  find_dependency(Qt5Core 5.14.0 )
/usr/share/cmake-3.18/Modules/CMakeFindDependencyMacro.cmake(47):  find_package(Qt5Core 5.14.0 QUIET  )
(...)

This is where the "required version >= 5.14.0" constraint is coming from. It's from including the KF5 libraries (KF5::SyntaxHighlighting or the other ones) into the build.

Cannot think of an easy fix right now.

A quick work-around would be disabling detecting KF5 libraries altogether. Run this from a clean build directory:

cmake -DCMAKE_DISABLE_FIND_PACKAGE_KF5SyntaxHighlighting=1 -DCMAKE_DISABLE_FIND_PACKAGE_KF5CoreAddons=1 ...

krf avatar May 20 '21 16:05 krf

That's a nice find but please note that AUTOGEN runs for everything on the project and since QT_VERSION_MINOR is mistakenly set to 15, AUTOGEN fails on everything with throwing Unknown option 'output-dep-file'.

If you mean that your finding is what causes diversion from the Qt available at the prefix path to the Qt installed on the system (in order to satisfy >=5.14), I think that fixing that might fix the problem!

fuzun avatar May 20 '21 16:05 fuzun

Client dependencies found in the system prefix pulling in a (newer) system Qt is a recurring problem, can happen with KF5, KDSME or even Qt modules not present in the desired Qt. I'm not aware of a good way to fix this though. Some possible ideas to at least reduce the impact:

  • Don't search for client dependencies in probe-only builds.
  • Remember the Qt version after the very first find_package(QtCore), and check whether that changed after all dependencies have been found, and if so exit with an explanation on how to proceed.

vkrause avatar May 21 '21 06:05 vkrause