Using Conan for Qt6: Difference between revisions
| Line 11: | Line 11: | ||
**Ninja | **Ninja | ||
**A working C++ compiler, supporting at least C++ 17 | **A working C++ compiler, supporting at least C++ 17 | ||
**Install required development libraries: https://doc.qt.io/qt-6/gettingstarted.html#platform-requirements | |||
*ICU | *ICU | ||
**There is work in progress to bring ICU as Conan package(s) as a dependency to Qt packages so that it is taken care of automatically for the users ([https://bugreports.qt.io/browse/QTQAINFRA-4592 QTQAINFRA-4592]). Until that one unfortunately needs to manually install ICU libs to system path where those can be found. | **There is work in progress to bring ICU as Conan package(s) as a dependency to Qt packages so that it is taken care of automatically for the users ([https://bugreports.qt.io/browse/QTQAINFRA-4592 QTQAINFRA-4592]). Until that one unfortunately needs to manually install ICU libs to system path where those can be found. | ||
| Line 43: | Line 44: | ||
== Qt Conan packages == | |||
To get an idea what Qt Conan packages are available run the following command | |||
* $ conan search -r qt <small><code>Existing package recipes:</code></small> <small><code>qtbase/6.2.0@qt/everywhere</code></small> <small><code>qtdeclarative/6.2.0@qt/everywhere</code></small> <small><code>qtimageformats/6.2.0@qt/everywhere</code></small> <small><code>qtmultimedia/6.2.0@qt/everywhere</code></small> | |||
The generic pattern for package naming is: <module name>/<version>-<pre-release segment>@qt/everywhere | |||
* Tome Qt .git repositories may yield multiple Conan packages like qtscxml.git -> qscxml, qtscxmlqml, qtscmlstatemachine and qtscxmlstatemachineqml | |||
* The optional pre-release segment may contain e.g. 6.2.0'''-alpha1''', 6.2.0'''-beta2''', 6.2.0'''-rc3''' | |||
== Build profiles == | |||
To tell Conan the build configuration you are interested about there are basically two ways (or three if you want to let Conan guess the default values). You can pass each setting and option sepately from c | |||
==Building== | ==Building== | ||
* | *Next to your project/app create a file that declares the Qt library dependencies as Conan packages: | ||
* | ** '''conanfile.txt''': # filename can be anything | ||
**''' | *** [requires] qtbase/6.2.0@qt/everywhere qtdeclarative/6.2.0@qt/everywhere # what ever your project/app may require qtcharts/6.2.0@qt/everywhere | ||
*** | * Get the build profiles | ||
** | ** | ||
**''' | * Call Conan to install the requirements for you: | ||
**''' | ** Get the build profiles to make things easier | ||
**''' | *** git clone qt5.git#dev # coin/conan/profiles | ||
*** | **** merge pending to 6.2.0 branch | ||
*** Note! It is not decided yet how we want to distribute the profile files to end users. Possible options are: | |||
**** put them in a zip file to download.qt.io # $ conan config install <URL> <destination directory> | |||
**** create a dedicated conan package for profiles which can be installed: $ conan install qtbuildprofiles/6.2.0@qt/everywhere | |||
** '''$ conan install <path>/conanfile.txt --build=missing --profile=/home/<user>/qt5/coin/conan/profiles/linux-x86_64-gcc --update --generator=virtualenv --remote=qt''' | |||
*** --build | |||
**** "--build" will force a complete build from sources including transitive dependencies | |||
**** "--build=never" will attempt to install pre-built binaries (from local cache or from given server) if those should exist for the given build configuration i.e. --profile. If requested build configuration is not found (cache or server) Conan will bail out with an error | |||
**** "--build=missing" Conan will attempt to build those missing packages/dependencies for the requested build configuration which are missing | |||
**** <nowiki>https://docs.conan.io/en/latest/mastering/policies.html</nowiki> | |||
*** --profile | |||
**** This specifies the build configuration i.e. Conan settings (os, os version, compiler, arch, ...) and Options (shared, release, headersclean, ..) | |||
***** Edit if needed | |||
***** Settings and Options in profile file can be overridden from command line by: | |||
****** -s compiler.version=9.3 -s compiler.libcxx=libstdc++11 -o release=no -o shared=no ... | |||
*** '''--update''' | |||
**** Forces Conan to check if the given server (-r, --remote) contains newer version of the package(s) and downloads those if found. '''This option should be always preferred''' | |||
*** --generator | |||
**** multiple can be given | |||
**** "--generator=virtualenv" | |||
***** This will generate 'activate.sh'/'activate.ps1' which you can call | |||
****** $ source activate.sh # on windows do not use 'source' -command | |||
***** Now all the Qt packages are in your PATH/env which were declared in the '''conaninfo.txt''' file | |||
**** "--generator=qmake" | |||
***** This will generate conanbuildinfo.pri file which you can include in your projects .pro file | |||
*** --remote | |||
**** Ask Conan to install the package(s) from the given remote server to your local Conan cache | |||
** Note! If you want to export the binaries out from the Conan cache to given directory you need to call conan install a bit differently | |||
*** $ conan install qtdeclarative/6.2.0@qt/everywhere --build=missing --profile=<profile> --update '''--install-folder'''=/home/<user>/Qt/6.2.0/gcc | |||
**** You should have the binaries of the required package and all of its transitive dependencies installed to the given directory with the usual directory layout: | |||
***** lib/ | |||
***** bin/ | |||
***** include/ | |||
***** ... | |||
*** Note! If you call $conan install <path>/conanfile.txt ... args ... --install-folder=/foo Conan will export binaries from cache to separate sub-directories per dependency | |||
**** /foo/qtbase/lib|bin|include|... | |||
**** /foo/qtdeclarative/lib|bin|include|... | |||
**** /foo/qtcharts/lib|bin|include|... | |||
** Once you have activated the 'activate.sh/activate.ps1' your can compile your project | |||
*** $ cd your_project_path && mkdir build && cd build | |||
*** $ cmake ../CMakeLists.txt | |||
*** $ cmake --build .. | |||
*** Launch your app.. | |||
* | |||
* | |||
*Put the installed tools into your PATH, prepend to PATH if needed to avoid mixing with older versions in your system<syntaxhighlight lang="bash"> | *Put the installed tools into your PATH, prepend to PATH if needed to avoid mixing with older versions in your system<syntaxhighlight lang="bash"> | ||
<QtSdk>/Tools/CMake/bin | <QtSdk>/Tools/CMake/bin | ||
Revision as of 09:58, 7 October 2021
"Work in Progress"
Prerequisites
Conan depends on Python installed on your system. Although the Conan client may be standalone executable the Conan packages itself contain recipes that are written in Python.
- Python 3.5 or higher
- If you want to use Conan to build packages from sources
- CMake (>= 3.16, >= 3.18.4 for Ninja Multi-Config, >= 3.21.1 for static Qt builds in Qt 6.2+)
- Ninja
- A working C++ compiler, supporting at least C++ 17
- Install required development libraries: https://doc.qt.io/qt-6/gettingstarted.html#platform-requirements
- ICU
- There is work in progress to bring ICU as Conan package(s) as a dependency to Qt packages so that it is taken care of automatically for the users (QTQAINFRA-4592). Until that one unfortunately needs to manually install ICU libs to system path where those can be found.
- For example linux/macOS:
- $ mkdir $HOME/icu_libs
- $ cp $HOME/MyQtInstallation/6.2.0/gcc_64/lib/libicu* $HOME/icu_libs
- export LD_LIBRARY_PATH=$HOME/icu_libs
Installing Conan
There are multiple options to install Conan package manager on your system:
- Official downloads: https://conan.io/downloads.html
- Qt Installer: https://download.qt.io/official_releases/online_installers/
- Qt -> Tools -> Conan
- Python environment: $ pip install conan
Connecting to Conan remote
First you need credentials to Conan server. Login to your Qt Account and click on the "Conan Package Manager" link.

- Click on the "Get a new password" link. These are your personal credentials to Conan remote.
- Add Conan remote to your environment
- $ conan remote add qt https://qtpkgtest.jfrog.io/artifactory/api/conan/qt
- You can choose the alias name for the remote name
- This will add it into $HOME/.conan/remotes.json
- $ conan remote list
- $ conan remote add qt https://qtpkgtest.jfrog.io/artifactory/api/conan/qt
- Authenticate to the server
- $ conan user USERNAME -p PASSWORD -r qt
- Run a search command to verify that your credentials and the remote were ok
- $ conan search -r qt
Qt Conan packages
To get an idea what Qt Conan packages are available run the following command
- $ conan search -r qt
Existing package recipes:
qtbase/6.2.0@qt/everywhere
qtdeclarative/6.2.0@qt/everywhere
qtimageformats/6.2.0@qt/everywhere
qtmultimedia/6.2.0@qt/everywhere
The generic pattern for package naming is: <module name>/<version>-<pre-release segment>@qt/everywhere
- Tome Qt .git repositories may yield multiple Conan packages like qtscxml.git -> qscxml, qtscxmlqml, qtscmlstatemachine and qtscxmlstatemachineqml
- The optional pre-release segment may contain e.g. 6.2.0-alpha1, 6.2.0-beta2, 6.2.0-rc3
Build profiles
To tell Conan the build configuration you are interested about there are basically two ways (or three if you want to let Conan guess the default values). You can pass each setting and option sepately from c
Building
- Next to your project/app create a file that declares the Qt library dependencies as Conan packages:
- conanfile.txt: # filename can be anything
- [requires] qtbase/6.2.0@qt/everywhere qtdeclarative/6.2.0@qt/everywhere # what ever your project/app may require qtcharts/6.2.0@qt/everywhere
- conanfile.txt: # filename can be anything
- Get the build profiles
- Call Conan to install the requirements for you:
- Get the build profiles to make things easier
- git clone qt5.git#dev # coin/conan/profiles
- merge pending to 6.2.0 branch
- Note! It is not decided yet how we want to distribute the profile files to end users. Possible options are:
- put them in a zip file to download.qt.io # $ conan config install <URL> <destination directory>
- create a dedicated conan package for profiles which can be installed: $ conan install qtbuildprofiles/6.2.0@qt/everywhere
- git clone qt5.git#dev # coin/conan/profiles
- $ conan install <path>/conanfile.txt --build=missing --profile=/home/<user>/qt5/coin/conan/profiles/linux-x86_64-gcc --update --generator=virtualenv --remote=qt
- --build
- "--build" will force a complete build from sources including transitive dependencies
- "--build=never" will attempt to install pre-built binaries (from local cache or from given server) if those should exist for the given build configuration i.e. --profile. If requested build configuration is not found (cache or server) Conan will bail out with an error
- "--build=missing" Conan will attempt to build those missing packages/dependencies for the requested build configuration which are missing
- https://docs.conan.io/en/latest/mastering/policies.html
- --profile
- This specifies the build configuration i.e. Conan settings (os, os version, compiler, arch, ...) and Options (shared, release, headersclean, ..)
- Edit if needed
- Settings and Options in profile file can be overridden from command line by:
- -s compiler.version=9.3 -s compiler.libcxx=libstdc++11 -o release=no -o shared=no ...
- This specifies the build configuration i.e. Conan settings (os, os version, compiler, arch, ...) and Options (shared, release, headersclean, ..)
- --update
- Forces Conan to check if the given server (-r, --remote) contains newer version of the package(s) and downloads those if found. This option should be always preferred
- --generator
- multiple can be given
- "--generator=virtualenv"
- This will generate 'activate.sh'/'activate.ps1' which you can call
- $ source activate.sh # on windows do not use 'source' -command
- Now all the Qt packages are in your PATH/env which were declared in the conaninfo.txt file
- This will generate 'activate.sh'/'activate.ps1' which you can call
- "--generator=qmake"
- This will generate conanbuildinfo.pri file which you can include in your projects .pro file
- --remote
- Ask Conan to install the package(s) from the given remote server to your local Conan cache
- --build
- Note! If you want to export the binaries out from the Conan cache to given directory you need to call conan install a bit differently
- $ conan install qtdeclarative/6.2.0@qt/everywhere --build=missing --profile=<profile> --update --install-folder=/home/<user>/Qt/6.2.0/gcc
- You should have the binaries of the required package and all of its transitive dependencies installed to the given directory with the usual directory layout:
- lib/
- bin/
- include/
- ...
- You should have the binaries of the required package and all of its transitive dependencies installed to the given directory with the usual directory layout:
- Note! If you call $conan install <path>/conanfile.txt ... args ... --install-folder=/foo Conan will export binaries from cache to separate sub-directories per dependency
- /foo/qtbase/lib|bin|include|...
- /foo/qtdeclarative/lib|bin|include|...
- /foo/qtcharts/lib|bin|include|...
- $ conan install qtdeclarative/6.2.0@qt/everywhere --build=missing --profile=<profile> --update --install-folder=/home/<user>/Qt/6.2.0/gcc
- Once you have activated the 'activate.sh/activate.ps1' your can compile your project
- $ cd your_project_path && mkdir build && cd build
- $ cmake ../CMakeLists.txt
- $ cmake --build ..
- Launch your app..
- Get the build profiles to make things easier
- Put the installed tools into your PATH, prepend to PATH if needed to avoid mixing with older versions in your system
<QtSdk>/Tools/CMake/bin <QtSdk>/Tools/Conan <QtSdk>/Tools/Ninja
- 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
- e.g.
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
- For MSVC compiler open command prompt and execute vcvars64.bat
- 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 -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
-g qmake
- Where the built binaries are?
$HOME/.conan/data/qtnetw<nowiki/>orkauth/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:
$PWD/include $PWD/libs $PWD/mkspecs $PWD/modules
- If using "-g deploy" generator the binaries are exported to a sub-folder named by the module:
$PWD/qtnetworkauth/include $PWD/qtnetworkauth/lib $PWD/qtnetworkauth/mkspecs $PWD/qtnetworkauth/modules
- The "conan(.exe) install" commands below will install the built binaries also to your current working directory so you may want to:
- 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}") endif() endforeach() .. .. 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 directory and you should be able to launch it
bin/*
- The MyApp should be in
- Running the application
- The deploy generator passed to conan deploys the build binaries from conan cache to your working directory
-g deploy
- 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
- Put the deployed binaries to the same directory of your built application
- The deploy generator
- Edit the CMakeLists.txt of your MyApp project
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:Note: QT_ADDITIONAL_PACKAGES_PREFIX_PATH does not work.
find_package(Qt6NetworkAuth)
- Edit the CMakeLists.txt of your MyApp project
include(/path/to/your/build_dir/conan_paths.cmake) 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