Qt6 Build System: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
For Qt5, see [[Qt5 Build System]].
For Qt5, see [[Qt5 Build System]].


For a description of terms used here, please see the [[Qt Build System Glossary]].  
For a description of terms used here, please see the [[Qt Build System Glossary]].


When writing CMake code, beware of the [[CMake Language Pitfalls]].
When writing CMake code, beware of the [[CMake Language Pitfalls]].
Line 24: Line 24:
Defines a feature called <feature>.  Whether a feature is enabled can be then elsewhere be checked by <tt>QT_FEATURE_<name></tt>.
Defines a feature called <feature>.  Whether a feature is enabled can be then elsewhere be checked by <tt>QT_FEATURE_<name></tt>.


<code>qt_feature("<feature>" [PUBLIC] [PRIVATE]
<code>qt_feature("<feature>" [PUBLIC] [PRIVATE]
                 [LABEL "<label>"]  
                 [LABEL "<label>"]
                 [PURPOSE "<purpose>"]  
                 [PURPOSE "<purpose>"]
                 [SECTION "<selection>"]  
                 [SECTION "<selection>"]
                 [AUTODETECT <condition>]  
                 [AUTODETECT <condition>]
                 [CONDITION <condition>]
                 [CONDITION <condition>]
                 [ENABLE <condition>]
                 [ENABLE <condition>]
Line 44: Line 44:
</code>
</code>


If <tt>&lt;value&gt;</tt> is set, the define will have this as value.  
If <tt>&lt;value&gt;</tt> is set, the define will have this as value.


If <tt>NEGATE</tt> is given, the define is set only if the feature is disabled. Otherwise it is set only if it is enabled.
If <tt>NEGATE</tt> is given, the define is set only if the feature is disabled. Otherwise it is set only if it is enabled.
Line 51: Line 51:
Qt's configure script is a convenience interface that translates its command line options to CMake arguments.
Qt's configure script is a convenience interface that translates its command line options to CMake arguments.


Most configure options are defined in &lt;code&gt;qt_cmdline.cmake&lt;/code&gt; files throughout the repositories. Each Qt repository can have a top-level &lt;code&gt;qt_cmdline.cmake&lt;/code&gt; file and several lower-level ones. For example, qtbase has the following files (at the time of writing):
Most configure options are defined in <tt>qt_cmdline.cmake</tt> files throughout the repositories. Each Qt repository can have a top-level <tt>qt_cmdline.cmake</tt> file and several lower-level ones. For example, qtbase has the following files (at the time of writing):
  qt_cmdline.cmake
  qt_cmdline.cmake
  src/corelib/qt_cmdline.cmake
  src/corelib/qt_cmdline.cmake
Line 62: Line 62:
  src/widgets/qt_cmdline.cmake
  src/widgets/qt_cmdline.cmake
  src/xml/qt_cmdline.cmake
  src/xml/qt_cmdline.cmake
The top-level file must reference the lower-level files. This is similar to include statements or CMake's &lt;code&gt;add_subdirectory&lt;/code&gt; calls.
The top-level file must reference the lower-level files. This is similar to include statements or CMake's <tt>add_subdirectory</tt> calls.
  qt_commandline_subconfig(src/corelib)
  qt_commandline_subconfig(src/corelib)
  qt_commandline_subconfig(src/network)
  qt_commandline_subconfig(src/network)

Revision as of 14:52, 20 March 2024


This is a description of the Qt6 CMake-based build system.

For Qt5, see Qt5 Build System.

For a description of terms used here, please see the Qt Build System Glossary.

When writing CMake code, beware of the CMake Language Pitfalls.

There is some historical information at CMake Port.

At the moment, there's not much here. We plan to extend this in the future. There's some information from the times of the initial CMake port. See below.

Configuration at CMake level

This is supposed to be a reference of Qt-specific CMake functions one can use in configure.cmake files. Since the port currently is still evolving quite rapidly, things may change. The ultimate reference is the code in qtbase/cmake/.

Commands in configure.cmake

qt_feature("<feature>" ...)

Defines a feature called <feature>. Whether a feature is enabled can be then elsewhere be checked by QT_FEATURE_<name>.

qt_feature("<feature>" [PUBLIC] [PRIVATE]
                [LABEL "<label>"]
                [PURPOSE "<purpose>"]
                [SECTION "<selection>"]
                [AUTODETECT <condition>]
                [CONDITION <condition>]
                [ENABLE <condition>]
                [DISABLE <condition>]
                [EMIT_IF <condition>])

PUBLIC or PRIVATE defines whether the feature is available within the Qt module, or also in other Qt modules.

qt_feature_definition("<feature>" "<name>" ...)

Makes a C++ define <name> available.

qt_feature_definition("<feature>" "<name>" [NEGATE] [VALUE "<value>"])

If <value> is set, the define will have this as value.

If NEGATE is given, the define is set only if the feature is disabled. Otherwise it is set only if it is enabled.

Qt's configure script

Qt's configure script is a convenience interface that translates its command line options to CMake arguments.

Most configure options are defined in qt_cmdline.cmake files throughout the repositories. Each Qt repository can have a top-level qt_cmdline.cmake file and several lower-level ones. For example, qtbase has the following files (at the time of writing):

qt_cmdline.cmake
src/corelib/qt_cmdline.cmake
src/gui/qt_cmdline.cmake
src/network/qt_cmdline.cmake
src/plugins/sqldrivers/qt_cmdline.cmake
src/printsupport/qt_cmdline.cmake
src/sql/qt_cmdline.cmake
src/testlib/qt_cmdline.cmake
src/widgets/qt_cmdline.cmake
src/xml/qt_cmdline.cmake

The top-level file must reference the lower-level files. This is similar to include statements or CMake's add_subdirectory calls.

qt_commandline_subconfig(src/corelib)
qt_commandline_subconfig(src/network)
qt_commandline_subconfig(src/gui)
qt_commandline_subconfig(src/sql)
qt_commandline_subconfig(src/xml)
qt_commandline_subconfig(src/widgets)
...

In principle, we could cram everything into one file.

Commands available in qt_cmdline.cmake

qt_commandline_subconfig

TBD

qt_commandline_option

TBD

qt_commandline_custom

TBD

qt_commandline_prefix

TBD

Common tasks

How to add a command line option that controls a feature?

TBD

How to add a command line option that sets a CMake variable?

TBD