1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
6\ingroup cmake-macros-qtwidgets
11\summary {Creates sources for .ui files.}
13\include cmake-find-package-widgets.qdocinc
18qt_wrap_ui(<VAR> ui_file1 [ui_file2 ...]
22\versionlessCMakeCommandsNote qt6_wrap_ui()
26Creates rules for calling the \l{uic}{User Interface Compiler (uic)} on the given
27\c{.ui} files. For each input file, an header file is generated in the build
28directory. The paths of the generated header files are added to \c{<VAR>}.
30\note This is a low-level macro. See the \l{CMake AUTOUIC Documentation} for a
31more convenient way to process \c{.ui} files with \c{uic}.
34\note \l{qt6_add_ui}{qt_add_ui} is the recommended way to process \c{.ui}
39You can set additional \c{OPTIONS} that should be added to the \c{uic} calls.
40You can find possible options in the \l{uic}{uic documentation}.
44\snippet cmake-macros/examples.cmake qt_wrap_ui
49\ingroup cmake-macros-qtwidgets
54\summary {Adds .ui files to a target.}
56\include cmake-find-package-widgets.qdocinc
62 SOURCES file1.ui [file2.ui ...]
63 [INCLUDE_PREFIX <PREFIX>]
67\versionlessCMakeCommandsNote qt6_add_ui()
73Creates rules for calling the \l{uic}{User Interface Compiler (uic)} on the
74\c{.ui} files. For each input file, a header file is generated in the build
75directory. The generated header files are added to sources of the target.
81The \c{TARGET} argument specifies the CMake target to which the generated header
86The \c{SOURCES} argument specifies the list of \c{.ui} files to process.
88\section2 INCLUDE_PREFIX
90\c INCLUDE_PREFIX specifies the include prefix for the generated header files.
91Use the same include prefix as in the \c{#include} directive in the source
92files. If \c{ui_<basename>.h} is included without a prefix, then this argument
97You can set additional \c{OPTIONS} that should be added to the \c{uic} calls.
98You can find possible options in the \l{uic}{uic documentation}.
102\section2 Without INCLUDE_PREFIX
104In the following snippet, the \c{mainwindow.cpp} file includes
105\c{ui_mainwindow.h} and \c{mainwindow.h}.
107\snippet cmake-macros/examples.cpp qt6_add_ui_1
109\c{CMakeLists.txt} is implemented as follows and it calls
110\l{qt6_add_ui}{qt_add_ui} to add \c{ui_mainwindow.h} to the \c{myapp} target.
112\snippet cmake-macros/examples.cmake qt6_add_ui_1
114In the above example, \c{ui_mainwindow.h} is included without a prefix. So the
115\c{INCLUDE_PREFIX} argument is not specified.
117\section2 With INCLUDE_PREFIX
119\snippet cmake-macros/examples.cpp qt6_add_ui_2
121In the above snippet, \c{mainwindow.cpp} includes \c{ui_mainwindow.h} with a
124\snippet cmake-macros/examples.cmake qt6_add_ui_2
126Since \c{ui_mainwindow.h} is included with a prefix, the \c{INCLUDE_PREFIX}
127argument is specified as \c{src/files} in the above example.
129\section2 Multiple .ui files
131In the following snippets, both \c{widget1.cpp} and \c{widget2.cpp} include
132\c{ui_widget1.h} and \c{ui_widget2.h} respectively.
136\snippet cmake-macros/examples.cpp qt6_add_ui_3_1
140\snippet cmake-macros/examples.cpp qt6_add_ui_3_2
142Both \c{ui_widget1.h} and \c{ui_widget2.h} are included with the same prefix
144\snippet cmake-macros/examples.cmake qt6_add_ui_3
146In this case, the \c{INCLUDE_PREFIX} argument can be specified as \c{src/files}
147for both files in the above snippet.
149\section1 When to prefer \l{qt6_add_ui}{qt_add_ui} over \c{AUTOUIC}?
151\l{qt6_add_ui}{qt_add_ui} has some advantages over \c{AUTOUIC}:
154\li \l{qt6_add_ui}{qt_add_ui} ensures that the \c{.ui} files are generated
155correctly during the first build, for the \c{Ninja} and \c{Ninja Multi-Config}
158\li \l{qt6_add_ui}{qt_add_ui} guarantees that the generated \c{.h} files are
159not leaked outside the build directory.
161\li Since \l{qt6_add_ui}{qt_add_ui} does not scan source files, it provides a
162faster build than \c{AUTOUIC}.
166\section1 When to prefer \l{qt6_add_ui}{qt_add_ui} over \c{qt_wrap_ui}?
168\l{qt6_add_ui}{qt_add_ui} has the \c{INCLUDE_PREFIX} argument, which can be used to
169specify the include prefix for the generated header files.
171\note It is not recommended to use both \l{qt6_add_ui}{qt_add_ui} and
172\c{AUTOUIC} for the same target.