qmake
Generate Makefiles from Qt project files
TLDR
Generate a Makefile from a project file in the current directory
Specify Makefile and project file locations
Generate a default project file
Compile a project
Enable debug mode
Display help
SYNOPSIS
qmake [options] [project-file.pro]
PARAMETERS
-help
Displays help information.
-v
Verbose mode: Prints more information.
-tp <template>
Specifies the template to use. Common templates include 'app', 'lib', 'vcapp', 'vclib', 'subdirs'.
-o <filename>
Specifies the output file name for the generated makefile or project file.
-makefile
Generates a makefile (default).
-project
Generates a project file from a directory containing source files. Useful for creating a base `.pro` file.
-query <variable>
Queries the value of a qmake variable.
-set <variable> <value>
Sets a qmake variable.
-r
Recursive mode: Processes subdirectories.
-d
Debug mode: Enables debugging output.
-after
Process the input file after all others.
-before
Process the input file before all others.
-nopwd
Do not change the current working directory.
DESCRIPTION
qmake is a cross-platform build system generator that simplifies the build process for Qt-based applications. It takes a project file (usually a `.pro` file) as input and generates platform-specific makefiles or project files for various build tools, such as Make, Visual Studio, and Xcode. This allows developers to write a single project description that can be used to build their application on multiple operating systems and with different compilers. It handles dependencies, compiler flags, and other build-related settings based on the project file and the chosen target platform. This abstraction improves portability and simplifies the build management for complex Qt projects.
CAVEATS
qmake requires Qt to be installed and configured correctly. The generated build files are specific to the chosen platform and build tool. Changes to the `.pro` file necessitate re-running qmake to regenerate the build files.
qmake's feature set is largely superseded by CMake in modern Qt development, though it remains available and usable.
PROJECT FILE (.PRO) FORMAT
The `.pro` file is the core input for qmake. It defines the project's source files, headers, libraries, compiler flags, and other settings. It uses a simple, declarative syntax.
Example: SOURCES += main.cpp myclass.cpp
HEADERS += myclass.h
QT += widgets
TEMPLATES
Templates define the type of project to be built (e.g., application, library). The `-tp` option specifies the template to use. Common templates include:
app: For creating an executable application.
lib: For creating a library.
subdirs: For projects with subdirectories.
HISTORY
qmake was developed as part of the Qt framework to simplify cross-platform build management. It gained popularity alongside Qt and was widely used for developing Qt-based applications. Over time, other build systems, particularly CMake, gained prominence and offered advantages in terms of flexibility and features. However, qmake remains a viable option for simpler Qt projects or for maintaining legacy codebases.