QtCreator: kit-specific precompiler macro definiti

2019-05-01 20:20发布

问题:

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?

回答1:

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...

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

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.



回答2:

I found another solution.

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

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.