A standard c++ qmake-based library is developed for Win32, Mac, and Linux. In the qmake project file, the platform-dependent sources are included like this:
win32 {
SOURCES += WinSystem.cpp
HEADERS += WinSystem.h
}
macx {
SOURCES += MacSystem.cpp
HEADERS += MacSystem.h
}
unix {
SOURCES += LinuxSystem.cpp
HEADERS += LinuxSystem.h
}
Now on OS X both unix
and macx
are defined, so the Linux files are also included and cause error! What is the solution to this?
Many qmake project files simply describe the sources and header files used by the project, using a list of name = value and name += value definitions. qmake also provides other operators, functions, and scopes that can be used to process the information supplied in variable declarations.
A scope is written as a condition followed by a series of declarations contained within a pair of braces. For example: The above code will add the paintwidget_win.cpp file to the sources listed in the generated Makefile when building for a Windows platform. When building for other platforms, the define will be ignored.
These advanced features allow Makefiles to be generated for multiple platforms from a single project file. In many project files, the assignment ( =) and append ( +=) operators can be used to include all the information about a project.
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. To assign a result to a variable, use the $$ operator with this type of function as you would to assign contents of one variable to another:
You can negate and combine blocks, so in unix but not in mac would be:
unix:!macx {
SOURCES += LinuxSystem.cpp
HEADERS += LinuxSystem.h
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With