c++qtcmakeqt6

Build specific modules in Qt6 (i.e. QtMqtt)


For a project which uses MQTT, I always had to compile the QtMqtt module from source, because it wasn't included in the prebuilt windows release and couldn't be chosen for installation either. In Qt5 that was pretty easy: Download source code from official git (https://code.qt.io/cgit/qt/qtmqtt.git/), open the .pro file in QtCreator and compile the project. For installation, I just moved the .dll files to my Qt install directory.

Now in Qt6, the build process was switched from qmake to cmake, so I cannot simply load the project in QtCreator, but have to compile it manually using CMake, which I find really unintuitive and prone to errors. From what I understand, I cannot compile single modules on their own from now on, but have to get the whole Qt 6.2.0 source code instead (i.e. via installer option) and then use a --target option on CMake to build only specific module. So here is what I did so far:

  1. Get Qt source code from installer (installed to Qt/6.2.0/Src)
  2. Create a command line environment according to this manual
  3. Open cmd environment, navigate to build folder (i.e. Qt/6.2.0/build)
  4. Configure build using command: ..\Src\configure -prefix Qt\6.2.0\build
  5. Build with cmake using command cmake --build . --target qtmqtt
  6. Install using command cmake --install .

What happens, is that the configuration works, and the build supposedly too, but installation fails with something like:

CMake Error at qtbase/src/3rdparty/libpng/cmake_install.cmake:41 (file):
  file INSTALL cannot find
  "F:/DEV/prog/Qt/6.2.0/build/qtbase/mkspecs/modules/qt_ext_libpng.pri": File
  exists.
Call Stack (most recent call first):
  qtbase/src/3rdparty/cmake_install.cmake:42 (include)
  qtbase/src/cmake_install.cmake:42 (include)
  qtbase/cmake_install.cmake:244 (include)
  cmake_install.cmake:42 (include)

The folder Qt/6.2.0/build then only consists of .cmake files but nothing which seems to be usable .dll files for me. I just don't understand how to properly set up everything with cmake. Why would they make it so complicated after all now, as it was fairly easy to compile modules with qmake in Qt5?


Solution

  • From what I understand, I cannot compile single modules on their own from now on, but have to get the whole Qt 6.2.0 source code instead (i.e. via installer option)

    That's not correct. Given a pre-built Qt, you should be still able to just build the qmqtt package from source by running e.g.

    <QTDIR>\bin\qt-configure-module <mqtt_src_dir>
    cmake --build .