November 30, 2010

filip filip
Lab Rat
63 posts

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 ?

8 replies

November 30, 2010

Volker Volker
Robot Herder
5428 posts

Have a look at the Q_OS_XXX or Q_WS_XXX macros in qglobal.h [doc.qt.nokia.com].

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.

  1. OnUbuntu:DEFINES += ON_UBUNTU
  2. OnBoard:DEFINES += ON_BOARD

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

Call qmake like this:

  1. # on your ubuntu box:
  2. qmake "CONFIG += OnUbuntu"
  3. # or when compiling for your board:
  4. qmake "CONFIG += OnBoard"

November 30, 2010

filip filip
Lab Rat
63 posts

Seems to work. Thanks !

December 2, 2010

thp thp
Lab Rat
35 posts

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):

  1. linux-g++ {
  2.     QT += opengl
  3. }

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:

  1. linux-g++-maemo5 {
  2.     QT += dbus
  3. }

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.

December 4, 2010

Deleted Member # 14e8 Deleted Member # 14e8
Lab Rat
355 posts

I have to admit that the solution we use at Tamoggemon’s is a lot more stupid.

Every h file includes a file called HAL.h. In Hal.H we have a bunch of #defines and they get toggled by hand. Might not be the smartest way but it works out well for us.

December 4, 2010

xsacha xsacha
Lab Rat
517 posts

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!

 Signature 

- Sacha

December 4, 2010

Deleted Member # 14e8 Deleted Member # 14e8
Lab Rat
355 posts

Hi,
well. We had parameters like screen size, rendering engine to use, etc…

December 4, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

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

December 4, 2010

Deleted Member # 14e8 Deleted Member # 14e8
Lab Rat
355 posts

Well, it depends.

It works well here…

 
  ‹‹ How to Cross compiling Qt/X11 for beagleboard?      Problem using Phonon with Windows CE ››

You must log in to post a reply. Not a member yet? Register here!