You can test for any other platform-compiler combination as long as a specification exists for it in the mkspecs directory.
Variables
Many of the variables used in project files are special variables that qmake uses when generating Makefiles, such as DEFINES, SOURCES, and HEADERS. It is possible for you to create variables for your own use; qmake creates new variables with a given name when it encounters an assignment to that name. For example:
MY_VARIABLE = value
There are no restricitions on what you do to your own variables, as qmake will ignore them unless it needs to evaluate them when processing a scope.
You can also assign the value of a current variable to another variable by prefixing $$ to the variable name. For example:
MY_DEFINES = $$DEFINES
Now the MY_DEFINES variable contains what is in the DEFINES variable at this point in the project file. This is also equivalent to:
MY_DEFINES = $${DEFINES}
The second notation allows you to append the contents of the variable to another value without separating the two with a space. For example, the following will ensure that the final executable will be given a name that includes the project template being used:
TARGET = myproject_$${TEMPLATE}
Variables can be used to store the contents of environment variables. These can be evaluated at the time that qmake is run, or included in the generated Makefile for evaluation when the project is built.
To obtain the contents of an environment value when qmake is run, use the $$(...) operator:
DESTDIR = $$(PWD)
message(The project will be installed in $$DESTDIR)
In the above assignment, the value of the PWD environment variable is read when the project file is processed.
To obtain the contents of an environment value at the time when the generated Makefile is processed, use the $(...) operator:
DESTDIR = $$(PWD)
message(The project will be installed in $$DESTDIR)
DESTDIR = $(PWD)
message(The project will be installed in the value of PWD)
message(when the Makefile is processed.)
In the above assignment, the value of PWD is read immediately when the project file is processed, but $(PWD) is assigned to DESTDIR in the generated Makefile. This makes the build process more flexible as long as the environment variable is set correctly when the Makefile is processed.
The special $$[...] operator can be used to access various configuration options that were set when Qt was built:
message(Qt version: $$[QT_VERSION])
message(Qt is installed in $$[QT_INSTALL_PREFIX])
message(Qt resources can be found in the following locations:)
message(Documentation: $$[QT_INSTALL_DOCS])
message(Header files: $$[QT_INSTALL_HEADERS])
message(Libraries: $$[QT_INSTALL_LIBS])
message(Binary files (executables): $$[QT_INSTALL_BINS])
message(Plugins: $$[QT_INSTALL_PLUGINS])
message(Data files: $$[QT_INSTALL_DATA])
message(Translation files: $$[QT_INSTALL_TRANSLATIONS])
message(Settings: $$[QT_INSTALL_SETTINGS])
message(Examples: $$[QT_INSTALL_EXAMPLES])
message(Demonstrations: $$[QT_INSTALL_DEMOS])
The variables accessible with this operator are typically used to enable third party plugins and components to be integrated with Qt. For example, a Qt Designer plugin can be installed alongside Qt Designer's built-in plugins if the following declaration is made in its project file:
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
Variable Processing Functions
qmake provides a selection of built-in functions to allow the contents of variables to be processed. These functions process the arguments supplied to them and return a value, or list of values, as a result. In order to assign a result to a variable, it is necessary to use the $$ operator with this type of function in the same way used to assign contents of one variable to another:
HEADERS = model.h
HEADERS += $$OTHER_HEADERS
HEADERS = $$unique(HEADERS)
This type of function should be used on the right-hand side of assignments (i.e, as an operand).
It is possible to define your own functions for processing the contents of variables. These functions can be defined in the following way:
defineReplace(functionName){
#function code
}
The following example function takes a variable name as its only argument, extracts a list of values from the variable with the eval() built-in function, and compiles a list of files:
defineReplace(headersAndSources) {
variable = $$1
names = $$eval($$variable)
headers =
sources =
for(name, names) {
header = $${name}.h
exists($$header) {
headers += $$header
}
source = $${name}.cpp
exists($$source) {
sources += $$source
}
}
return($$headers $$sources)
}
Conditional Functions
qmake provides built-in functions that can be used as conditions when writing scopes. These functions do not return a value, but instead indicate "success" or "failure":
count(options, 2) {
message(Both release and debug specified.)
}
This type of function should be used in conditional expressions only.
It is possible to define your own functions to provide conditions for scopes. The following example tests whether each file in a list exists and returns true if they all exist, or false if not:
defineTest(allFiles) {
files = $$ARGS
for(file, files) {
!exists($$file) {
return(false)
}
}
return(true)
}
Adding New Configuration Features
qmake lets you create your own features that can be included in project files by adding their names to the list of values specified by the CONFIG variable. Features are collections of custom functions and definitions in .prf files that can reside in one of many standard directories. The locations of these directories are defined in a number of places, and qmake checks each of them in the following order when it looks for .prf files:
- In a directory listed in the QMAKEFEATURES environment variable; this contains a colon-separated list of directories.
- In a directory listed in the QMAKEFEATURES property variable; this contains a colon-spearated list of directories.
- In a features directory residing within a mkspecs directory. mkspecs directories can be located beneath any of the directories listed in the QMAKEPATH environment variable (a colon-separated list of directories). ($QMAKEPATH/mkspecs/<features>)
- In a features directory residing beneath the directory provided by the QMAKESPEC environment variable. ($QMAKESPEC/<features>)
- In a features directory residing in the data_install/mkspecs directory. (data_install/mkspecs/<features>)
- In a features directory that exists as a sibling of the directory specified by the QMAKESPEC environment variable. ($QMAKESPEC/../<features>)
The following features directories are searched for features files:
- features/unix, features/win32, or features/macx, depending on the platform in use
- features/
For example, consider the following assignment in a project file:
CONFIG += myfeatures
With this addition to the CONFIG variable, qmake will search the locations listed above for the myfeatures.prf file after it has finished parsing your project file. On Unix systems, it will look for the following file:
- $QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES environment variable)
- $$QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES property variable)
- myfeatures.prf (in the project's root directory)
- $QMAKEPATH/mkspecs/features/unix/myfeatures.prf and $QMAKEPATH/mkspecs/features/myfeatures.prf (for each directory listed in the QMAKEPATH environment variable)
- $QMAKESPEC/features/unix/myfeatures.prf and $QMAKESPEC/features/myfeatures.prf
- data_install/mkspecs/features/unix/myfeatures.prf and data_install/mkspecs/features/myfeatures.prf
- $QMAKESPEC/../features/unix/myfeatures.prf and $QMAKESPEC/../features/myfeatures.prf
Note: The .prf files must have names in lower case.
[Previous: qmake Platform Notes]
[Contents]
[Next: Using Precompiled Headers]