Results 1 to 3 of 3

Thread: Qmake question, support for conditional compilation?

  1. #1
    Join Date
    May 2012
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Qmake question, support for conditional compilation?

    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!

  2. #2
    Join Date
    May 2012
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qmake question, support for conditional compilation?

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qmake question, support for conditional compilation?

    Usually with qmake we do it like this:

    qmake Code:
    1. BUILD_FOR_CUST1 {
    2. DEFINES += "__COMPILE_FOR_CUST1__=1"
    3. }
    To copy to clipboard, switch view to plain text mode 

    and if we want to activate the clause we write:

    qmake Code:
    1. CONFIG += BUILD_FOR_CUST1
    To copy to clipboard, switch view to plain text mode 

    or just call "qmake CONFIG+=BUILD_FOR_CUST1".

    Alternatively you can use features (files with prf extension).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Does qmake support make install option?
    By hakermania in forum Newbie
    Replies: 14
    Last Post: 31st October 2010, 08:52
  2. Does qmake support out of source builds?
    By drescherjm in forum Qt Tools
    Replies: 5
    Last Post: 20th September 2010, 20:54
  3. QMake and GIF Support
    By sheeeng in forum Installation and Deployment
    Replies: 16
    Last Post: 28th July 2009, 10:49
  4. Replies: 5
    Last Post: 25th September 2007, 10:43
  5. qmake question
    By lni in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2007, 00:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.