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?
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>
}
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
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