Qmake Configuration Issues

Source: Internet
Author: User

Create a project file

The project file contains all the information that Qmake needs to build your application, library files, or plugins. Typically, you specify resources in a project file using a series of declarations, but support for simple program constructs allows you to describe different build processes for different platforms or environments.

Project file elements

The project file format used by Qmake can support simple and complex building system use. Jane's project file uses a simple declaration style that defines a standard variable that indicates the header and source files used in the project. Complex projects can use the control process structure to adjust the build process.

The following sections describe the use of different types of elements in a project file.

Variable

In the project file, a variable is a list of strings to hold. In a simple project, these variables notify qmake to use the relevant configuration information, or provide a file name and path to use during the build process.

Qmake looks for certain variables in each project file and uses them to determine what to write to makefile. For example, the variable list in headers and sources is used to tell Qmake header files and source files in the same directory as project files.

Variables can also hold a list of temporary variables inside, and existing variable lists can be overwritten or extended by new values.

The following code snippet illustrates how a value list is assigned to a variable:

HEADERS = Mainwindow.h paintwidget.h

The list of values in a variable is extended by the following way:

SOURCES = main.cpp mainwindow.cpp paintwidget.cppconfig + = Console

Note: The first assignment statement contains only the value specified in the same row as the headers variable. The second assignment statement separates the values in the sources from the backslash (\).

The config variable is another special variable that Qmake used when generating makefile. The general Configuration is discussed here. In the code snippet above, the console is added to the list of values that the config already exists.

The table below lists the common variables and describes their contents. For a complete list of variables and their descriptions, please see variables

Variable Describe
CONFIG Common project configuration options.
DESTDIR The directory where the executable and binary files will be stored.
FORMS A list of UI files that have been processed by user interface compiler (UIC).
HEADERS A list of header file (. h) names that are used when building the project.
Qt List of QT modules used in the project
RESOURCES A list of resource files (. qrc) that are included in the final project. For more information about resource files, see the Qt Resource System.
SOURCES The list of source files (. cpp) used when building the project.
TEMPLATE The template used by the project. This determines whether the build process outputs an application, a library, or a plug-in

You can read the contents of a variable by attaching a $$ to it before the variable name. This allows you to assign the contents of a variable to another variable.

Temp_sources = $ $SOURCES

The $$ operator is widely used in built-in functions for manipulating strings and lists of values. For more details, see Qmake Language

Space

Typically, spaces are used to separate values in variable assignments. Specifies that the variable contains spaces, and you must enclose the variable in double quotation marks

DEST = "program Files"

The quoted text is treated as a separate value in the variable. A similar approach is used to handle paths that contain spaces, especially when the Windows platform defines INCLUDEPATH and libs variables:

Win32:includepath + = "C:/mylibs/extra Headers" Unix:includepath + = "/home/user/extra headers"

Comments

Comments can be added to the project file. The comment begins with the # character until the end of the line. For example:

# comments usually start at the head of a line, but it can also be behind this peer content

To include the # character in an assignment variable, you must use the contents of the built-in Literal_hash variable

Built-in functions and control flow

Qmake provides a number of built-in functions to handle variable content. In a simple project file, the include () function is most commonly used, and the function uses a file name as a parameter. The contents of the given file are included in the project file where the Include function is used. The Include () function is often used to include other project files

Include (Other.pro)

Conditional structure statements can be supported by scope (scopes). This behavior is the same as the IF in the programming language

Win32 {SOURCES + = Paintwidget_win.cpp}

Only when the condition is true does the task in curly braces be executed. In this example, the WIN32 option for config must be set. The curly brace on the left must be on the same line as the condition only if it is automatically processed on the Windows system

A more complex operation on a variable usually covers the built-in functions such as find (), unique (), and count () that are provided for looping. Provides these features, and other action strings and paths, provides user input, and calls extension tools. For more detailed information on using these functions, see Qmake Language. For a list of all functions and their descriptions, see Replace Functions and Test Functions.

Project templates

The template variable is used to define the type that the project will build. If it is not declared in the project file, Qmake assumes that the application is built and will generate an appropriate makefile (or equivalent file) for that purpose.

The following table briefly describes the project type variables and each file that is generated as a description qmake:

Template Qmake output
App (default) Makefile Building an application
Lib Makefile Generate a library
Aux Makefile does not generate anything. If no editor needs to call create target. For example, your project is written in an explanatory language.
Note: This template type is only available for makefile-based generators. In particular, it does not work with the vcxproj and Xcode generators.
Subdirs The Makefile rule contains sub-files specified using the Subdirs variable. Each subdirectory must contain its own project file.
Vcapp Visual Studio project files build an application
Vclib

Visual Studio project files generate a library

Vcsubdirs

Visual Studio solution files to build projects in subdirectories

View Building Common Project Types recommendations when writing project files that use project templates and Library template projects.

When using the Subdirs template, Qmake generates a makefile to check each subdirectory, process the project files found in the subdirectory, and execute the platform's make tool to generate a new makefile. The Subdirs variable is used to contain a list of all subdirectories to be processed.

General configuration

The config variable specifies the options and features that the project should configure.

The project can be built in release mode or in debug mode or both modes. If debug and release are specified together, the last specified entry takes effect. If you specify the Debug_and_release option to build the debug and release two versions of the project, Qmake generates a makefile that contains the build two version rule. Can be called in the following ways:

Make all

Add the Build_all option to the config variable, which is used when the rule builds the project.

Note: Each variable specified in config can be used as a conditional scope. You can use the built-in config () method to test whether a configuration option exists. For example, the code below shows that using this method as a condition for a domain test if only OpenGL options are used

CONFIG (OpenGL) {message (Building with OpenGL support.)} else {message (OpenGL. Available.)}

This allows different configuration constructs to be defined for release and Debug. For more detailed information, see Using Scopes.

The options below define the type of project to build.

Note: Some options will only take effect if they are used on the relevant platform.

option description
QT This project is a QT application that needs to connect to the QT library. You can use the QT variable to control all the additional QT modules needed for your application. This value is added by default, but you can delete it with qmake for non-QT projects.
x11 A project is an X11 application or library. If the target uses QT then this value is not required.

The Application and library project templates provide you with more specialized configuration options to adjust the build process. The options are explained in more detail in building Common Project Types

For example, if your application uses the QT library and you want to build the project in debug mode. Your project file will contain the following code:

CONFIG + = qt Debug

Note: You must use "+ =" and cannot use "=", otherwise qmake will not be able to determine which settings are required for your application using QT configuration.

Declaring the QT library

If the config variable contains qt values, turn on qmake support for QT applications. This allows you to fine-tune the QT module used by your application. Variables through QT can be used to declare additional modules that are needed. For example, we can also enable the XML and network modules in the following ways:

QT + = Network xml

Note: QT includes the core and GUI modules by default, so the above declaration adds the network and XML modules to the default list. The assignment below removes the default module, which causes the application's source code to appear incorrectly at compile time:

QT = Network XML # This would omit the core and GUI modules.

If you want to build a project without a GUI module, you need to delete it with the "-=" operation. By default, QT contains the core and GUI. The following code will result in a minimal QT project build:

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

You can add a list of QT modules to QT variables, see QT

Configuration Features

The Qmake can provide additional configuration features specified in the feature file (. prf). These additional features often provide support for custom tools that are used in the build process. In order to add functionality to the build process, append the name of the function (the stem of the function filename) to the config variable

For example, use the code below Qmake to configure the build process to take advantage of the external libraries provided by Pkg-config. such as D-bus and the Ogg library.

CONFIG + = Link_pkgconfigpkgconfig + ogg dbus-1

For more detailed information on adding new features, see Adding new Configuration Features.


declaring other libraries

In addition to the QT supported libraries, you can add other libraries to the project, and you must specify them in the project file.

Qmake can find the path where the library is located, and a specific library link can be added to the value list of the LIBS variable. You can specify the path to the library, or use the UNIX style notation to specify the library and path.

For example, the code below shows how to specify a library:

LIBS + =-l/user/local/lib-lmath

The path that contains the header file can also be added to the Includepath variable in the same way

For example, add several paths to find the header file

Includepath = C:/msdev/include D:/stl/include


Qmake Configuration Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.