LinuxCommandLibrary

qmake

Generate Makefiles from Qt project files

TLDR

Generate a Makefile from a project file in the current directory

$ qmake
copy

Specify Makefile and project file locations
$ qmake -o [path/to/Makefile] [path/to/project_file.pro]
copy

Generate a default project file
$ qmake -project
copy

Compile a project
$ qmake && make
copy

Enable debug mode
$ qmake -d
copy

Display help
$ qmake -help
copy

SYNOPSIS

qmake [options] [files]
Common usages:
qmake -project [options]
qmake [file.pro] [options]
qmake -makefile [file.pro] [options]

PARAMETERS

-project
    Generates a basic .pro project file in the current directory. Ideal for starting new projects.

-o file
    Specifies the name of the output build file (e.g., Makefile, .vcxproj). If omitted, qmake uses a default name.

-makefile
    Instructs qmake to generate a Makefile. This is the default behavior when a .pro file is provided.

-spec spec
    Specifies the target platform and compiler configuration (e.g., linux-g++, win32-msvc). Use qmake -query QMAKE_SPEC to see current spec.

-config config
    Adds a specific build configuration to the project (e.g., debug, release, static, shared). Can be used multiple times.

-set VAR=VALUE
    Sets a qmake variable before processing the project file. Useful for overriding project settings from the command line.

-query [VAR]
    Queries the value of a qmake variable or lists all known variables if no variable is specified.

-r, -recursive
    Recursively processes subdirectories specified in the SUBDIRS variable of the project file.

-nocache
    Disables the qmake cache, forcing it to re-evaluate all expressions.

-help
    Displays a help message with available command-line options.

-v, -version
    Displays the qmake version and Qt version information.

-d, -debug
    Enables debug output, showing more detailed information about qmake's processing.

-Wall
    Enables all compiler warnings. This is often passed through to the underlying compiler.

DESCRIPTION

qmake is a cross-platform build system generator used primarily with the Qt framework. Its main purpose is to simplify the compilation process of Qt-based applications and libraries across various operating systems and compiler environments. Instead of manually writing complex Makefiles or project files for each platform, developers use qmake to process simple, declarative project files (typically ending in .pro).

qmake automatically handles common Qt-specific build steps, such as invoking the Meta-Object Compiler (moc) for signals and slots, the User Interface Compiler (uic) for .ui files, and the Resource Compiler (rcc) for embedding resources. It can generate Makefiles (for Unix-like systems, MinGW), Visual Studio project files (for Windows), Xcode project files (for macOS), and more. This automation significantly streamlines development by abstracting away platform-specific build complexities, allowing developers to focus on writing code.

CAVEATS

While powerful for Qt projects, qmake is less suitable or efficient for general C++ projects without Qt dependencies. For new Qt projects, especially starting with Qt 6 and beyond, CMake is increasingly recommended as the preferred build system, offering greater flexibility and a more standardized approach within the broader C++ ecosystem. qmake projects can sometimes become complex and harder to maintain for very large or highly customized build scenarios compared to alternatives.

<B>QMAKE PROJECT FILES (.PRO)</B>

The core of qmake are its project files, typically named .pro. These text files use a simple, declarative syntax to define project properties like source files (SOURCES), header files (HEADERS), Qt modules (QT), build configurations (CONFIG), and platform-specific settings. qmake reads these files and translates them into appropriate build system files for the target platform.

<B>VARIABLES AND FUNCTIONS</B>

qmake allows extensive configuration through variables (e.g., TARGET, DESTDIR, INCLUDEPATH, LIBS) and functions (e.g., message(), system(), contains(), $$[QT_INSTALL_HEADERS]). These provide powerful ways to manage dependencies, define custom build steps, and adapt projects to different environments or build requirements.

HISTORY

qmake was originally developed by Trolltech (the creators of Qt, later acquired by Nokia, then by Digia, and now managed by The Qt Company) as an integral part of the Qt toolkit. It was introduced to address the complexities of building cross-platform C++ applications, particularly those leveraging Qt's extensive features. For many years, qmake served as the primary and recommended build system for all Qt development. While it remains fully supported for existing projects, The Qt Company has increasingly moved towards advocating for CMake as the default build system for new Qt projects, especially since Qt 6, due to CMake's broader adoption in the C++ community and its more powerful, flexible features.

SEE ALSO

make(1): The standard build automation tool that qmake often generates files for., cmake(1): A widely adopted cross-platform build system generator, becoming the recommended choice for modern Qt projects., moc(1): Qt's Meta-Object Compiler, invoked by qmake to handle C++ extensions for Qt's signal/slot mechanism., uic(1): Qt's User Interface Compiler, invoked by qmake to compile .ui files (Qt Designer forms) into C++ code., rcc(1): Qt's Resource Compiler, invoked by qmake to compile .qrc files (Qt resource files) into C++ code., qtchooser(1): A utility to select the default Qt installation to be used by development tools like qmake.

Copied to clipboard