在QtCreator 4.2.0中,我尝试使用一个* .pro文件来为多种硬件配置构建二进制文件。
在Build&Run => Build Settings => Build Enviroment中,我定义了环境变量TARGET
,如下所示:
TARGET
的值为bbb
TARGET
的值为desktop
在pro文件中,我使用以下测试功能:
equals($$TARGET,"bbb")
{
message("setting include paths for bbb"))
message($$TARGET)
}
equals($$TARGET,"laptop")
{
message("setting include paths for laptop.")
message($$TARGET)
}
contains($$TARGET,"*bbb*")
{
message("setting include paths for bbb"))
message($$TARGET)
}
contains($$TARGET,"*laptop*")
{
message("setting include paths for laptop.")
message($$TARGET)
}
而且我在运行qmake时得到此输出:
Project MESSAGE: setting include paths for bbb
Project MESSAGE: bbb
Project MESSAGE: setting include paths for laptop.
Project MESSAGE: bbb
Project MESSAGE: setting include paths for bbb
Project MESSAGE: bbb
Project MESSAGE: setting include paths for laptop.
Project MESSAGE: bbb
Project MESSAGE: setting include paths for bbb
这对我来说毫无意义,我无法弄清楚我在做什么错。为什么要进行laptop
测试后的零件?
顺便说一下,我通过使用Scopes
解决了我的问题。这对我来说很完美:
CONFIG += $$(TARGET_HW)
desktop {
message("setting include paths for laptop.")
}
cetec {
message("setting include paths for cetec."))
}
但是我仍然对使用测试功能的正确方法感兴趣。
例如,我为第一次测试提供了正确的语法:
equals(TARGET,"bbb") {
message("setting include paths for bbb"))
message($$TARGET)
}
请注意: