Mikael
Mikael

Reputation: 213

How to make the Qt project file (.pro) platform dependent?

Is there a way to include different libraries depending on the operating system with Qt-Creator?

In other words, is there an equivalent for the following lines in the .pro file:

#ifdef Q_WS_WIN
include(C:/myProject/myLybrary/my-lib.pri)
#endif

#ifdef Q_WS_X11
include(/home/user/myProject/myLybrary/my-lib.pri)
#endif

I know that the character '#' identifies a comment in the .pro file. What's the alternative here?

Upvotes: 6

Views: 12285

Answers (4)

Air In Day Vees
Air In Day Vees

Reputation: 66

I believe by operating system that you mean the target architecture you are compiling for. That's the context in which the .pro file operates, and it may or may not be the same architecture as the operating system of the host machine you are developing on.

You can specify a conditional expression in the .pro file based on the qmake spec that you are compiling with. For example, if you want to include some libraries only when you are compiling for an embedded Linux architecture, then you would put:

linux-oe-g++ {
    LIBS += -lsomelib
    HEADERS += SomeClass.h
    SOURCES += SomeClass.cpp
}

These lines would only go into effect when linux-oe-g++ is used as the -spec argument for qmake. (This is set in the Qt Creator IDE by configuring the project to use a kit that has the platform specified in the "Qt makespec" field.)

A preprocessor directive like the following C++ code does depend on the operating system you are developing on:

#ifdef __linux__
#include "linux/mylinuxlib.h"
#endif

This conditional is environment-dependent and is true only if I am developing on a Linux OS. It does not depend on the target architecture I am compiling for.

Upvotes: 3

user3804701
user3804701

Reputation: 21

Or if you like cross compile:

linux-g++-64{
# your includes
}

linux-arm-g++{
    # your includes
}

Upvotes: 1

ariwez
ariwez

Reputation: 1313

You can also use it like that (if more than one file):

linux-g++ | linux-g++-64 | linux-g++-32 {
 # your includes
}

win32 {
 # your includes
}

Upvotes: 8

thuga
thuga

Reputation: 12931

Have you tried this:

unix: include(/home/user/myProject/myLybrary/my-lib.pri)
win32: include(C:/myProject/myLybrary/my-lib.pri)

Upvotes: 8

Related Questions