/usr/share/qt5/doc/qtdoc/cmake-manual.html is in qt5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- cmake-manual.qdoc -->
<title>CMake Manual | Qt 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td ><a href="index.html">Qt 5.9</a></td><td >CMake Manual</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#getting-started">Getting Started</a></li>
<li class="level2"><a href="#imported-targets">Imported targets</a></li>
<li class="level2"><a href="#using-qt-5-with-cmake-older-than-3-1-0">Using Qt 5 with <code>CMake</code> older than 3.1.0</a></li>
<li class="level2"><a href="#using-qt-5-with-cmake-older-than-2-8-12">Using Qt 5 with <code>CMake</code> older than 2.8.12</a></li>
<li class="level2"><a href="#using-qt-5-with-cmake-older-than-2-8-11">Using Qt 5 with <code>CMake</code> older than 2.8.11</a></li>
<li class="level2"><a href="#using-qt-5-with-cmake-older-than-2-8-9">Using Qt 5 with <code>CMake</code> older than 2.8.9</a></li>
<li class="level1"><a href="#variable-reference">Variable Reference</a></li>
<li class="level2"><a href="#module-variables">Module variables</a></li>
<li class="level2"><a href="#installation-variables">Installation variables</a></li>
<li class="level1"><a href="#macro-reference">Macro Reference</a></li>
<li class="level2"><a href="#qt5core-macros">Qt5Core macros</a></li>
<li class="level2"><a href="#qt5widgets-macros">Qt5Widgets macros</a></li>
<li class="level2"><a href="#qt5dbus-macros">Qt5DBus macros</a></li>
<li class="level2"><a href="#qt5linguisttools-macros">Qt5LinguistTools macros</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">CMake Manual</h1>
<span class="subtitle"></span>
<!-- $$$cmake-manual.html-description -->
<div class="descr"> <a name="details"></a>
<p><code>CMake</code> is a tool that helps simplify the build process for development projects across different platforms. <code>CMake</code> automates the generation of buildsystems such as Makefiles and Visual Studio project files.</p>
<p><code>CMake</code> is a 3rd party tool with its own <a href="http://www.cmake.org/cmake/help/documentation.html">documentation</a>. The rest of this manual details the specifics of how to use Qt 5 with <code>CMake</code>. The minimum version required to use Qt5 is <code>CMake</code> 2.8.3, but 3.1.0 is recommended.</p>
<a name="getting-started"></a>
<h2 id="getting-started">Getting Started</h2>
<p>The first requirement when using <code>CMake</code> is to use <code>find_package</code> to locate the libraries and header files shipped with Qt. These libraries and header files can then be used to build libraries and applications based on Qt.</p>
<p>The recommended way to use Qt libraries and headers with <code>CMake</code> 2.8.11 is to use the <code>target_link_libraries</code> command. In <code>CMake</code> 2.8.11 and later versions, this command automatically adds appropriate include directories, compile definitions, the position-independent-code flag, and links to the qtmain.lib library on Windows.</p>
<p>To build a helloworld GUI executable, typical usage would be:</p>
<pre class="cpp">
cmake_minimum_required(VERSION 2.8.11)
project(testproject)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Tell CMake to create the helloworld executable
add_executable(helloworld WIN32 main.cpp)
# Use the Widgets module from Qt 5.
target_link_libraries(helloworld Qt5::Widgets)
</pre>
<p>Note that setting the minimum required CMake version to 2.8.11 is required for automatic linking to the qtmain.lib library on Windows.</p>
<p>In order for <code>find_package</code> to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5<Module>_DIR must be set in the <code>CMake</code> cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use <code>CMake</code> is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.</p>
<p>The CMAKE_AUTOMOC setting runs moc automatically when required. For more on this feature see the <a href="http://www.cmake.org/cmake/help/v2.8.11/cmake.html#prop_tgt:AUTOMOC">CMake AUTOMOC documentation</a></p>
<a name="imported-targets"></a>
<h3 >Imported targets</h3>
<p>Imported targets are created for each Qt module. Imported target names should be preferred instead of using a variable like Qt5<Module><a href="windows-requirements.html#libraries">_LIBRARIES</a> in CMake commands such as <code>target_link_libraries</code>. The actual path to the library can be obtained using the <a href="http://www.cmake.org/cmake/help/v2.8.11/cmake.html#prop_tgt:LOCATION">LOCATION property</a>:</p>
<pre class="cpp">
find_package(Qt5Core)
get_target_property(QtCore_location Qt5::Core LOCATION)
</pre>
<p>Note however that it is rare to require the full location to the library in <code>CMake</code> code. Most <code>CMake</code> APIs are aware of imported targets and can automatically use them instead of the full path.</p>
<p>Each module in Qt 5 has a library target with the naming convention Qt5::<Module> which can be used for this purpose.</p>
<p>Imported targets are created with the configurations Qt was configured with. That is, if Qt was configured with the -debug switch, an imported target with the configuration DEBUG will be created. If Qt was configured with the -release switch an imported target with the configuration RELEASE will be created. If Qt was configured with the -debug-and-release switch (the default on windows), then imported targets will be created with both RELEASE and DEBUG configurations.</p>
<p>If your project has custom CMake build configurations, it may be necessary to set a mapping from your custom configuration to either the debug or release Qt configuration.</p>
<pre class="cpp">
find_package(Qt5Core)
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")
# set up a mapping so that the Release configuration for the Qt imported target is
# used in the COVERAGE CMake configuration.
set_target_properties(Qt5::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")
</pre>
<p>Plugins are also available as <code>IMPORTED</code> targets in CMake. The <a href="../qtnetwork/qtnetwork-index.html">Qt Network</a>, <a href="../qtsql/qtsql-index.html">Qt SQL</a>, <a href="../qtgui/qtgui-index.html">Qt GUI</a>, and <a href="../qtwidgets/qtwidgets-index.html">Qt Widgets</a> modules have plugins associated. They provide a list of plugins in the <code>Qt5</code><i><Module></i><code>_PLUGINS</code> variable.</p>
<pre class="cpp">
foreach(plugin ${Qt5Network_PLUGINS})
get_target_property(_loc ${plugin} LOCATION)
message("Plugin ${plugin} is at location ${_loc}")
endforeach()
</pre>
<a name="using-qt-5-with-cmake-older-than-3-1-0"></a>
<h3 >Using Qt 5 with <code>CMake</code> older than 3.1.0</h3>
<p>Qt 5.7 requires C++11 support. <code>CMake</code> starting from version 3.1.0 implicitly adds the minimum required compiler flags (e.g. <code>-std=gnu++11</code>) to the Qt5 module targets. If you use <code>CMake</code> version older than 3.1.0, you need to add the needed <code>-std=...</code> to the targets linking against Qt5 modules yourself.</p>
<p>If you use Qt 5.7 and a <code>CMake</code> version above 3.1.0, plus require a more recent C++ standard version, use the CMake way of selecting the standard version, or specify features required and let CMake compute the flags. Example:</p>
<pre class="cpp">
set(CMAKE_CXX_STANDARD 14)
</pre>
<p>Also see: <a href="https://cmake.org/cmake/help/v3.1/manual/cmake-compile-features.7.html">CMake cmake-compile-features Documentation</a></p>
<a name="using-qt-5-with-cmake-older-than-2-8-12"></a>
<h3 >Using Qt 5 with <code>CMake</code> older than 2.8.12</h3>
<p>It is also necessary when using an older <code>CMake</code> to add Qt5<Module>_EXECUTABLE_COMPILE_FLAGS to the CMAKE_CXX_FLAGS so that the -fPIC flags are added to the compile flags if necessary (as is the default with Qt 5).</p>
<a name="using-qt-5-with-cmake-older-than-2-8-11"></a>
<h3 >Using Qt 5 with <code>CMake</code> older than 2.8.11</h3>
<p>The recommended way to use Qt libraries and headers with <code>CMake</code> prior to 2.8.11 is to use the <code>qt5_use_modules</code> macro.</p>
<p>Note that it is necessary to use <code>find_package</code> to find a Qt module before using the macro. See the documentation for the <a href="http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package">CMake find_package Documentation</a> command for the full options it supports.</p>
<p>The <code>qt5_use_modules</code> macro encapsulates all of the variable usage required to use a Qt module. It automatically finds the modules given to it on the command line if they have not already been found.</p>
<pre class="cpp">
find_package(Qt5Widgets)
add_executable(helloworld WIN32 main.cpp)
qt5_use_modules(helloworld Widgets)
</pre>
<a name="using-qt-5-with-cmake-older-than-2-8-9"></a>
<h3 >Using Qt 5 with <code>CMake</code> older than 2.8.9</h3>
<p>If using <code>CMake</code> older than 2.8.9, the <code>qt5_use_modules</code> macro is not available. Attempting to use it will result in an error.</p>
<p>To use Qt 5 with versions of <code>CMake</code> older than 2.8.9, it is necessary to use the <code>target_link_libraries</code>, <code>include_directories</code>, and <code>add_definitions</code> commands, and to manually specify moc requirements with either <code>qt5_generate_moc</code> or <code>qt5_wrap_cpp</code>:</p>
<pre class="cpp">
cmake_minimum_required(VERSION 2.8.3)
project(testproject)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Widgets_INCLUDE_DIRS})
# Use the compile definitions defined in the Qt 5 Widgets module
add_definitions(${Qt5Widgets_DEFINITIONS})
# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
qt5_generate_moc(main.cpp main.moc)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp main.moc)
#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(helloworld Qt5::Widgets)
</pre>
<a name="variable-reference"></a>
<h2 id="variable-reference">Variable Reference</h2>
<a name="module-variables"></a>
<h3 >Module variables</h3>
<p>The result of a <code>find_package</code> call is that imported targets will be created for use with <code>target_link_libraries</code>, some variables will be populated with information required to configure the build, and macros will be made available for use. The name of the imported target for each module matches the name of the module with a prefix of 'Qt5::', for example Qt5::Widgets. All of the package-specific variables have a consistent name with a prefix of the name of the package. For example, <code>find_package</code>(Qt5Widgets) will make the following variables available if successfully found:</p>
<ul>
<li>Qt5Widgets_VERSION String describing the version of the module.</li>
<li>Qt5Widgets_VERSION_STRING Same as Qt5Widgets_VERSION. Deprecated, use Qt5Widgets_VERSION instead.</li>
<li>Qt5Widgets_LIBRARIES List of libraries for use with the target_link_libraries command.</li>
<li>Qt5Widgets_INCLUDE_DIRS List of directories for use with the include_directories command.</li>
<li>Qt5Widgets_DEFINITIONS List of definitions for use with add_definitions.</li>
<li>Qt5Widgets_COMPILE_DEFINITIONS List of definitions for use with the COMPILE_DEFINITIONS target property.</li>
<li>Qt5Widgets_FOUND Boolean describing whether the module was found successfully.</li>
<li>Qt5Widgets_EXECUTABLE_COMPILE_FLAGS String of flags to be used when building executables.</li>
</ul>
<p>Equivalents of those variables will be available for all packages found with a <code>find_package</code> call. Note that the variables are case-sensitive.</p>
<a name="installation-variables"></a>
<h3 >Installation variables</h3>
<p>Additionally, several other variables are available which do not relate to a particular package, but to the Qt installation itself.</p>
<ul>
<li>QT_VISIBILITY_AVAILABLE Boolean describing whether Qt was built with hidden visibility.</li>
<li>QT_LIBINFIX String containing the infix used in library names.</li>
</ul>
<a name="macro-reference"></a>
<h2 id="macro-reference">Macro Reference</h2>
<a name="qt5core-macros"></a>
<h3 >Qt5Core macros</h3>
<p>Macros available when Qt5Core is found.</p>
<div class="table"><table class="generic">
<thead><tr class="qt-style"><th >Macro</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >qt5_wrap_cpp(outfiles inputfile ... OPTIONS ...)</td><td >Create moc code from a list of files containing Qt class with the <a href="../qtcore/qobject.html#Q_OBJECT">Q_OBJECT</a> declaration. Per-directory preprocessor definitions are also added. Options may be given to moc, such as those found when executing "moc -help".</td></tr>
<tr valign="top" class="even"><td >qt5_add_resources(outfiles inputfile ... OPTIONS ...)</td><td >Create code from a list of Qt resource files. Options may be given to rcc, such as those found when executing "rcc -help".</td></tr>
<tr valign="top" class="odd"><td >qt5_add_binary_resources(target inputfile ... OPTIONS ... DESTINATION ...)</td><td >Create an RCC file from a list of Qt resource files. Options may be given to rcc, such as those found when executing "rcc -help". A destination may be given to use a different filename or path for the RCC file.</td></tr>
<tr valign="top" class="even"><td >qt5_generate_moc(inputfile outputfile )</td><td >Creates a rule to run moc on infile and create outfile. Use this if for some reason QT5_WRAP_CPP() isn't appropriate, e.g. because you need a custom filename for the moc file or something similar.</td></tr>
<tr valign="top" class="odd"><td >qt5_use_modules(target [LINK_PUBLIC|LINK_PRIVATE] module ... )</td><td >Indicates that the target uses the named Qt 5 modules. The target will be linked to the specified modules, use the include directories installed by those modules, use the COMPILE_DEFINITIONS set by those modules, and use the COMPILE_FLAGS set by the modules. The LINK_PRIVATE or LINK_PUBLIC specifiers can optionally be specified. If LINK_PRIVATE is specified then the modules are not made part of the link interface of the target. See the documentation for <a href="http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:target_link_libraries">target_link_libraries</a> for more information.<p>Note that this macro is only available if using <code>CMake</code> 2.8.9 or later. This macro is obsolete. Use target_link_libraries with IMPORTED targets instead.</p>
</td></tr>
</table></div>
<a name="qt5widgets-macros"></a>
<h3 >Qt5Widgets macros</h3>
<p>Macros available when Qt5Widgets is found.</p>
<div class="table"><table class="generic">
<thead><tr class="qt-style"><th >Macro</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >qt5_wrap_ui(outfiles inputfile ... OPTIONS ...)</td><td >Create code from a list of Qt designer ui files. Options may be given to uic, such as those found when executing "uic -help"</td></tr>
</table></div>
<a name="qt5dbus-macros"></a>
<h3 >Qt5DBus macros</h3>
<p>Macros available when Qt5DBus is found.</p>
<div class="table"><table class="generic">
<thead><tr class="qt-style"><th >Macro</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >qt5_add_dbus_interface(outfiles interface basename)</td><td >Create the interface header and implementation files with the given basename from the given interface xml file and add it to the list of sources</td></tr>
<tr valign="top" class="even"><td >qt5_add_dbus_interfaces(outfiles inputfile ... )</td><td >Create the interface header and implementation files for all listed interface xml files the name will be automatically determined from the name of the xml file</td></tr>
<tr valign="top" class="odd"><td >qt5_add_dbus_adaptor(outfiles xmlfile parentheader parentclassname [basename] [classname])</td><td >Create a dbus adaptor (header and implementation file) from the xml file describing the interface, and add it to the list of sources. The adaptor forwards the calls to a parent class, defined in parentheader and named parentclassname. The name of the generated files will be <basename>adaptor.{cpp,h} where basename defaults to the basename of the xml file. If <classname> is provided, then it will be used as the classname of the adaptor itself.</td></tr>
<tr valign="top" class="even"><td >qt5_generate_dbus_interface( header [interfacename] OPTIONS ...)</td><td >Generate the xml interface file from the given header. If the optional argument interfacename is omitted, the name of the interface file is constructed from the basename of the header with the suffix .xml appended. Options may be given to qdbuscpp2xml, such as those found when executing "qdbuscpp2xml --help"</td></tr>
</table></div>
<a name="qt5linguisttools-macros"></a>
<h3 >Qt5LinguistTools macros</h3>
<p>Macros available when Qt5LinguistTools is found.</p>
<div class="table"><table class="generic">
<thead><tr class="qt-style"><th >Macro</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >qt5_create_translation( qm_files directories ... sources ... ts_files ... OPTIONS ...)</td><td >Out: qm_files In: Directories sources ts_files Options: flags to pass to lupdate, such as -extensions to specify Extensions for a directory scan. Generates commands to create .ts (via lupdate) and .qm (via lrelease) - files from directories and/or sources. The ts files are created and/or updated in the source tree (unless given with full paths). The qm files are generated in the build tree. Updating the translations can be done by adding the qm_files to the source list of your library/executable, so they are always updated, or by adding a custom target to control when they get updated/generated.</td></tr>
<tr valign="top" class="even"><td >qt5_add_translation( qm_files ts_files ... )</td><td >Out: qm_files In: ts_files Generates commands to create .qm from .ts - files. The generated filenames can be found in qm_files. The ts_files must exist and are not updated in any way.</td></tr>
</table></div>
</div>
<!-- @@@cmake-manual.html -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|