Conditional compiling depending on target



  • I'm developing an application that has to run on my host computer (Ubuntu) - mainly for testing purposes - as well as on our target board (with IMX27 processor). Some things, mainly related to hardware, are specific to the target board and have to be excluded from the host version. I would like to do that with conditional compiling, but don't know what to use to detect the target system. Can I use Q_CC_GNU as an indication for the host target ? Can anyone help ?



  • Have a look at the Q_OS_XXX or Q_WS_XXX macros in "qglobal.h":http://doc.qt.nokia.com/4.7/qtglobal.html.

    If that does not fit you needs, you can manually define a macro in qmake's .pro file which is exposed to your code, probably together with a CONFIG switch on the qmake command line.

    @
    OnUbuntu:DEFINES += ON_UBUNTU
    OnBoard:DEFINES += ON_BOARD
    @

    You then can test in your code with #ifdef/#ifndef.

    Call qmake like this:

    @

    on your ubuntu box:

    qmake "CONFIG += OnUbuntu"

    or when compiling for your board:

    qmake "CONFIG += OnBoard"
    @



  • Seems to work. Thanks !



  • If you also want to only use some Qt modules depending on where you are building, you could do something like this in your .pro file (note that you can either use ":" for a single line or "{" and "}" for a block):

    @
    linux-g++ {
    QT += opengl
    }
    @

    This will only enable the OpenGL module if you are building on Linux. Or if you only want D-Bus on Maemo 5 (but not on Symbian), you could do something like this:

    @
    linux-g++-maemo5 {
    QT += dbus
    }
    @

    As already mentioned, for doing #ifdefs in the code, use Q_WS_MAEMO_5 for Qt on the N900 and Q_OS_SYMBIAN for Symbian.



  • I've simply been using the Q_OS.. defines. What else do you need to define in your HAL.h that you can't already do with Qt defines?

    Might be a bit of redundancy there!



  • tamhanna, I think such things should be made by compilation flags, not by header.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.