Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtCreator: kit-specific precompiler macro definitions

Tags:

qt

qt-creator

qt5

I am using QtCreator 3.1.1 to build a cross-platform project, and so I arranged to have different compilation kits for targeting my desktop PC and my BeagleBoneBlack (BBB).

Now I would like to define some macro in qmake project file (.pro) which are specific only for a given kit.

In other words I would like do in my .pro file something like:

if(kit == BBB)
   DEFINES += MY_BBB_MACRO
elseif(kit == Desktop)
   DEFINES += MY_DESKTOP_MACRO
else
   DEFINES += OTHER_MACRO

Is is possible? How can I do that?

like image 954
Morix Dev Avatar asked Jul 23 '14 14:07

Morix Dev


People also ask

What is a QT Kit?

A Qt Kit is a set of a Qt version, compiler and device and some other settings. It is used to uniquely identify the combination of tools for your project build. A typical kit for the desktop would contain a C++ compiler and a Qt version (e.g. Qt 6. xx. yy) and a device (“Desktop”).


2 Answers

I obtained some help on Qt forum (take a look here) about this problem...

Anyway the solution consists in using qmake built-in test functions.

Basically I've added some CONFIG directive in QtCreator's project management: in the following screenshot you can see for example you can see that I've added CONFIG+=BBB in the project configuration for BBB kit; in the same way I've added CONFIG+=AM335x and CONFIG+=Desktop to AM335x and Desktop kits, respectively...

enter image description here

Then, in my .pro file I've added something like:

enter image description here

and now in my source code I can use something like #ifdef PLATFORM_BBB, #ifdef PLATFORM_AM335X and #ifdef PLATFORM_DESKTOP for differentiating the program behavior depending on compilation kit.

like image 172
Morix Dev Avatar answered Nov 12 '22 16:11

Morix Dev


I found another solution.

First, add additional arguments in Projects using CONFIG+=Variable name for kit.

screen capture from Project setting

And in .pro file, write some code like below.

Desktop {
    message("Desktop is selected")
}

RPI {
    message("rpi is selected")
    target.path = /home/pi
    INSTALLS += target
}

If you look at the general message tab, you can see that the setting works well.

like image 23
Jaewon Kim Avatar answered Nov 12 '22 16:11

Jaewon Kim