Autogen: Doc: Update documentation for (CMAKE_)AUTOMOC_MACRO_NAMES

This commit is contained in:
Sebastian Holtermann
2017-09-25 19:52:11 +02:00
parent 7b33d67bc5
commit 08041dd15e
4 changed files with 32 additions and 29 deletions

View File

@@ -59,9 +59,10 @@ The :prop_tgt:`AUTOMOC` target property controls whether :manual:`cmake(1)`
inspects the C++ files in the target to determine if they require ``moc`` to inspects the C++ files in the target to determine if they require ``moc`` to
be run, and to create rules to execute ``moc`` at the appropriate time. be run, and to create rules to execute ``moc`` at the appropriate time.
If a ``Q_OBJECT`` or ``Q_GADGET`` macro is found in a header file, ``moc`` If a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is found in a header file,
will be run on the file. The result will be put into a file named according ``moc`` will be run on the file. The result will be put into a file named
to ``moc_<basename>.cpp``. If the macro is found in a C++ implementation according to ``moc_<basename>.cpp``.
If the macro is found in a C++ implementation
file, the moc output will be put into a file named according to file, the moc output will be put into a file named according to
``<basename>.moc``, following the Qt conventions. The ``<basename>.moc`` must ``<basename>.moc``, following the Qt conventions. The ``<basename>.moc`` must
be included by the user in the C++ implementation file with a preprocessor be included by the user in the C++ implementation file with a preprocessor
@@ -95,9 +96,7 @@ following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The
options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS` options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS`
variable may be populated to pre-set the options for all following targets. variable may be populated to pre-set the options for all following targets.
The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file Additional macro names to search for can be added to :prop_tgt:`AUTOMOC_MACRO_NAMES`.
determines if it needs to be ``moc`` processed. To search for additional
strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`.
Additional ``moc`` dependency file names can be extracted from source code Additional ``moc`` dependency file names can be extracted from source code
by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.

View File

@@ -12,8 +12,8 @@ When this property is set ``ON``, CMake will scan the header and
source files at build time and invoke moc accordingly. source files at build time and invoke moc accordingly.
* If an ``#include`` statement like ``#include "moc_<basename>.cpp"`` is found, * If an ``#include`` statement like ``#include "moc_<basename>.cpp"`` is found,
the ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in an otherwise empty a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is expected to appear in the
line of the ``<basename>.h(xx)`` header file. ``moc`` is run on the header ``<basename>.h(xx)`` header file. ``moc`` is run on the header
file to generate ``moc_<basename>.cpp`` in the file to generate ``moc_<basename>.cpp`` in the
``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added ``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added
to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
@@ -26,11 +26,12 @@ source files at build time and invoke moc accordingly.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`. * See :prop_tgt:`AUTOGEN_BUILD_DIR`.
* If an ``#include`` statement like ``#include "<basename>.moc"`` is found, * If an ``#include`` statement like ``#include "<basename>.moc"`` is found,
then ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in the current source a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` is expected to appear in the
file and ``moc`` is run on the source file itself. source file and ``moc`` is run on the source file itself.
* Header files that are not included by an ``#include "moc_<basename>.cpp"`` * Header files that are not included by an ``#include "moc_<basename>.cpp"``
statement are nonetheless scanned for ``Q_OBJECT`` or ``Q_GADGET`` macros. statement are nonetheless scanned for a macro out of
:prop_tgt:`AUTOMOC_MACRO_NAMES`.
The resulting ``moc_<basename>.cpp`` files are generated in custom The resulting ``moc_<basename>.cpp`` files are generated in custom
directories and automatically included in a generated directories and automatically included in a generated
``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file, ``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file,
@@ -44,8 +45,9 @@ source files at build time and invoke moc accordingly.
* Additionally, header files with the same base name as a source file, * Additionally, header files with the same base name as a source file,
(like ``<basename>.h``) or ``_p`` appended to the base name (like (like ``<basename>.h``) or ``_p`` appended to the base name (like
``<basename>_p.h``), are parsed for ``Q_OBJECT`` or ``Q_GADGET`` macros, ``<basename>_p.h``), are scanned for a macro out of
and if found, ``moc`` is also executed on those files. :prop_tgt:`AUTOMOC_MACRO_NAMES`, and if found, ``moc``
is also executed on those files.
* ``AUTOMOC`` always checks multiple header alternative extensions, * ``AUTOMOC`` always checks multiple header alternative extensions,
such as ``hpp``, ``hxx``, etc. when searching for headers. such as ``hpp``, ``hxx``, etc. when searching for headers.
@@ -69,9 +71,7 @@ automoc targets together in an IDE, e.g. in MSVS.
The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group
files generated by :prop_tgt:`AUTOMOC` together in an IDE, e.g. in MSVS. files generated by :prop_tgt:`AUTOMOC` together in an IDE, e.g. in MSVS.
The appearance of the strings ``Q_OBJECT`` or ``Q_GADGET`` in a source file Additional macro names to search for can be added to :prop_tgt:`AUTOMOC_MACRO_NAMES`.
determines if it needs to be ``moc`` processed. To search for additional
strings, list them in :prop_tgt:`AUTOMOC_MACRO_NAMES`.
Additional ``moc`` dependency file names can be extracted from source code Additional ``moc`` dependency file names can be extracted from source code
by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`. by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.

View File

@@ -1,20 +1,23 @@
AUTOMOC_MACRO_NAMES AUTOMOC_MACRO_NAMES
------------------- -------------------
Additional macro names used by :prop_tgt:`AUTOMOC` A :ref:`;-list <CMake Language Lists>` list of macro names used by
to determine if a C++ file needs to be processed by ``moc``. :prop_tgt:`AUTOMOC` to determine if a C++ file needs to be processed by ``moc``.
This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON`` This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON``
for this target. for this target.
CMake searches for the strings ``Q_OBJECT`` and ``Q_GADGET`` to When running :prop_tgt:`AUTOMOC`, CMake searches for the strings listed in
determine if a file needs to be processed by ``moc``. :prop_tgt:`AUTOMOC_MACRO_NAMES` in C++ source and header files.
:prop_tgt:`AUTOMOC_MACRO_NAMES` allows to add additional strings to the If any of the strings is found
search list. This is useful for cases where the ``Q_OBJECT`` or ``Q_GADGET``
macro is hidden inside another macro. - as the first non space string on a new line or
- as the first non space string after a ``{`` on a new line,
then the file will be processed by ``moc``.
By default :prop_tgt:`AUTOMOC_MACRO_NAMES` is initialized from By default :prop_tgt:`AUTOMOC_MACRO_NAMES` is initialized from
:variable:`CMAKE_AUTOMOC_MACRO_NAMES`, which is empty by default. :variable:`CMAKE_AUTOMOC_MACRO_NAMES`.
See the :manual:`cmake-qt(7)` manual for more information on using CMake See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt. with Qt.
@@ -25,4 +28,4 @@ In this case the the ``Q_OBJECT`` macro is hidden inside an other macro
called ``CUSTOM_MACRO``. To let CMake know that source files, that contain called ``CUSTOM_MACRO``. To let CMake know that source files, that contain
``CUSTOM_MACRO``, need to be ``moc`` processed, we call:: ``CUSTOM_MACRO``, need to be ``moc`` processed, we call::
set_property(TARGET tgt PROPERTY AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") set_property(TARGET tgt APPEND PROPERTY AUTOMOC_MACRO_NAMES "CUSTOM_MACRO")

View File

@@ -1,14 +1,15 @@
CMAKE_AUTOMOC_MACRO_NAMES CMAKE_AUTOMOC_MACRO_NAMES
---------------------------- ----------------------------
Additional macro names used by :variable:`CMAKE_AUTOMOC` A :ref:`;-list <CMake Language Lists>` list of macro names used by
to determine if a C++ file needs to be processed by ``moc``. :variable:`CMAKE_AUTOMOC` to determine if a C++ file needs to be
processed by ``moc``.
This variable is used to initialize the :prop_tgt:`AUTOMOC_MACRO_NAMES` This variable is used to initialize the :prop_tgt:`AUTOMOC_MACRO_NAMES`
property on all the targets. See that target property for additional property on all the targets. See that target property for additional
information. information.
By default it is empty. The default value is ``Q_OBJECT;Q_GADGET;Q_NAMESPACE``.
Example Example
------- -------
@@ -16,4 +17,4 @@ Let CMake know that source files that contain ``CUSTOM_MACRO`` must be ``moc``
processed as well:: processed as well::
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOMOC_MACRO_NAMES "CUSTOM_MACRO") list(APPEND CMAKE_AUTOMOC_MACRO_NAMES "CUSTOM_MACRO")