Qt6 Add-on src package build using Conan package manager

From Qt Wiki
Jump to: navigation, search

"Work in Progress"

Qt6 Additional Library src package build using Conan package manager

To build Qt6 Additional Library src packages using Conan, which is provided by the Qt Installer, you can follow these steps. Note! This is still in beta phase i.e. you may need workarounds to get it working and instructions may change later.


  • Install required development libraries: https://doc.qt.io/qt-6/gettingstarted.html#platform-requirements
  • Qt Installer - install:
    • CMake (3.15 or higher is required)
      • the Additional Libraries use the CMake itself for the build
    • Conan (installs standalone conan(.exe) executable + settings files
    • Ninja (CMake generator)
    • 6.0.0 essentials binary package
    • Additional Library src package(s) needed in your CMake project
      • Qt Installer providesAdditional Library packages under top-level "Additional libraries" node
  • Put the installed tools into your PATH, prepend to PATH if needed to avoid mixing with older versions in your system
  • Build the Additional Library conan package
    • The "conan(.exe) install" commands below will install the built binaries also to your current working directory so you may want to:
      • mkdir build_dir && cd build_dir
    • Windows MSVC2019:
      • For MSVC compiler open command prompt and execute vcvars64.bat
        • e.g. C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat
      • conan.exe install qtnetworkauth/6.0.0@qt/final --build=missing --profile=<QtSdk>/Tools/Conan/profiles/'''qt-6.0.0-msvc2019_64''' -s build_type=Release -g cmake_paths -g=cmake -g deploy
    • Windows MinGW81:
      • For MinGW compiler add MinGW tools location to path
      • conan.exe install qtnetworkauth/6.0.0@qt/final --build=missing --profile=<QtSdk>/Tools/Conan/profiles/'''qt-6.0.0-mingw81_64''' -s build_type=Release -g cmake_paths -g=cmake -g deploy
    • macOS clang
      • conan install qtnetworkauth/6.0.0@qt/final --build=missing --profile=<QtSdk>/Tools/Conan/profiles/'''qt-6.0.0-macx-clang''' -s build_type=Release -g cmake_paths -g=cmake -g deploy
    • Linux gcc
      • conan install qtnetworkauth/6.0.0@qt/final --build=missing --profile=<QtSdk>/Tools/Conan/profiles/'''qt-6.0.0-gcc-x86_64''' -s build_type=Release -g cmake_paths -g=cmake -g deploy
    • Currently the follwing Additional Libraries are available as Conan packages:
      • qtnetworkauth
      • qtimageformats
      • qt3d
    • The cmake_paths generator will produce 'conan_paths.cmake' to your working directory, include it in your CMake project
    • If you have a qmake based consuming project for theAdditional Library you can pass -g qmake -generator which will create 'conanbuildinfo.pri' file which you can include in your qmake project. https://docs.conan.io/en/latest/integrations/build_system/qmake.html
    • Where the built binaries are?
      • $HOME/.conan/data/qtnetworkauth/6.0.0/qt/final/package'
        • Note: If you have configured your Conan home/cache folder differently the built package is located there
      • When using a conan reference to install, i.e. "conan install module/version@user/channel ..." conan will automatically deploy the binaries also to your current working directory:
      • If using "-g deploy" generator the binaries are exported to a sub-folder named by the module:
  • Build the consuming project/app
    • Edit the CMakeLists.txt of your MyApp project
      include(${CMAKE_BINARY_DIR}/conan_paths.cmake) # adjust the path for the "build_dir/conan_paths.cmake" in your env
      find_package(Qt6 COMPONENTS Widgets Network REQUIRED)
      find_package(Qt6 COMPONENTS NetworkAuth REQUIRED)
      add_executable(MyApp main.cpp mainwindow.cpp mainwindow.h mainwindow.ui)
      # Note! Temporary solution until fixed in Qt6 build system
      foreach(prefix ${CMAKE_PREFIX_PATH})
          set(prefix_include "${prefix}/include")
              if(EXISTS "${prefix_include}")
                  target_include_directories(MyApp PRIVATE "${prefix_include}")
      target_link_libraries(MyApp PRIVATE Qt::Widgets Qt::NetworkAuth)
    • Build 'MyApp'
      cd myapp
      mkdir build && cd build
      cmake -G Ninja -D CMAKE_INSTALL_PREFIX=<QtSdk>/6.0.0/gcc_64 -DCMAKE_BUILD_TYPE=Release -DQT_ADDITIONAL_PACKAGES_PREFIX_PATH=path/to_your/'''<u>build_dir</u>''' ..
      # Note: The "'''build_dir'''" is the root dir where conan deployed the built qtnetworkauth binaries in previous steps
      cmake --build .
      • The MyApp should be in bin/* directory and you should be able to launch it
    • Running the application
      • The deploy generator -g deploy passed to conan deploys the build binaries from conan cache to your working directory
      • Windows:
        • Put the deployed binaries to the same directory of your built application
      • macOS
        • Put the deployed binaries to the same directory of your built application
        • export DYLD_FRAMEWORK_PATH with paths to 6.0.0 essentials & qtnetworkauth deploy directory
      • Linux:
        • Put the deployed binaries to the same directory of your built application

Android builds

If you are new to Android please check first instructions how to setup Android development environment.

There are some workarounds needed still for Android builds:

  • You must use the following instead:
  • Edit the CMakeLists.txt of your MyApp project
    list(PREPEND CMAKE_FIND_ROOT_PATH "/path/to/your/build_dir/")
  • Build the project:
    • Set the environment variables $ANDROID_SDK_ROOT and $ANDROID_NDK_ROOT to point to the Android SDK and NDK paths respectively.
    • /path/to/your/qt_for_android/bin/qt-cmake(.bat) -GNinja -DCMAKE_BUILD_TYPE=Release -DANDROID_SDK_ROOT=$ANDROID_SDK_ROOT -DANDROID_NDK_ROOT=$ANDROID_NDK_ROOT
    • cmake --build . --target apk

Note: androiddeployqt still cannot handle the Conan builds and cannot copy the modules' libraries to the android-build folder. As a workaround, the required libraries (*.so) can be copied manually to android-build/libs/<abi> for the apk to package them. For more updates, see QTBUG-88519.

Conan profiles for Qt packages

The Qt Installer installs Conan profile files for those Qt essential binary packages that are selected for installation by the user.

The profile files are installed in: <QtSdk>/Tools/Conan/profiles

The profile files contain settings that match the configuration that was used to build the matching essentials binary package.

The [env] section contains 'QT_PATH' which points to the essentials package installation. This way the add-on Conan build recipe can locate the qt.toolchain.cmake file which is needed by the build recipe to build the Additional Library.

For Boot to Qt targets (Boot2Qt), the profiles do not have the QT_PATH env set and user needs to give this as environment variable when using conan (-e , --env) to point to the selected toolchain.

The profiles can be found from: https://code.qt.io/cgit/qt/qt-conan-config.git/ (https://codereview.qt-project.org/admin/repos/qt/qt-conan-config)

In case you want to install profiles by your self e.g. to some other location or you did not use Qt installer to install those you can use the following command:

- $conan config install <git-repo> -sf <path-in-git-repo> -tf <destination-path>

- e.g. $conan config install git://code.qt.io/qt/qt-conan-config.git -sf profiles/qt/linux/6.0.0 -tf /home/<user>/temp_path

Further notes

  • Ninja is the recommended CMake generator and should be used. E.g. on Windows you may get compilation time errors if using VS generator