Search code examples
qtqt-creatorqmake

QMake: test functions do not work as expected


In QtCreator 4.2.0 I try to use one *.pro file for building binaries for multiple hardware configurations.

In Build & Run => Build Settings => Build Enviroment I define the enviroment variable TARGET like as follows:

  • Build Settings A: Variable TARGET has Value bbb
  • Build Settings B: Variable TARGET has Value desktop

In the pro-file I use the following test functions:

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

And I get this output when running 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

This makes no sense to me an I can't figure what I'm doing wrong here. Why are the parts after testing fro laptop executed?

By the way, I solved my problem by using Scopes. This works perfect for me:

CONFIG += $$(TARGET_HW)
desktop {
    message("setting include paths for laptop.")
}

cetec {
    message("setting include paths for cetec."))
}

But I'm still interested in the correct way of using test functions.


Solution

  • I provide the correct syntax for the first test, as an example:

    equals(TARGET,"bbb") {
        message("setting include paths for bbb"))
        message($$TARGET)
    }
    

    Please notice:

    1. The curly brace is on the same line of the test.
    2. The variable tested has no dollar signs, just the variable name