PDA

View Full Version : Qmake question, support for conditional compilation?



HowardHarkness
25th May 2012, 18:43
I used Qt many years ago (3.x), so I got tapped to do a Qt project at my new job. Not only is my Qt really rusty, things have changed -- and I'm on a different platform. Any rate, I've run into a qmake problem.

What I want to do:

The company has a tool which will take a makefile which contains a CONFIGURABLE section, and will generate (and install) executables for each entry. Example:

##CONFIGURABLE#################################### ##########
BUILD_FOR_CUST1 = 0
BUILD_FOR_CUST2 = 0
BUILD_FOR_CUST3 = 0
##END CONFIGURABLE###################################### ####

Later in the makefile, there is a section that looks like this:

##GCC INFORMATION####################################### ####
CC = gcc
CFLAGS = -D__COMPILE_FOR_NS__=$(BUILD_FOR_NS) -D__COMPILE_FOR_CUST1__=$(BUILD_FOR_CUST1) -D__COMPILE_FOR_CUST2__=$(BUILD_FOR_CUST2) -D__COMPILE_FOR_CUST3__=$(BUILD_FOR_CUST3)-Wall
LDFLAGS = -Wl,-R"/TDS_Data/Program"
##END GCC INFORMATION#######################################

The tool will iterate through this, and spit out 3 executables, one for each of the variables, by setting each to "= 1" in turn.

In the various code files, there is conditional compilation of the form:

#if __COMPILE_FOR_CUST1__
// code for customer 1
#endif
//etc.

What can I put into the .PRO file to generate something at least close to what this tool is expecting?

Failing that, is there something I can do to achieve the same task?

I have tried adding stuff to the .PRO file, such as

##CONFIGURABLE#################################### ##########
BUILD_FOR_CUST1 = 0
BUILD_FOR_CUST2 = 1
##END CONFIGURABLE###################################### ####

equals($$BUILD_FOR_CUST1,1){
DEFINES+="__COMPILE_FOR_CUST1__=1"
}

equals($$BUILD_FOR_CUST2,1){
DEFINES+="__COMPILE_FOR_CUST2__=1"
}

However, this does not work. There are no DEFINES directive in the output from qmake, so I'm guessing that I'm not understanding how equals( ) works. I have also experimented with defineReplace( ), and using the DEFINES+= in the project settings of the IDE, but apparently, I don't understand enough about how that works, either, because the qmake line in the makefile output contains gibberish.

I hope I've put enough information in here to accurately describe the problem. If not, please tell me what sort of information I need to add.

To summarize, I'm trying to build a program using conditional compilation, and trying to integrate the build with an existing system. TIA!

HowardHarkness
25th May 2012, 21:14
To clarify things a bit, I should add that I can specify the conditional compilation variables using the IDE by entering the DEFINES+=__COMPILE_FOR_CUST1__=1 in the "Additional arguments" box for the qmake configuration. The problem is figuring out how to get the various versions built by the existing company build process. If I can just come fairly close, it's possible that I can get the existing build process modified.

wysota
25th May 2012, 21:52
Usually with qmake we do it like this:

BUILD_FOR_CUST1 {
DEFINES += "__COMPILE_FOR_CUST1__=1"
}

and if we want to activate the clause we write:

CONFIG += BUILD_FOR_CUST1

or just call "qmake CONFIG+=BUILD_FOR_CUST1".

Alternatively you can use features (files with prf extension).