Jump to content

Using Conan for Qt6: Difference between revisions

From Qt Wiki
Iieklund (talk | contribs)
No edit summary
Iieklund (talk | contribs)
No edit summary
Line 3: Line 3:
"Work in Progress"
"Work in Progress"


== Qt6 Add-on src package build using Conan package manager ==
==Qt6 Add-on src package build using Conan package manager==


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


== Linux ==
==Linux==
* Install required development libraries: https://doc-snapshots.qt.io/qt5-dev/linux-requirements.html
 
* Qt Installer - install:
*Install required development libraries: https://doc-snapshots.qt.io/qt6-dev/gettingstarted.html#platform-requirements
** CMake (3.15 or higher is required)
*Qt Installer - install:
** Conan (installs standalone conan(.exe) executable + settings files
**CMake (3.15 or higher is required)
** Ninja (CMake generator)
**Conan (installs standalone conan(.exe) executable + settings files
** 6.0.0 essentials binary package
**Ninja (CMake generator)
** Add-on src package(s) needed in your CMake project
**6.0.0 essentials binary package
*** Qt Installer provides Add-on packages under top-level "Additional libraries" node
**Add-on src package(s) needed in your CMake project
* Put the installed tools into you PATH, prepend to PATH if needed to avoid mixing with older versions in your system
***Qt Installer provides Add-on packages under top-level "Additional libraries" node
** <QtSdk>/Tools/CMake/bin
*Put the installed tools into you PATH, prepend to PATH if needed to avoid mixing with older versions in your system
** <QtSdk>/Tools/Conan
**<QtSdk>/Tools/CMake/bin
** <QtSdk>/Tools/Ninja
**<QtSdk>/Tools/Conan
* After installation of the 6.0.0 essentials binary package edit the following file: '<QtSdk>/6.0.0/gcc_64/lib/cmake/Qt6/qt.toolchain.cmake'
**<QtSdk>/Tools/Ninja
** Comment out the two first lines (the paths refer to the CI build environment)
*'''Build the conan package'''
** TODO: This step is not required after a patch to qtbase <https://codereview.qt-project.org/c/qt/qtbase/+/313965> lands into 6.0.0 snapshots
**$conan(.exe) install qtnetworkauth/6.0.0@qt/beta --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)
* '''Build the conan package'''
***the cmake_paths generator will produce ''''conan_paths.cmake'''<nowiki/>' to your working directory, include it in your CMake project
** <QtSdk>/Tools/Conan/conan(.exe) install qtnetworkauth/6.0.0@qt/alpha --build=missing --profile=<QtSdk>/Tools/Conan/.conan/profiles/qt-6.0.0-linux -s build_type=Release '''-g cmake_paths''' -g=cmake (-g deploy)
**After successful build the built package should exist in your Conan cache: '$HOME/.conan/data/qtnetworkauth/6.0.0/qt/beta/package'
*** the cmake_paths generator will produce ''''conan_paths.cmake'''<nowiki/>' to your working directory, include it in your CMake project
***Note: If you have configured your conan home/cache folder differently the built package is located there
** After successful build the built package should exist in your Conan cache: 'Tools/Conan/.conan/data/qtnetworkauth/6.0.0/qt/alpha/package'
*Edit the CMakeLists.txt of your MyApp project
* Edit the CMakeLists.txt of your MyApp project


     include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
     include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
Line 51: Line 50:


     target_link_libraries(QtMPConsumerApp PRIVATE Qt::Widgets '''Qt::NetworkAuth''')
     target_link_libraries(QtMPConsumerApp PRIVATE Qt::Widgets '''Qt::NetworkAuth''')
* Build 'MyApp'
** $ cd myapp
** $ mkdir build && cd build
** $ cmake -DCMAKE_INSTALL_PREFIX=<QtSdk>/6.0.0/gcc_64 -DCMAKE_BUILD_TYPE=Release ..
** $ cmake --build .
** The MyApp should be in 'bin/* directory and you should be able to launch it


== macOS ==
*Build 'MyApp'
* Follow the same steps as for Linux above with the following changes
**$ cd myapp
** set(ENV{CONAN_DEFAULT_PROFILE_PATH} "<QtSdk>/Tools/Conan/.conan/profiles/qt-6.0.0-macx-clang")
**$ mkdir build && cd build
** export DYLD_FRAMEWORK_PATH with paths to 6.0.0 essentials & qtnetworkauth deploy directory
**$ cmake -DCMAKE_INSTALL_PREFIX=<QtSdk>/6.0.0/gcc_64 -DCMAKE_BUILD_TYPE=Release ..
**$ cmake --build .
**The MyApp should be in 'bin/* directory and you should be able to launch it
 
==macOS==
 
*Follow the same steps as for Linux above with the following changes
**export DYLD_FRAMEWORK_PATH with paths to 6.0.0 essentials & qtnetworkauth deploy directory
 
==Windows (MSVC 2019 compiler)==
 
*Follow the same steps as for Linux above with the following changes
*Open command prompt and execute vcvars64.bat
**"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
*Please note that Perl seems to be required also but not available from online installer at the moment.
*Add Qt binary folder into path
**path=<QtSdk>\6.0.0\msvc2019_64\bin;%PATH%
 
== 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 add-on.
 
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:


== Windows (MSVC 2019 compiler) ==
- $conan config install <git-repo> -sf <path-in-git-repo> -tf <destination-path>
* Follow the same steps as for Linux above with the following changes
* Open command prompt and execute vcvars64.bat
** "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
* Please note that Perl seems to be required also but not available from online installer at the moment.
* Add Qt binary folder into path
** path=<QtSdk>\6.0.0\msvc2019_64\bin;%PATH%
** set QT_CONAN_PROFILE=qt-6.0.0-msvc2019_64


- 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==


== Further notes ==
*Make sure the conan(.exe) provided by the Qt Installer is prepended into the PATH to avoid mixing it with system conan (if installed)
* Make sure the conan(.exe) provided by the Qt Installer is prepended into the PATH to avoid mixing it with system conan (if installed)
*Ninja is the recommended CMake generator and should be used. E.g. on Windows you may get compilation time errors if using VS generator
* Ninja is the recommended CMake generator and should be used. E.g. on Windows you may get compilation time errors if using VS generator

Revision as of 06:32, 23 October 2020

"Work in Progress"

Qt6 Add-on src package build using Conan package manager

To build Qt6 Add-on 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.

Linux

  • Install required development libraries: https://doc-snapshots.qt.io/qt6-dev/gettingstarted.html#platform-requirements
  • Qt Installer - install:
    • CMake (3.15 or higher is required)
    • Conan (installs standalone conan(.exe) executable + settings files
    • Ninja (CMake generator)
    • 6.0.0 essentials binary package
    • Add-on src package(s) needed in your CMake project
      • Qt Installer provides Add-on packages under top-level "Additional libraries" node
  • Put the installed tools into you 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 conan package
    • $conan(.exe) install qtnetworkauth/6.0.0@qt/beta --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)
      • the cmake_paths generator will produce 'conan_paths.cmake' to your working directory, include it in your CMake project
    • After successful build the built package should exist in your Conan cache: '$HOME/.conan/data/qtnetworkauth/6.0.0/qt/beta/package'
      • Note: If you have configured your conan home/cache folder differently the built package is located there
  • Edit the CMakeLists.txt of your MyApp project
   include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
   find_package(Qt6 COMPONENTS Widgets Network)
   find_package(Qt6NetworkAuth)
   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(QtMPConsumerApp PRIVATE Qt::Widgets Qt::NetworkAuth)
  • Build 'MyApp'
    • $ cd myapp
    • $ mkdir build && cd build
    • $ cmake -DCMAKE_INSTALL_PREFIX=<QtSdk>/6.0.0/gcc_64 -DCMAKE_BUILD_TYPE=Release ..
    • $ cmake --build .
    • The MyApp should be in 'bin/* directory and you should be able to launch it

macOS

  • Follow the same steps as for Linux above with the following changes
    • export DYLD_FRAMEWORK_PATH with paths to 6.0.0 essentials & qtnetworkauth deploy directory

Windows (MSVC 2019 compiler)

  • Follow the same steps as for Linux above with the following changes
  • Open command prompt and execute vcvars64.bat
    • "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
  • Please note that Perl seems to be required also but not available from online installer at the moment.
  • Add Qt binary folder into path
    • path=<QtSdk>\6.0.0\msvc2019_64\bin;%PATH%

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 add-on.

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 [[1]] -sf profiles/qt/linux/6.0.0 -tf /home/<user>/temp_path

Further notes

  • Make sure the conan(.exe) provided by the Qt Installer is prepended into the PATH to avoid mixing it with system conan (if installed)
  • Ninja is the recommended CMake generator and should be used. E.g. on Windows you may get compilation time errors if using VS generator