components/cmake/files/man7/cmake-qt.7
author April Chin <april.chin@oracle.com>
Wed, 11 Nov 2015 12:06:59 -0800
changeset 5081 198d4a3e4b73
permissions -rw-r--r--
21834219 update cmake to 3.3.2 22121918 enable system-test target for cmake

.\" Man page generated from reStructuredText.
.
.TH "CMAKE-QT" "7" "October 14, 2015" "3.3.2" "CMake"
.SH NAME
cmake-qt \- CMake Qt Features Reference
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH INTRODUCTION
.sp
CMake can find and use Qt 4 and Qt 5 libraries.  The Qt 4 libraries are found
by the \fBFindQt4\fP find\-module shipped with CMake, whereas the
Qt 5 libraries are found using "Config\-file Packages" shipped with Qt 5. See
\fBcmake\-packages(7)\fP for more information about CMake packages, and
see \fI\%the Qt cmake manual\fP
for your Qt version.
.sp
Qt 4 and Qt 5 may be used together in the same
\fBCMake buildsystem\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

project(Qt4And5)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Widgets REQUIRED)
add_executable(publisher publisher.cpp)
target_link_libraries(publisher Qt5::Widgets Qt5::DBus)

find_package(Qt4 REQUIRED)
add_executable(subscriber subscriber.cpp)
target_link_libraries(subscriber Qt4::QtGui Qt4::QtDBus)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
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.
.SH QT BUILD TOOLS
.sp
Qt relies on some bundled tools for code generation, such as \fBmoc\fP for
meta\-object code generation, \fBuic\fP for widget layout and population,
and \fBrcc\fP for virtual filesystem content generation.  These tools may be
automatically invoked by \fBcmake(1)\fP if the appropriate conditions
are met.  The automatic tool invocation may be used with both Qt 4 and Qt 5.
.sp
The tools are executed as part of a synthesized custom target generated by
CMake.  Target dependencies may be added to that custom target by adding them
to the \fBAUTOGEN_TARGET_DEPENDS\fP target property.
.SS AUTOMOC
.sp
The \fBAUTOMOC\fP target property controls whether \fBcmake(1)\fP
inspects the C++ files in the target to determine if they require \fBmoc\fP to
be run, and to create rules to execute \fBmoc\fP at the appropriate time.
.sp
If a \fBQ_OBJECT\fP or \fBQ_GADGET\fP macro is found in a header file, \fBmoc\fP
will be run on the file.  The result will be put into a file named according
to \fBmoc_<basename>.cpp\fP\&.  If the macro is found in a C++ implementation
file, the moc output will be put into a file named according to
\fB<basename>.moc\fP, following the Qt conventions.  The \fBmoc file\fP may be
included by the user in the C++ implementation file with a preprocessor
\fB#include\fP\&.  If it is not so included, it will be added to a separate file
which is compiled into the target.
.sp
The \fBmoc\fP command line will consume the \fBCOMPILE_DEFINITIONS\fP and
\fBINCLUDE_DIRECTORIES\fP target properties from the target it is being
invoked for, and for the appropriate build configuration.
.sp
Generated \fBmoc_*.cpp\fP and \fB*.moc\fP files are placed in the build directory
so it is convenient to set the \fBCMAKE_INCLUDE_CURRENT_DIR\fP
variable.  The \fBAUTOMOC\fP target property may be pre\-set for all
following targets by setting the \fBCMAKE_AUTOMOC\fP variable.  The
\fBAUTOMOC_MOC_OPTIONS\fP target property may be populated to set
options to pass to \fBmoc\fP\&. The \fBCMAKE_AUTOMOC_MOC_OPTIONS\fP
variable may be populated to pre\-set the options for all following targets.
.SS AUTOUIC
.sp
The \fBAUTOUIC\fP target property controls whether \fBcmake(1)\fP
inspects the C++ files in the target to determine if they require \fBuic\fP to
be run, and to create rules to execute \fBuic\fP at the appropriate time.
.sp
If a preprocessor \fB#include\fP directive is found which matches
\fBui_<basename>.h\fP, and a \fB<basename>.ui\fP file exists, then \fBuic\fP will
be executed to generate the appropriate file.
.sp
Generated \fBui_*.h\fP files are placed in the build directory so it is
convenient to set the \fBCMAKE_INCLUDE_CURRENT_DIR\fP variable.  The
\fBAUTOUIC\fP target property may be pre\-set for all following targets
by setting the \fBCMAKE_AUTOUIC\fP variable.  The
\fBAUTOUIC_OPTIONS\fP target property may be populated to set options
to pass to \fBuic\fP\&.  The \fBCMAKE_AUTOUIC_OPTIONS\fP variable may be
populated to pre\-set the options for all following targets.  The
\fBAUTOUIC_OPTIONS\fP source file property may be set on the
\fB<basename>.ui\fP file to set particular options for the file.  This
overrides options from the \fBAUTOUIC_OPTIONS\fP target property.
.sp
A target may populate the \fBINTERFACE_AUTOUIC_OPTIONS\fP target
property with options that should be used when invoking \fBuic\fP\&.  This must be
consistent with the \fBAUTOUIC_OPTIONS\fP target property content of the
depender target.  The \fBCMAKE_DEBUG_TARGET_PROPERTIES\fP variable may
be used to track the origin target of such
\fBINTERFACE_AUTOUIC_OPTIONS\fP\&.  This means that a library which
provides an alternative translation system for Qt may specify options which
should be used when running \fBuic\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
add_library(KI18n klocalizedstring.cpp)
target_link_libraries(KI18n Qt5::Core)

# KI18n uses the tr2i18n() function instead of tr().  That function is
# declared in the klocalizedstring.h header.
set(autouic_options
  \-tr tr2i18n
  \-include klocalizedstring.h
)

set_property(TARGET KI18n APPEND PROPERTY
  INTERFACE_AUTOUIC_OPTIONS ${autouic_options}
)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
A consuming project linking to the target exported from upstream automatically
uses appropriate options when \fBuic\fP is run by \fBAUTOUIC\fP, as a
result of linking with the \fBIMPORTED\fP target:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
set(CMAKE_AUTOUIC ON)
# Uses a libwidget.ui file:
add_library(LibWidget libwidget.cpp)
target_link_libraries(LibWidget
  KF5::KI18n
  Qt5::Widgets
)
.ft P
.fi
.UNINDENT
.UNINDENT
.SS AUTORCC
.sp
The \fBAUTORCC\fP target property controls whether \fBcmake(1)\fP
creates rules to execute \fBrcc\fP at the appropriate time on source files
which have the suffix \fB\&.qrc\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
add_executable(myexe main.cpp resource_file.qrc)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The \fBAUTORCC\fP target property may be pre\-set for all following targets
by setting the \fBCMAKE_AUTORCC\fP variable.  The
\fBAUTORCC_OPTIONS\fP target property may be populated to set options
to pass to \fBrcc\fP\&.  The \fBCMAKE_AUTORCC_OPTIONS\fP variable may be
populated to pre\-set the options for all following targets.  The
\fBAUTORCC_OPTIONS\fP source file property may be set on the
\fB<name>.qrc\fP file to set particular options for the file.  This
overrides options from the \fBAUTORCC_OPTIONS\fP target property.
.SH QTMAIN.LIB ON WINDOWS
.sp
The Qt 4 and 5 \fBIMPORTED\fP targets for the QtGui libraries specify
that the qtmain.lib static library shipped with Qt will be linked by all
dependent executables which have the \fBWIN32_EXECUTABLE\fP enabled.
.sp
To disable this behavior, enable the \fBQt5_NO_LINK_QTMAIN\fP target property for
Qt 5 based targets or \fBQT4_NO_LINK_QTMAIN\fP target property for Qt 4 based
targets.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe Qt4::QtGui)

add_executable(myexe_no_qtmain WIN32 main_no_qtmain.cpp)
set_property(TARGET main_no_qtmain PROPERTY QT4_NO_LINK_QTMAIN ON)
target_link_libraries(main_no_qtmain Qt4::QtGui)
.ft P
.fi
.UNINDENT
.UNINDENT
.SH COPYRIGHT
2000-2015 Kitware, Inc.
.\" Generated by docutils manpage writer.
.