QtCreator:特定于套件的预编译器宏定义 [英] QtCreator: kit-specific precompiler macro definitions

查看:167
本文介绍了QtCreator:特定于套件的预编译器宏定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QtCreator 3.1.1 来构建跨平台项目,因此我安排了不同的编译工具包来针对我的台式机和 BeagleBoneBlack (BBB).

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

现在我想在 qmake 项目文件 (.pro) 中定义一些仅针对给定套件的宏.

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

换句话说,我想在我的 .pro 文件中做类似的事情:

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?

推荐答案

我在 Qt 论坛上获得了一些帮助(看看 这里) 关于这个问题...

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

无论如何,解决方案在于使用 qmake 内置测试功能.

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

基本上我在 QtCreator 的项目管理中添加了一些 CONFIG 指令:在下面的截图中你可以看到例如你可以看到我添加了 CONFIG+=BBB在 BBB 套件的项目配置中;以同样的方式,我将 CONFIG+=AM335xCONFIG+=Desktop 分别添加到 AM335x 和桌面套件...

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

然后,在我的 .pro 文件中,我添加了如下内容:

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

现在在我的源代码中,我可以使用诸如 #ifdef PLATFORM_BBB#ifdef PLATFORM_AM335X#ifdef PLATFORM_DESKTOP 之类的东西来区分程序行为取决于编译工具包.

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.

这篇关于QtCreator:特定于套件的预编译器宏定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆