Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qmake platform scopes

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?

like image 372
yolo Avatar asked Jun 16 '11 11:06

yolo


People also ask

What is qmake in C++?

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.

How do I write a scope in a makefile?

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.

What are the advanced features of makefiles?

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.

How do I assign a result to a variable in qmake?

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:


1 Answers

You can negate and combine blocks, so in unix but not in mac would be:

unix:!macx {
  SOURCES += LinuxSystem.cpp
  HEADERS += LinuxSystem.h
}
like image 55
Tatu Lahtela Avatar answered Sep 28 '22 01:09

Tatu Lahtela