Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using conditions when customize qt project

Tags:

qt

qmake

Good day! I have a qt project and I want to customize it using .pro-file conditions. Notably, I want to use one .pro-file to get several outputs, something like that:

DEFINES += APP1=0 APP2=1
DEFINES += TYPE=APP1
if(TYPE == APP1) {
LIBS += <LIB1>
DESTDIR = <DIR1>
}
else {
LIBS += <LIB2>
DESTDIR = <DIR2>
}

But when I try to build my project I get the following error when running qmake:

Parse Error('else')

How to do it correctly?

like image 510
Mikhail Zimka Avatar asked Jan 22 '13 10:01

Mikhail Zimka


2 Answers

The values stored in the CONFIG variable are treated specially by qmake. Each of the possible values can be used as the condition for a scope. So, your project file can be wrote simply as:

CONFIG += APP1

APP1 {
  LIBS += <LIB1>
  DESTDIR = <DIR1>
} else {
  LIBS += <LIB2>
  DESTDIR = <DIR2>
}
like image 184
liuyi.luo Avatar answered Nov 10 '22 01:11

liuyi.luo


I just want to note 1 thing about the conditions Make sure the curly bracket is not the same line. Otherwise it will fail

Good

CONFIG += opencv_32_bit

opencv_32_bit {

} else {

}

Will fail

CONFIG += opencv_32_bit

opencv_32_bit 
{

}
else
{

}

I'm not sure why, but I had this problem since I prefer braces on the next line

like image 20
Daniel Georgiev Avatar answered Nov 10 '22 01:11

Daniel Georgiev