CMake Port: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add notes)
(cmake/README.md should no longer point to wip/cmake but dev branch)
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:CMake Port]]
This is an overview on the port of Qt from qmake to CMake.
This is an overview on the port of Qt from qmake to CMake.


== Non-technical issues: ==
== Quick Links ==
 
* [https://bugreports.qt.io/browse/QTBUG-73351 Key initiative: Transition to CMake in JIRA]
* [irc://chat.freenode.net:6665/qt-cmake #qt-cmake channel on freenode/IRC]
* [http://code.qt.io/cgit/qt/qtbase.git/log/?h=wip/cmake wip/cmake branch in qtbase]
* [http://code.qt.io/cgit/qt/qtbase.git/tree/cmake/README.md?h=dev cmake/README.md]
 
== Overview ==
 
The current port of qtbase can be found in the [https://codereview.qt-project.org/#/q/project:qt/qtbase+branch:dev,n,z dev branch] of qt/qtbase.git. See also [http://code.qt.io/cgit/qt/qtbase.git/tree/cmake/README.md?h=dev cmake/README.md in the sources.]
 
This port was announced and discussed on the qt-development mailing list: [https://lists.qt-project.org/pipermail/development/2018-October/034023.html "Build system for Qt 6" thread on development@qt-project.org]
 
== Development Status ==
 
* [[CMake_Port/Development_Notes|Development Notes by date]]: the summary of the development progress.
 
== Sub-pages ==
 
{{Special:PrefixIndex/CMake_Port/}}
 
== Non-technical issues ==


=== Open Questions ===
=== Open Questions ===
Line 38: Line 60:
* Do we need more changes in cmake? We want a released cmake with everything we need in time for the Qt 6 release, so we need to push this through review upstream ASAP!
* Do we need more changes in cmake? We want a released cmake with everything we need in time for the Qt 6 release, so we need to push this through review upstream ASAP!
* Work on finding all the 3rd-party code we need. E.g. I got a patch for OpenGL in gerrit that needs some work in the find_packages department.
* Work on finding all the 3rd-party code we need. E.g. I got a patch for OpenGL in gerrit that needs some work in the find_packages department.
* Cross compilation: It would be wonderful if somebody with more knowledge in that area could look into this topic.
* Cross compilation:
** Requires that the target sysroot contains all third-party libraries that we use, including things like double-conversion, harfuzz, etc.
*** The use of vcpkg in combination with yocto is tricky as yocto's environment setup strictly tells cmake to not look anywhere else for libraries/files/packages. So it's best to not combine them but make sure that your yocto SDK has everything you need. Simplest workaround: Create a simple arm-linux triplet, build pcre2, double-conversion with vcpkg from within a shell that's been through yocto's environment-setup-* and copy the resulting artifacts into the sysroot (from $vcpkg_root/installed/$yourtriplet to $sysroot/usr)
** Requires a separate host build of Qt (that's installed), and then pass -DHOST_QT_TOOLS_DIRECTORY=/path/to/where/host/build/is/installed/bin (the bin is important!)
** The plan is to replace the HOST_QT_TOOLS_DIRECTORY with a more fine-grained and extensible tools selection by having per-Qt module tools packages (Qt6CoreTools, Qt6QuickTools, Qt63dTools)
* CI: What needs to be done to make our CI build cmake projects? Can we get that sorted to get wider test coverage (and an idea how the switch will effect build times:-).
* CI: What needs to be done to make our CI build cmake projects? Can we get that sorted to get wider test coverage (and an idea how the switch will effect build times:-).
** More passing tests in Qt base
** More passing tests in Qt base
Line 53: Line 79:
* Library naming: Qt library names are missing SOVERSION, etc. pp.
* Library naming: Qt library names are missing SOVERSION, etc. pp.


== Porting Notes ==
== Technical decisions ==
* Process of getting new CMakeLists.txt files, ideally:
* Why use AUTOMOC instead of a custom scanner + custom build rules?
** Run the conversion script
Initially we did use a custom scanner, but we encountered a big issue and decided to go with AUTOMOC.
** Edit the places which fail by hand, add a comment stating that it was edited by hand
** When the conversion script was fixed, and it re-run:
*** Either the code next to the comment is fixed automatically
*** Or the hand-edited version needs to be kept


== Quick Links ==
Headers and cpp files need to be scanned ONLY after all sources are set for the target, so the safest way to do it would be after all directories and targets are processed. The problem is that it's not possible to associate additional sources (the generated moc.cpp files) to a target outside the directory where the target was defined.
 
* [https://bugreports.qt.io/browse/QTBUG-73351 Key initiative: Transition to CMake in JIRA]
* [https://lists.qt-project.org/pipermail/development/2018-October/034023.html "Build system for Qt 6" thread on development@qt-project.org]
* [irc://chat.freenode.net:6665/qt-cmake #qt-cmake channel on freenode/IRC]
 
== Overview ==


The current port of qtbase can be found in the [https://codereview.qt-project.org/#/q/project:qt/qtbase+branch:wip/cmake,n,z wip/cmake branch] of qt/qtbase.git. See also [http://code.qt.io/cgit/qt/qtbase.git/tree/cmake/README.md?h=wip/cmake cmake/README.md in the sources.]
Another proposed approach was to scan and associate the additional sources just before the directory scope is left, by abusing CMake's [https://cmake.org/cmake/help/latest/command/variable_watch.html variable_watch] on the CMAKE_CURRENT_SOURCE_DIR variable, but the maintainers of CMake claimed that it is an implementation detail that is liable to change, so it would not be safe to use.

Revision as of 07:12, 17 June 2020

This is an overview on the port of Qt from qmake to CMake.

Quick Links

Overview

The current port of qtbase can be found in the dev branch of qt/qtbase.git. See also cmake/README.md in the sources.

This port was announced and discussed on the qt-development mailing list: "Build system for Qt 6" thread on development@qt-project.org

Development Status

Sub-pages

Non-technical issues

Open Questions

  • Qt development workflows:
    • Documentation and knowledge transfer:
    • Where will the CMake workflow differ from the current qmake one?
  • Document the differences and explain why they exist to reduce friction of devs
    • building Qt with CMake
  • How can we spread the knowledge? In the end everybody needs to work with cmake, so how do we train our devs and contributors to write/update the build system?
  • What is the process to get fixes from Qt 5 into Qt 6? We will need to do that for a long time after all
  • 3rd party code:
    • How do we get external libraries into place -- now that we are getting rid of src/3rdparty? VCPKG? Can we get that decided and into place?
  • Projects *using* Qt
    • How can we ease the transition of current CMake based Qt 5 projects to Qt6 with CMake? Can we introduce changes to Qt 5 right now to make switching between Qt 5/Qt 6 easier?
    • Idea:
      • For Qt5:
        • Status quo: `find_package(Qt5 ...), results in targets: Qt5::Core.
        • In future, also export targets named: Qt::Core (for Qt6 compat)
      • Qt6:
        • Should: `find_package(Qt6 ...)`, results in targets: Qt::Core
  • How can we ease the transition of current qmake based Qt 5 projects to Qt6 with CMake?
    • Idea: Tobias has porting scripts, but they are very Qt specific
      • Probably not useful for the average Qt developer
  • QMake support in Qt6?
    • Customer still need to build QMake projects
    • Idea: Make QMake build outside qtbase.git
      • Do a verbatim copy of mkspecs for Qt6
      • Let CMake generate the QMake module .pri files (via ECM's CMake modules)
  • Qt Community:
    • How do we communicate the progress to our community and get a community decision on the build system for Qt 6?
    • We'll put this document on the wiki, work on it, later turn it into a QUIP

Technical issues

  • Do we need more changes in cmake? We want a released cmake with everything we need in time for the Qt 6 release, so we need to push this through review upstream ASAP!
  • Work on finding all the 3rd-party code we need. E.g. I got a patch for OpenGL in gerrit that needs some work in the find_packages department.
  • Cross compilation:
    • Requires that the target sysroot contains all third-party libraries that we use, including things like double-conversion, harfuzz, etc.
      • The use of vcpkg in combination with yocto is tricky as yocto's environment setup strictly tells cmake to not look anywhere else for libraries/files/packages. So it's best to not combine them but make sure that your yocto SDK has everything you need. Simplest workaround: Create a simple arm-linux triplet, build pcre2, double-conversion with vcpkg from within a shell that's been through yocto's environment-setup-* and copy the resulting artifacts into the sysroot (from $vcpkg_root/installed/$yourtriplet to $sysroot/usr)
    • Requires a separate host build of Qt (that's installed), and then pass -DHOST_QT_TOOLS_DIRECTORY=/path/to/where/host/build/is/installed/bin (the bin is important!)
    • The plan is to replace the HOST_QT_TOOLS_DIRECTORY with a more fine-grained and extensible tools selection by having per-Qt module tools packages (Qt6CoreTools, Qt6QuickTools, Qt63dTools)
  • CI: What needs to be done to make our CI build cmake projects? Can we get that sorted to get wider test coverage (and an idea how the switch will effect build times:-).
    • More passing tests in Qt base
    • Better testing of MacOS and Windows.
  • Add one more Qt module and see how that works -- building it stand-alone against an already installed QtBase and from a master build directory.
    • Idea: Test building qtsvg
    • Create a wip/cmake branch on Gerrit (but not necessarily)
  • Creator integration
    • Currently QtCreator needs `qmake -query` to identify Qt kits
    • Needs something similar in the CMake world, basically a Qt description file format (CMake? JSON?)
  • Qt build compiler flags
    • Qt configure's -developer-build builds with warnings-as-errors, how to do it in CMake?
    • Idea: Use ECM code for inspiration? -- will probably still need to enable warnings-as-errors manually
  • Library naming: Qt library names are missing SOVERSION, etc. pp.

Technical decisions

  • Why use AUTOMOC instead of a custom scanner + custom build rules?

Initially we did use a custom scanner, but we encountered a big issue and decided to go with AUTOMOC.

Headers and cpp files need to be scanned ONLY after all sources are set for the target, so the safest way to do it would be after all directories and targets are processed. The problem is that it's not possible to associate additional sources (the generated moc.cpp files) to a target outside the directory where the target was defined.

Another proposed approach was to scan and associate the additional sources just before the directory scope is left, by abusing CMake's variable_watch on the CMAKE_CURRENT_SOURCE_DIR variable, but the maintainers of CMake claimed that it is an implementation detail that is liable to change, so it would not be safe to use.