Sophie

Sophie

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

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>Creating Project Files | 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 >Creating Project Files</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-tutorial.html" />
  <link rel="next" href="qmake-common-projects.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qmake-tutorial.html">Getting Started</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qmake-common-projects.html">Building Common Project Types</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#project-file-elements">Project File Elements</a></li>
<li class="level2"><a href="#variables">Variables</a></li>
<li class="level2"><a href="#comments">Comments</a></li>
<li class="level2"><a href="#built-in-functions-and-control-flow">Built-in Functions and Control Flow</a></li>
<li class="level1"><a href="#project-templates">Project Templates</a></li>
<li class="level1"><a href="#general-configuration">General Configuration</a></li>
<li class="level1"><a href="#declaring-qt-libraries">Declaring Qt Libraries</a></li>
<li class="level1"><a href="#configuration-features">Configuration Features</a></li>
<li class="level1"><a href="#declaring-other-libraries">Declaring Other Libraries</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Creating Project Files</h1>
<span class="subtitle"></span>
<!-- $$$qmake-project-files.html-description -->
<div class="descr"> <a name="details"></a>
<p>Project files contain all the information required by qmake to build your application, library, or plugin. Generally, you use a series of declarations to specify the resources in the project, but support for simple programming constructs enables you to describe different build processes for different platforms and environments.</p>
<a name="project-file-elements"></a>
<h2 id="project-file-elements">Project File Elements</h2>
<p>The project file format used by qmake can be used to support both simple and fairly complex build systems. Simple project files use a straightforward declarative style, defining standard variables to indicate the source and header files that are used in the project. Complex projects may use control flow structures to fine-tune the build process.</p>
<p>The following sections describe the different types of elements used in project files.</p>
<a name="projectfileelementsvariables"></a><a name="variables"></a>
<h3 >Variables</h3>
<p>In a project file, variables are used to hold lists of strings. In the simplest projects, these variables inform qmake about the configuration options to use, or supply filenames and paths to use in the build process.</p>
<p>qmake looks for certain variables in each project file, and it uses the contents of these to determine what it should write to a Makefile. For example, the lists of values in the <a href="qmake-variable-reference.html#headers">HEADERS</a> and <a href="qmake-variable-reference.html#sources">SOURCES</a> variables are used to tell qmake about header and source files in the same directory as the project file.</p>
<p>Variables can also be used internally to store temporary lists of values, and existing lists of values can be overwritten or extended with new values.</p>
<p>The following snippet illustrates how lists of values are assigned to variables:</p>
<pre class="cpp">

  HEADERS = mainwindow.h paintwidget.h

</pre>
<p>The list of values in a variable is extended in the following way:</p>
<pre class="cpp">

  SOURCES = main.cpp mainwindow.cpp \
            paintwidget.cpp
  CONFIG += console

</pre>
<p><b>Note: </b>The first assignment only includes values that are specified on the same line as the <code>HEADERS</code> variable. The second assignment splits the values in the <code>SOURCES</code> variable across lines by using a backslash (\).</p><p>The <a href="qmake-variable-reference.html#config">CONFIG</a> variable is another special variable that qmake uses when generating a Makefile. It is discussed in <a href="qmake-project-files.html#general-configuration">General Configuration</a>. In the snippet above, <code>console</code> is added to the list of existing values contained in <code>CONFIG</code>.</p>
<p>The following table lists some frequently used variables and describes their contents. For a full list of variables and their descriptions, see <a href="qmake-variable-reference.html">Variables</a>.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Variable</th><th >Contents</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qmake-variable-reference.html#config">CONFIG</a></td><td >General project configuration options.</td></tr>
<tr valign="top" class="even"><td ><a href="qmake-variable-reference.html#destdir">DESTDIR</a></td><td >The directory in which the executable or binary file will be placed.</td></tr>
<tr valign="top" class="odd"><td ><a href="qmake-variable-reference.html#forms">FORMS</a></td><td >A list of UI files to be processed by the user interface compiler (uic).</td></tr>
<tr valign="top" class="even"><td ><a href="qmake-variable-reference.html#headers">HEADERS</a></td><td >A list of filenames of header (.h) files used when building the project.</td></tr>
<tr valign="top" class="odd"><td ><a href="qmake-variable-reference.html#qt">QT</a></td><td >A list of Qt modules used in the project.</td></tr>
<tr valign="top" class="even"><td ><a href="qmake-variable-reference.html#resources">RESOURCES</a></td><td >A list of resource (.qrc) files to be included in the final project. See the <a href="../qtcore/resources.html">The Qt Resource System</a> for more information about these files.</td></tr>
<tr valign="top" class="odd"><td ><a href="qmake-variable-reference.html#sources">SOURCES</a></td><td >A list of source code files to be used when building the project.</td></tr>
<tr valign="top" class="even"><td ><a href="qmake-variable-reference.html#template">TEMPLATE</a></td><td >The template to use for the project. This determines whether the output of the build process will be an application, a library, or a plugin.</td></tr>
</table></div>
<p>The contents of a variable can be read by prepending the variable name with <code>$$</code>. This can be used to assign the contents of one variable to another:</p>
<pre class="cpp">

  TEMP_SOURCES = $$SOURCES

</pre>
<p>The <code>$$</code> operator is used extensively with built-in functions that operate on strings and lists of values. For more information, see <a href="qmake-language.html">qmake Language</a>.</p>
<a name="whitespace"></a>
<h4 >Whitespace</h4>
<p>Usually, whitespace separates values in variable assignments. To specify values that contain spaces, you must enclose the values in double quotes:</p>
<pre class="cpp">

  DEST = &quot;Program Files&quot;

</pre>
<p>The quoted text is treated as a single item in the list of values held by the variable. A similar approach is used to deal with paths that contain spaces, particularly when defining the <a href="qmake-variable-reference.html#includepath">INCLUDEPATH</a> and <a href="qmake-variable-reference.html#libs">LIBS</a> variables for the Windows platform:</p>
<pre class="cpp">

  win32:INCLUDEPATH += &quot;C:/mylibs/extra headers&quot;
  unix:INCLUDEPATH += &quot;/home/user/extra headers&quot;

</pre>
<a name="comments"></a>
<h3 >Comments</h3>
<p>You can add comments to project files. Comments begin with the <code>#</code> character and continue to the end of the same line. For example:</p>
<pre class="cpp">

  # Comments usually start at the beginning of a line, but they
  # can also follow other content on the same line.

</pre>
<p>To include the <code>#</code> character in variable assignments, it is necessary to use the contents of the built-in <a href="qmake-variable-reference.html#literal-hash">LITERAL_HASH</a> variable.</p>
<a name="built-in-functions-and-control-flow"></a>
<h3 >Built-in Functions and Control Flow</h3>
<p>qmake provides a number of built-in functions to enable the contents of variables to be processed. The most commonly used function in simple project files is the <a href="qmake-test-function-reference.html#include-filename">include()</a> function which takes a filename as an argument. The contents of the given file are included in the project file at the place where the <code>include</code> function is used. The <code>include</code> function is most commonly used to include other project files:</p>
<pre class="cpp">

  include(other.pro)

</pre>
<p>Support for conditional structures is made available via <a href="qmake-language.html#scopes">scopes</a> that behave like <code>if</code> statements in programming languages:</p>
<pre class="cpp">

  win32 {
      SOURCES += paintwidget_win.cpp
  }

</pre>
<p>The assignments inside the braces are only made if the condition is true. In this case, the <code>win32</code> <a href="qmake-variable-reference.html#config">CONFIG</a> option must be set. This happens automatically on Windows. The opening brace must stand on the same line as the condition.</p>
<p>More complex operations on variables that would usually require loops are provided by built-in functions such as <a href="qmake-function-reference.html#findfunction">find()</a>, <a href="qmake-function-reference.html#unique">unique()</a>, and <a href="qmake-test-function-reference.html#countfunction">count()</a>. These functions, and many others are provided to manipulate strings and paths, support user input, and call external tools. For more information about using the functions, see <a href="qmake-language.html">qmake Language</a>. For lists of all functions and their descriptions, see <a href="qmake-function-reference.html">Replace Functions</a> and <a href="qmake-test-function-reference.html">Test Functions</a>.</p>
<a name="project-templates"></a>
<h2 id="project-templates">Project Templates</h2>
<p>The <a href="qmake-variable-reference.html#template">TEMPLATE</a> variable is used to define the type of project that will be built. If this is not declared in the project file, qmake assumes that an application should be built, and will generate an appropriate Makefile (or equivalent file) for the purpose.</p>
<p>The following table summarizes the types of projects available and describes the files that qmake will generate for each of them:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Template</th><th >qmake Output</th></tr></thead>
<tr valign="top" class="odd"><td >app (default)</td><td >Makefile to build an application.</td></tr>
<tr valign="top" class="even"><td >lib</td><td >Makefile to build a library.</td></tr>
<tr valign="top" class="odd"><td >aux</td><td >Makefile to build nothing. Use this if no compiler needs to be invoked to create the target, for instance because your project is written in an interpreted language.<p><b>Note: </b>This template type is only available for Makefile-based generators. In particular, it will not work with the vcxproj and Xcode generators.</p></td></tr>
<tr valign="top" class="even"><td >subdirs</td><td >Makefile containing rules for the subdirectories specified using the <a href="qmake-variable-reference.html#subdirs">SUBDIRS</a> variable. Each subdirectory must contain its own project file.</td></tr>
<tr valign="top" class="odd"><td >vcapp</td><td >Visual Studio Project file to build an application.</td></tr>
<tr valign="top" class="even"><td >vclib</td><td >Visual Studio Project file to build a library.</td></tr>
<tr valign="top" class="odd"><td >vcsubdirs</td><td >Visual Studio Solution file to build projects in sub-directories.</td></tr>
</table></div>
<p>See <a href="qmake-common-projects.html">Building Common Project Types</a> for advice on writing project files for projects that use the <code>app</code> and <code>lib</code> templates.</p>
<p>When the <code>subdirs</code> template is used, qmake generates a Makefile to examine each specified subdirectory, process any project file it finds there, and run the platform's <code>make</code> tool on the newly-created Makefile. The <code>SUBDIRS</code> variable is used to contain a list of all the subdirectories to be processed.</p>
<a name="generalconfiguration"></a><a name="general-configuration"></a>
<h2 id="general-configuration">General Configuration</h2>
<p>The <a href="qmake-variable-reference.html#config">CONFIG</a> variable specifies the options and features that the project should be configured with.</p>
<p>The project can be built in <i>release</i> mode or <i>debug</i> mode, or both. If debug and release are both specified, the last one takes effect. If you specify the <code>debug_and_release</code> option to build both the debug and release versions of a project, the Makefile that qmake generates includes a rule that builds both versions. This can be invoked in the following way:</p>
<pre class="cpp">

  make all

</pre>
<p>Adding the <code>build_all</code> option to the <code>CONFIG</code> variable makes this rule the default when building the project.</p>
<p><b>Note: </b>Each of the options specified in the <code>CONFIG</code> variable can also be used as a scope condition. You can test for the presence of certain configuration options by using the built-in <a href="qmake-test-function-reference.html#config-config">CONFIG()</a> function. For example, the following lines show the function as the condition in a scope to test whether only the <code>opengl</code> option is in use:</p><pre class="cpp">

  CONFIG(opengl) {
      message(Building with OpenGL support.)
  } else {
      message(OpenGL support is not available.)
  }

</pre>
<p>This enables different configurations to be defined for <code>release</code> and <code>debug</code> builds. For more information, see <a href="qmake-language.html#scopes">Using Scopes</a>.</p>
<p>The following options define the type of project to be built.</p>
<p><b>Note: </b>Some of these options only take effect when used on the relevant platform.</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 >qt</td><td >The project is a Qt application and should link against the Qt library. You can use the <code>QT</code> variable to control any additional Qt modules that are required by your application. This value is added by default, but you can remove it to use qmake for a non-Qt project.</td></tr>
<tr valign="top" class="even"><td >x11</td><td >The project is an X11 application or library. This value is not needed if the target uses Qt.</td></tr>
</table></div>
<p>The <a href="qmake-variable-reference.html#template">application and library project templates</a> provide you with more specialized configuration options to fine tune the build process. The options are explained in detail in <a href="qmake-common-projects.html">Building Common Project Types</a>.</p>
<p>For example, if your application uses the Qt library and you want to build it in <code>debug</code> mode, your project file will contain the following line:</p>
<pre class="cpp">

  CONFIG += qt debug

</pre>
<p><b>Note: </b>You must use &quot;+=&quot;, not &quot;=&quot;, or qmake will not be able to use Qt's configuration to determine the settings needed for your project.</p><a name="declaring-qt-libraries"></a>
<h2 id="declaring-qt-libraries">Declaring Qt Libraries</h2>
<p>If the <a href="qmake-variable-reference.html#config">CONFIG</a> variable contains the <code>qt</code> value, qmake's support for Qt applications is enabled. This makes it possible to fine-tune which of the Qt modules are used by your application. This is achieved with the <a href="qmake-variable-reference.html#qt">QT</a> variable which can be used to declare the required extension modules. For example, we can enable the XML and network modules in the following way:</p>
<pre class="cpp">

  QT += network xml

</pre>
<p><b>Note: </b><code>QT</code> includes the <code>core</code> and <code>gui</code> modules by default, so the above declaration <i>adds</i> the network and XML modules to this default list. The following assignment <i>omits</i> the default modules, and will lead to errors when the application's source code is being compiled:</p><pre class="cpp">

  QT = network xml # This will omit the core and gui modules.

</pre>
<p>If you want to build a project <i>without</i> the <code>gui</code> module, you need to exclude it with the &quot;-=&quot; operator. By default, <code>QT</code> contains both <code>core</code> and <code>gui</code>, so the following line will result in a minimal Qt project being built:</p>
<pre class="cpp">

  QT -= gui # Only the core module is used.

</pre>
<p>For a list of Qt modules that you can add to the <code>QT</code> variable, see <a href="qmake-variable-reference.html#qt">QT</a>.</p>
<a name="configuration-features"></a>
<h2 id="configuration-features">Configuration Features</h2>
<p>qmake can be set up with extra configuration features that are specified in feature (.prf) files. These extra features often provide support for custom tools that are used during the build process. To add a feature to the build process, append the feature name (the stem of the feature filename) to the <code>CONFIG</code> variable.</p>
<p>For example, qmake can configure the build process to take advantage of external libraries that are supported by <a href="http://www.freedesktop.org/wiki/Software/pkg-config">pkg-config</a>, such as the D-Bus and ogg libraries, with the following lines:</p>
<pre class="cpp">

  CONFIG += link_pkgconfig
  PKGCONFIG += ogg dbus-1

</pre>
<p>For more information about adding features, see <a href="qmake-advanced-usage.html#adding-new-configuration-features">Adding New Configuration Features</a>.</p>
<a name="declaring-other-libraries"></a>
<h2 id="declaring-other-libraries">Declaring Other Libraries</h2>
<p>If you are using other libraries in your project in addition to those supplied with Qt, you need to specify them in your project file.</p>
<p>The paths that qmake searches for libraries and the specific libraries to link against can be added to the list of values in the <a href="qmake-variable-reference.html#libs">LIBS</a> variable. You can specify the paths to the libraries or use the Unix-style notation for specifying libraries and paths.</p>
<p>For example, the following lines show how a library can be specified:</p>
<pre class="cpp">

  LIBS += -L/usr/local/lib -lmath

</pre>
<p>The paths containing header files can also be specified in a similar way using the <a href="qmake-variable-reference.html#includepath">INCLUDEPATH</a> variable.</p>
<p>For example, to add several paths to be searched for header files:</p>
<pre class="cpp">

  INCLUDEPATH = c:/msdev/include d:/stl/include

</pre>
</div>
<!-- @@@qmake-project-files.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qmake-tutorial.html">Getting Started</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qmake-common-projects.html">Building Common Project Types</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>