Starting in QT, Part III - qmake and. Pro
In this third post we will talk about QT utility qmake project files and *. Pro. Let us understand what it is for qmake and how to configure different types of projects.
The qmake
The qmake is a utility that comes with the QT framework. Its function is to parse a project file (*. Pro) and generate a Makefile already with the rules of the moc , uic and QT embedded options. Without it, for example, would have to explicitly call the moc to create files and moc_ * explicitly pass to the compiler and linker options to include the correct QT to our projects.
Official documentation about qmake and project files can be found here .
* Project files. Pro
To create a simple project from the command line, enter the project directory and typing:
user @ host $ qmake-project
That done, you will create a file with the same name as the current directory, followed by the extension. Pro. If there are already files in this directory recognized by qmake, as source code files (. H. Cpp), forms (. Ui), etc, they are automatically added to the project file.
Created the file. Pro, to execute qmake without arguments it will try to parse a file. Pro with the same name as the current directory. You can even specify an alternative project file as an argument for qmake. If everything worked, was created a Makefile, and with a simple make, we can build the project.
The project files are regular text files containing macros and directives that will be interpreted by qmake to create the Makefile. The full list of options can be found in the documentation online . The most common are:
TEMPLATE: Indicate the type of project. Use 'app' for proramas executables or 'lib' to create libraries.
CONFIG: Add several options to the project. Among them, 'debug' debugging information to add, 'staticlib' together with the template 'lib', that is created abiblioteca static (. It in linux).
TARGET: The name and location of the target, ie, the application or library.
MOC_DIR: directory where the files will be grads moc_ *. Useful to not pollute the source code directory.
OBJECTS_DIR: Complementary to the previous option indicates the directory where the files on it will generate object code (*. O).
IncludePath: external directories where headers are to be used in the project, such as headers from external libraries.
DEPENDPATH: external source code directories that will be used by the project.
HEADERS: The header files of the project (*. H).
FORMS: interface files generated with the QTDesigner (*. Ui).
SOURCES: The files of source code implementation of the project (*. Cpp).
LIBS: external libraries used by the project. -L indicates the path to the library, e-l says the library name.
QT: QT modules to be added / deleted from the project. If past "QT = '(equals empty QT), QT is no module used in the project.
SUBDIRS: Used in conjunction with the template 'subdirs' indicates the subdirectories ons qmake should look for other project files.
With this in hand we can create simple designs SOME.
A simple application:
# The first line creates a character of this comment # The name of this file is 'app.pro' Our # TEMPLATE = app template is an application called TARGET = bin / # myapp.bin myapp.bin within the dir. / Bin MOC_DIR = tmp / moc # Directory for MOCs, optional OBJECTS_DIR = tmp / obj # directory for object code, optional HEADERS + = MyClass.h # Header class MyClass SOURCES + = main.cpp # Use to organize files into myclass.cpp # multiple lines.
A simple library:
# The name of this file is 'lib.pro' Our # TEMPLATE = lib template is a library CONFIG + = dll # dynamic call TARGET = lib / mylib # mylib within the dir. / Lib MOC_DIR = tmp / moc # Directory for MOCs, optional OBJECTS_DIR = tmp / obj # directory for object code, optional HEADERS + = MyClass.h # Header class MyClass SOURCES + = myclass.cpp # Implementation of class MyClass
An application that uses an external library:
# The name of this file is 'mixed.pro' Our # TEMPLATE = app template is an application called TARGET = bin / # myapp.lkd myapp.lkd within the dir. / Bin MOC_DIR = tmp / moc # Directory for MOCs, optional OBJECTS_DIR = tmp / obj # directory for object code, optional + = IncludePath. # Dir where are the Headers of the external lib SOURCES + = main.cpp # Implementation of the application.
Nested directories:
To utilize nested directories, we need a project file in the current directory, and another subdirectory.
In the current directory, use the options:
TEMPLATE = subdirs SUBDIRS = [list of subdirectories to be built in sequence]
If given only the directory name, it must contain a project file with your own name. Is it possible in entando, report directly to the list of subdirectories, one directory followed by a project file with Quaker name.
The complete source code of the examples discussed in this tutorial can be found here .
In conclusion
The qmake is a simple and very powerful tool which greatly facilitates the life of one who has to manage trees of complex project, even if the project does not use QT (just add at the end of the '= QT'). Add to this the fact that the project files have a syntax very simple and somewhat intuitive. If you need finer adjustments, documentation online will give you a dozen options for fun.
With or without QT QT qmake is always a good option for management of tree build.

