|
@@ -10,34 +10,39 @@ cmake-qt(7)
|
|
|
Introduction
|
|
|
============
|
|
|
|
|
|
-CMake can find and use Qt 4 and Qt 5 libraries. The Qt 4 libraries are found
|
|
|
-by the :module:`FindQt4` find-module shipped with CMake, whereas the
|
|
|
-Qt 5 libraries are found using "Config-file Packages" shipped with Qt 5. See
|
|
|
-:manual:`cmake-packages(7)` for more information about CMake packages, and
|
|
|
-see `the Qt cmake manual <https://doc.qt.io/qt-5/cmake-manual.html>`_
|
|
|
-for your Qt version.
|
|
|
-
|
|
|
-Qt 4 and Qt 5 may be used together in the same
|
|
|
+CMake can find and use Qt 4, Qt 5 and Qt 6 libraries. The Qt 4 libraries are
|
|
|
+found by the :module:`FindQt4` find-module shipped with CMake, whereas the
|
|
|
+Qt 5 and Qt 6 libraries are found using "Config-file Packages" shipped with
|
|
|
+Qt 5 and Qt 6. See :manual:`cmake-packages(7)` for more information about CMake
|
|
|
+packages, and see `the Qt cmake manual`_ for your Qt version.
|
|
|
+
|
|
|
+.. _`the Qt cmake manual`: https://doc.qt.io/qt-6/cmake-manual.html
|
|
|
+
|
|
|
+Qt 4, Qt 5 and Qt 6 may be used together in the same
|
|
|
:manual:`CMake buildsystem <cmake-buildsystem(7)>`:
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
- cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
|
|
|
+ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
|
|
|
|
|
- project(Qt4And5)
|
|
|
+ project(Qt4_5_6)
|
|
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
|
|
- find_package(Qt5 COMPONENTS Widgets DBus REQUIRED)
|
|
|
+ find_package(Qt6 COMPONENTS Widgets DBus REQUIRED)
|
|
|
add_executable(publisher publisher.cpp)
|
|
|
- target_link_libraries(publisher Qt5::Widgets Qt5::DBus)
|
|
|
+ target_link_libraries(publisher Qt6::Widgets Qt6::DBus)
|
|
|
+
|
|
|
+ find_package(Qt5 COMPONENTS Gui DBus REQUIRED)
|
|
|
+ add_executable(subscriber1 subscriber1.cpp)
|
|
|
+ target_link_libraries(subscriber1 Qt5::Gui Qt5::DBus)
|
|
|
|
|
|
find_package(Qt4 REQUIRED)
|
|
|
- add_executable(subscriber subscriber.cpp)
|
|
|
- target_link_libraries(subscriber Qt4::QtGui Qt4::QtDBus)
|
|
|
+ add_executable(subscriber2 subscriber2.cpp)
|
|
|
+ target_link_libraries(subscriber2 Qt4::QtGui Qt4::QtDBus)
|
|
|
|
|
|
-A CMake target may not link to both Qt 4 and Qt 5. A diagnostic is issued if
|
|
|
-this is attempted or results from transitive target dependency evaluation.
|
|
|
+A CMake target may not link to more than one Qt version. A diagnostic is issued
|
|
|
+if this is attempted or results from transitive target dependency evaluation.
|
|
|
|
|
|
Qt Build Tools
|
|
|
==============
|
|
@@ -46,7 +51,7 @@ Qt relies on some bundled tools for code generation, such as ``moc`` for
|
|
|
meta-object code generation, ``uic`` for widget layout and population,
|
|
|
and ``rcc`` for virtual file system content generation. These tools may be
|
|
|
automatically invoked by :manual:`cmake(1)` if the appropriate conditions
|
|
|
-are met. The automatic tool invocation may be used with both Qt 4 and Qt 5.
|
|
|
+are met. The automatic tool invocation may be used with Qt version 4 to 6.
|
|
|
|
|
|
.. _`Qt AUTOMOC`:
|
|
|
|
|
@@ -158,7 +163,7 @@ should be used when running ``uic``:
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
add_library(KI18n klocalizedstring.cpp)
|
|
|
- target_link_libraries(KI18n Qt5::Core)
|
|
|
+ target_link_libraries(KI18n Qt6::Core)
|
|
|
|
|
|
# KI18n uses the tr2i18n() function instead of tr(). That function is
|
|
|
# declared in the klocalizedstring.h header.
|
|
@@ -213,25 +218,44 @@ overrides options from the :prop_tgt:`AUTORCC_OPTIONS` target property.
|
|
|
Source files can be excluded from :prop_tgt:`AUTORCC` processing by
|
|
|
enabling :prop_sf:`SKIP_AUTORCC` or the broader :prop_sf:`SKIP_AUTOGEN`.
|
|
|
|
|
|
+.. _`<ORIGIN>_autogen`:
|
|
|
+
|
|
|
The ``<ORIGIN>_autogen`` target
|
|
|
===============================
|
|
|
|
|
|
The ``moc`` and ``uic`` tools are executed as part of a synthesized
|
|
|
-``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>` generated by
|
|
|
-CMake. By default that ``<ORIGIN>_autogen`` target inherits the dependencies
|
|
|
+:ref:`<ORIGIN>_autogen` :command:`custom target <add_custom_target>` generated by
|
|
|
+CMake. By default that :ref:`<ORIGIN>_autogen` target inherits the dependencies
|
|
|
of the ``<ORIGIN>`` target (see :prop_tgt:`AUTOGEN_ORIGIN_DEPENDS`).
|
|
|
-Target dependencies may be added to the ``<ORIGIN>_autogen`` target by adding
|
|
|
+Target dependencies may be added to the :ref:`<ORIGIN>_autogen` target by adding
|
|
|
them to the :prop_tgt:`AUTOGEN_TARGET_DEPENDS` target property.
|
|
|
|
|
|
+.. note::
|
|
|
+ If Qt 5.15 or later is used and the generator is either :generator:`Ninja` or
|
|
|
+ :ref:`Makefile Generators`, see :ref:`<ORIGIN>_autogen_timestamp_deps`.
|
|
|
+
|
|
|
+.. _`<ORIGIN>_autogen_timestamp_deps`:
|
|
|
+
|
|
|
+The ``<ORIGIN>_autogen_timestamp_deps`` target
|
|
|
+==============================================
|
|
|
+
|
|
|
+If Qt 5.15 or later is used and the generator is either :generator:`Ninja` or
|
|
|
+:ref:`Makefile Generators`, the ``<ORIGIN>_autogen_timestamp_deps`` target is
|
|
|
+also created in addition to the :ref:`<ORIGIN>_autogen` target. This target
|
|
|
+does not have any sources or commands to execute, but it has dependencies that
|
|
|
+were previously inherited by the pre-Qt 5.15 :ref:`<ORIGIN>_autogen` target.
|
|
|
+These dependencies will serve as a list of order-only dependencies for the
|
|
|
+custom command, without forcing the custom command to re-execute.
|
|
|
+
|
|
|
Visual Studio Generators
|
|
|
========================
|
|
|
|
|
|
When using the :manual:`Visual Studio generators <cmake-generators(7)>`, CMake
|
|
|
generates a ``PRE_BUILD`` :command:`custom command <add_custom_command>`
|
|
|
-instead of the ``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>`
|
|
|
-(for :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`).
|
|
|
-This isn't always possible though and
|
|
|
-an ``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>` is used,
|
|
|
+instead of the :ref:`<ORIGIN>_autogen`
|
|
|
+:command:`custom target <add_custom_target>` (for :prop_tgt:`AUTOMOC` and
|
|
|
+:prop_tgt:`AUTOUIC`). This isn't always possible though and an
|
|
|
+:ref:`<ORIGIN>_autogen` :command:`custom target <add_custom_target>` is used,
|
|
|
when either
|
|
|
|
|
|
- the ``<ORIGIN>`` target depends on :prop_sf:`GENERATED` files which aren't
|