CONFIG(config)

This function can be used to test for variables placed into the CONFIG variable. This is the same as scopes, but has the added advantage that a second parameter can be passed to test for the active config. As the order of values is important in CONFIG variables (that is, the last one set will be considered the active config for mutually exclusive values) a second parameter can be used to specify a set of values to consider. For example:

Because release is considered the active setting (for feature parsing) it will be the CONFIG used to generate the build file. In the common case a second parameter is not needed, but for specific mutual exclusive tests it is invaluable.

contains(variablename, value)

Succeeds if the variable variablename contains the value value; otherwise fails. It is possible to specify a regular expression for parameter value.

debug(level, message)

Checks whether qmake runs at the specified debug level. If yes, it returns true and prints a debug message.

defined(name[, type])

Tests whether the function or variable name is defined. If type is omitted, checks all functions. To check only variables or particular type of functions, specify type. It can have the following values:

equals(variablename, value)

error(string)

This function never returns a value. qmake displays string as an error message to the user and exits. This function should only be used for unrecoverable errors.

For example:

error(An error has occurred in the configuration process.)

eval(string)

Evaluates the contents of the string using qmake syntax rules and returns true. Definitions and assignments can be used in the string to modify the values of existing variables or create new definitions.

For example:

eval(TARGET = myapp) {
message($$TARGET)
}

Note: Quotation marks can be used to delimit the string, and the return value can be discarded if it is not needed.

exists(filename)

Tests whether a file with the given filename exists. If the file exists, the function succeeds; otherwise it fails. If a regular expression is specified for the filename, this function succeeds if any file matches the regular expression specified.

greaterThan(variablename, value)

Tests that the value of variablename is greater than value. First, this function attempts a numerical comparison. If at least one of the operands fails to convert, this function does a string comparison.

if(condition)

if(linux-g++*|macx-g++*):CONFIG(debug, debug|release) {
message("We are on Linux or Mac OS, and we are in debug mode.")
}

include(filename)

Includes the contents of the file specified by filename into the current project at the point where it is included. This function succeeds if filename is included; otherwise it fails. The included file is processed immediately.

You can check whether the file was included by using this function as the condition for a scope. For example:

infile(filename, var, val)

Succeeds if the file filename (when parsed by qmake itself) contains the variable var with a value of val; otherwise fails. If you do not specify val, the function tests whether var has been assigned in the file.

isActiveConfig

This is an alias for the CONFIG function.

isEmpty(variablename)

Succeeds if the variable variablename is empty; otherwise fails. This is the equivalent of count( variablename, 0 ).

For example:

isEmpty( CONFIG ) {
CONFIG += warn_on debug
}

isEqual

This is an alias for the equals function.

lessThan(variablename, value)

Tests that the value of variablename is less than value. Works as greaterThan().

log(message)

message(string)

Always succeeds, and displays string as a general message to the user. Unlike the error() function, this function allows processing to continue.

message( "This is a message" )

The above line causes "This is a message" to be written to the console. The use of quotation marks is optional, but recommended.

Note: By default, messages are written out for each Makefile generated by qmake for a given project. If you want to ensure that messages only appear once for each project, test the build_pass variable in conjunction with a scope to filter out messages during builds. For example:

!build_pass:message( "This is a message" )

mkpath(dirPath)

Creates the directory path dirPath. This function is a wrapper around the QDir::mkpath function.

requires(condition)

Evaluates condition. If the condition is false, qmake skips this project (and its SUBDIRS) when building.

Note: You can also use the REQUIRES variable for this purpose. However, we recommend using this function, instead.

system(command)

Executes the given command in a secondary shell. Succeeds if the command returns with a zero exit status; otherwise fails. You can check the return value of this function using a scope.

unset(variablename)

versionAtLeast(variablename, versionNumber)

Tests that the version number from variablename is greater than or equal to versionNumber. The version number is considered to be a sequence of non-negative decimal numbers delimited by '.'; any non-numerical tail of the string will be ignored. Comparison is performed segment-wise from left to right; if one version is a prefix of the other, it is considered smaller.

versionAtMost(variablename, versionNumber)

Tests that the version number from variablename is less than or equal to versionNumber. Works as versionAtLeast().

warning(string)

Always succeeds, and displays string as a warning message to the user.

write_file(filename, [variablename, [mode]])

Writes the values of variablename to a file with the name filename, each value on a separate line. If variablename is not specified, creates an empty file. If mode is append and the file already exists, appends to it instead of replacing it.

Test Function Library

Complex test functions are implemented in a library of .prf files.

packagesExist(packages)

Uses the PKGCONFIG mechanism to determine whether or not the given packages exist at the time of project parsing.

This can be useful to optionally enable or disable features. For example:

To make the target global, the code above needs to be included into every subdirs subproject. In addition, to make these targets do anything, non-subdirs subprojects need to include respective code. The easiest way to achieve this is creating a custom feature file. For example: