Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 16

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qmake-manual.qdoc -->
  <title>Advanced Usage | qmake Manual</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 >Qt 5.9</td><td ><a href="qmake-manual.html">qmake Manual</a></td><td >Advanced Usage</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="qmake-language.html" />
  <link rel="next" href="qmake-precompiledheaders.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmake-language.html">qmake Language</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qmake-precompiledheaders.html">Using Precompiled Headers</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#adding-new-configuration-features">Adding New Configuration Features</a></li>
<li class="level1"><a href="#installing-files">Installing Files</a></li>
<li class="level1"><a href="#adding-custom-targets">Adding Custom Targets</a></li>
<li class="level1"><a href="#adding-compilers">Adding Compilers</a></li>
<li class="level1"><a href="#library-dependencies">Library Dependencies</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Advanced Usage</h1>
<span class="subtitle"></span>
<!-- $$$qmake-advanced-usage.html-description -->
<div class="descr"> <a name="details"></a>
<a name="adding-new-configuration-features"></a>
<h2 id="adding-new-configuration-features">Adding New Configuration Features</h2>
<p>qmake lets you create your own <code>features</code> that can be included in project files by adding their names to the list of values specified by the <a href="qmake-variable-reference.html#config">CONFIG</a> variable. Features are collections of custom functions and definitions in <code>.prf</code> files that can reside in one of many standard directories. The locations of these directories are defined in a number of places, and qmake checks each of them in the following order when it looks for <code>.prf</code> files:</p>
<ol class="1" type="1"><li>In a directory listed in the <code>QMAKEFEATURES</code> environment variable that contains a list of directories delimited by the platform's path list separator (colon for Unix, semicolon for Windows).</li>
<li>In a directory listed in the <code>QMAKEFEATURES</code> property variable that contains a list of directories delimited by the platform's path list separator.</li>
<li>In a features directory residing within a <code>mkspecs</code> directory. <code>mkspecs</code> directories can be located beneath any of the directories listed in the <code>QMAKEPATH</code> environment variable that contains a list of directories delimited by the platform's path list separator. For example: <code>$QMAKEPATH/mkspecs/&lt;features&gt;</code>.</li>
<li>In a features directory residing beneath the directory provided by the <a href="qmake-environment-reference.html#qmakespec">QMAKESPEC</a> environment variable. For example: <code>$QMAKESPEC/&lt;features&gt;</code>.</li>
<li>In a features directory residing in the <code>data_install/mkspecs</code> directory. For example: <code>data_install/mkspecs/&lt;features&gt;</code>.</li>
<li>In a features directory that exists as a sibling of the directory specified by the <code>QMAKESPEC</code> environment variable. For example: <code>$QMAKESPEC/../&lt;features&gt;</code>.</li>
</ol>
<p>The following features directories are searched for features files:</p>
<ol class="1" type="1"><li><code>features/unix</code>, <code>features/win32</code>, or <code>features/macx</code>, depending on the platform in use</li>
<li><code>features/</code></li>
</ol>
<p>For example, consider the following assignment in a project file:</p>
<pre class="cpp">

  CONFIG += myfeatures

</pre>
<p>With this addition to the <code>CONFIG</code> variable, qmake will search the locations listed above for the <code>myfeatures.prf</code> file after it has finished parsing your project file. On Unix systems, it will look for the following file:</p>
<ol class="1" type="1"><li><code>$QMAKEFEATURES/myfeatures.prf</code> (for each directory listed in the <code>QMAKEFEATURES</code> environment variable)</li>
<li><code>$$QMAKEFEATURES/myfeatures.prf</code> (for each directory listed in the <code>QMAKEFEATURES</code> property variable)</li>
<li><code>myfeatures.prf</code> (in the project's root directory)</li>
<li><code>$QMAKEPATH/mkspecs/features/unix/myfeatures.prf</code> and <code>$QMAKEPATH/mkspecs/features/myfeatures.prf</code> (for each directory listed in the <code>QMAKEPATH</code> environment variable)</li>
<li><code>$QMAKESPEC/features/unix/myfeatures.prf</code> and <code>$QMAKESPEC/features/myfeatures.prf</code></li>
<li><code>data_install/mkspecs/features/unix/myfeatures.prf</code> and <code>data_install/mkspecs/features/myfeatures.prf</code></li>
<li><code>$QMAKESPEC/../features/unix/myfeatures.prf</code> and <code>$QMAKESPEC/../features/myfeatures.prf</code></li>
</ol>
<p><b>Note: </b>The <code>.prf</code> files must have names in lower case.</p><a name="installing-files"></a>
<h2 id="installing-files">Installing Files</h2>
<p>It is common on Unix to also use the build tool to install applications and libraries; for example, by invoking <code>make install</code>. For this reason, qmake has the concept of an <code>install set</code>, an object which contains instructions about the way a part of a project is to be installed. For example, a collection of documentation files can be described in the following way:</p>
<pre class="cpp">

  documentation.path = /usr/local/program/doc
  documentation.files = docs/*

</pre>
<p>The <code>path</code> member informs qmake that the files should be installed in <code>/usr/local/program/doc</code> (the path member), and the <code>files</code> member specifies the files that should be copied to the installation directory. In this case, everything in the <code>docs</code> directory will be copied to <code>/usr/local/program/doc</code>.</p>
<p>Once an install set has been fully described, you can append it to the install list with a line like this:</p>
<pre class="cpp">

  INSTALLS += documentation

</pre>
<p>qmake will ensure that the specified files are copied to the installation directory. If you require more control over this process, you can also provide a definition for the <code>extra</code> member of the object. For example, the following line tells qmake to execute a series of commands for this install set:</p>
<pre class="cpp">

  unix:documentation.extra = create_docs; mv master.doc toc.doc

</pre>
<p>The <code>unix</code> <a href="qmake-language.html#scopes-and-conditions">scope</a> ensures that these particular commands are only executed on Unix platforms. Appropriate commands for other platforms can be defined using other scope rules.</p>
<p>Commands specified in the <code>extra</code> member are executed before the instructions in the other members of the object are performed.</p>
<p>If you append a built-in install set to the <code>INSTALLS</code> variable and do not specify <code>files</code> or <code>extra</code> members, qmake will decide what needs to be copied for you. Currently, the <code>target</code> and <code>dlltarget</code> install sets are supported. For example:</p>
<pre class="cpp">

  target.path = /usr/local/myprogram
  INSTALLS += target

</pre>
<p>In the above lines, qmake knows what needs to be copied, and will handle the installation process automatically.</p>
<a name="adding-custom-targets"></a>
<h2 id="adding-custom-targets">Adding Custom Targets</h2>
<p>qmake tries to do everything expected of a cross-platform build tool. This is often less than ideal when you really need to run special platform-dependent commands. This can be achieved with specific instructions to the different qmake backends.</p>
<p>Customization of the Makefile output is performed through an object-style API as found in other places in qmake. Objects are defined automatically by specifying their <i>members</i>. For example:</p>
<pre class="cpp">

  mytarget.target = .buildfile
  mytarget.commands = touch $$mytarget.target
  mytarget.depends = mytarget2

  mytarget2.commands = @echo Building $$mytarget.target

</pre>
<p>The definitions above define a qmake target called <code>mytarget</code>, containing a Makefile target called <code>.buildfile</code> which in turn is generated with the <a href="qmake-test-function-reference.html#touchfunction">touch()</a> function. Finally, the <code>.depends</code> member specifies that <code>mytarget</code> depends on <code>mytarget2</code>, another target that is defined afterwards. <code>mytarget2</code> is a dummy target. It is only defined to echo some text to the console.</p>
<p>The final step is to use the <code>QMAKE_EXTRA_TARGETS</code> variable to instruct qmake that this object is a target to be built:</p>
<pre class="cpp">

  QMAKE_EXTRA_TARGETS += mytarget mytarget2

</pre>
<p>This is all you need to do to actually build custom targets. Of course, you may want to tie one of these targets to the <a href="qmake-variable-reference.html#target">qmake build target</a>. To do this, you simply need to include your Makefile target in the list of <a href="qmake-variable-reference.html#pre-targetdeps">PRE_TARGETDEPS</a>.</p>
<p>Custom target specifications support the following members:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Member</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >commands</td><td >The commands for generating the custom build target.</td></tr>
<tr valign="top" class="even"><td >CONFIG</td><td >Specific configuration options for the custom build target. Can be set to <code>recursive</code> to indicate that rules should be created in the Makefile to call the relevant target inside the sub-target specific Makefile. This member defaults to creating an entry for each of the sub-targets.</td></tr>
<tr valign="top" class="odd"><td >depends</td><td >The existing build targets that the custom build target depends on.</td></tr>
<tr valign="top" class="even"><td >recurse</td><td >Specifies which sub-targets should be used when creating the rules in the Makefile to call in the sub-target specific Makefile. This member is used only when <code>recursive</code> is set in <code>CONFIG</code>. Typical values are &quot;Debug&quot; and &quot;Release&quot;.</td></tr>
<tr valign="top" class="odd"><td >recurse_target</td><td >Specifies the target that should be built via the sub-target Makefile for the rule in the Makefile. This member adds something like <code>$(MAKE) -f Makefile.[subtarget] [recurse_target]</code>. This member is used only when <code>recursive</code> is set in <code>CONFIG</code>.</td></tr>
<tr valign="top" class="even"><td >target</td><td >The name of the custom build target.</td></tr>
</table></div>
<a name="adding-compilers"></a>
<h2 id="adding-compilers">Adding Compilers</h2>
<p>It is possible to customize qmake to support new compilers and preprocessors:</p>
<pre class="cpp">

  new_moc.output  = moc_${QMAKE_FILE_BASE}.cpp
  new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
  new_moc.depend_command = g++ -E -M ${QMAKE_FILE_NAME} | sed &quot;s,^.*: ,,&quot;
  new_moc.input = NEW_HEADERS
  QMAKE_EXTRA_COMPILERS += new_moc

</pre>
<p>With the above definitions, you can use a drop-in replacement for moc if one is available. The command is executed on all arguments given to the <code>NEW_HEADERS</code> variable (from the <code>input</code> member), and the result is written to the file defined by the <code>output</code> member. This file is added to the other source files in the project. Additionally, qmake will execute <code>depend_command</code> to generate dependency information, and place this information in the project as well.</p>
<p>Custom compiler specifications support the following members:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Member</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >commands</td><td >The commands used for for generating the output from the input.</td></tr>
<tr valign="top" class="even"><td >CONFIG</td><td >Specific configuration options for the custom compiler. See the CONFIG table for details.</td></tr>
<tr valign="top" class="odd"><td >depend_command</td><td >Specifies a command used to generate the list of dependencies for the output.</td></tr>
<tr valign="top" class="even"><td >dependency_type</td><td >Specifies the type of file the output is. If it is a known type (such as TYPE_C, TYPE_UI, TYPE_QRC), it is handled as one of those type of files.</td></tr>
<tr valign="top" class="odd"><td >depends</td><td >Specifies the dependencies of the output file.</td></tr>
<tr valign="top" class="even"><td >input</td><td >The variable that specifies the files that should be processed with the custom compiler.</td></tr>
<tr valign="top" class="odd"><td >name</td><td >A description of what the custom compiler is doing. This is only used in some backends.</td></tr>
<tr valign="top" class="even"><td >output</td><td >The filename that is created from the custom compiler.</td></tr>
<tr valign="top" class="odd"><td >output_function</td><td >Specifies a custom qmake function that is used to specify the filename to be created.</td></tr>
<tr valign="top" class="even"><td >variables</td><td >Indicates that the variables specified here are replaced with $(QMAKE_COMP_VARNAME) when referred to in the pro file as $(VARNAME).</td></tr>
<tr valign="top" class="odd"><td >variable_out</td><td >The variable that the files created from the output should be added to.</td></tr>
</table></div>
<p>The CONFIG member supports the following options:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Option</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td >combine</td><td >Indicates that all of the input files are combined into a single output file.</td></tr>
<tr valign="top" class="even"><td >target_predeps</td><td >Indicates that the output should be added to the list of <a href="qmake-variable-reference.html#pre-targetdeps">PRE_TARGETDEPS</a>.</td></tr>
<tr valign="top" class="odd"><td >explicit_dependencies</td><td >The dependencies for the output only get generated from the depends member and from nowhere else.</td></tr>
<tr valign="top" class="even"><td >no_link</td><td >Indicates that the output should not be added to the list of objects to be linked in.</td></tr>
</table></div>
<a name="libdepend"></a><a name="library-dependencies"></a>
<h2 id="library-dependencies">Library Dependencies</h2>
<p>Often when linking against a library, qmake relies on the underlying platform to know what other libraries this library links against, and lets the platform pull them in. In many cases, however, this is not sufficient. For example, when statically linking a library, no other libraries are linked to, and therefore no dependencies to those libraries are created. However, an application that later links against this library will need to know where to find the symbols that the static library will require. qmake attempts to keep track of the dependencies of a library, where appropriate, if you explicitly enable tracking.</p>
<p>The first step is to enable dependency tracking in the library itself. To do this you must tell qmake to save information about the library:</p>
<pre class="cpp">

  CONFIG += create_prl

</pre>
<p>This is only relevant to the <code>lib</code> template, and will be ignored for all others. When this option is enabled, qmake will create a file ending in .prl which will save some meta-information about the library. This metafile is just like an ordinary project file, but only contains internal variable declarations. When installing this library, by specifying it as a target in an <a href="qmake-variable-reference.html#installs">INSTALLS</a> declaration, qmake will automatically copy the .prl file to the installation path.</p>
<p>The second step in this process is to enable reading of this meta information in the applications that use the static library:</p>
<pre class="cpp">

  CONFIG += link_prl

</pre>
<p>When this is enabled, qmake will process all libraries linked to by the application and find their meta-information. qmake will use this to determine the relevant linking information, specifically adding values to the application project file's list of <a href="qmake-variable-reference.html#defines">DEFINES</a> as well as <a href="qmake-variable-reference.html#libs">LIBS</a>. Once qmake has processed this file, it will then look through the newly introduced libraries in the <code>LIBS</code> variable, and find their dependent .prl files, continuing until all libraries have been resolved. At this point, the Makefile is created as usual, and the libraries are linked explicitly against the application.</p>
<p>The .prl files should be created by qmake only, and should not be transferred between operating systems, as they may contain platform-dependent information.</p>
</div>
<!-- @@@qmake-advanced-usage.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmake-language.html">qmake Language</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qmake-precompiledheaders.html">Using Precompiled Headers</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>