Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable comparison in QMake

I know that in QMake you can use the $$ syntax to add custom variable arguments like so:

# In .pro
message($$FOO)
# In shell
$ qmake 'FOO="ABC"'

I also know you can use conditonals to check things like the current platform as well:

win32 {
    # ...
}

Using a combination of these syntaxes, how would you define a conditional to check if the variable argument equals a value?

# I want something like this:
$$FOO == "..." {
    # ...
}
like image 238
beakr Avatar asked Jan 08 '14 22:01

beakr


1 Answers

This is what we are using in QtSerialPort itself:

equals(variablename, value)

Tests whether variablename equals the string value.

For example:

TARGET = helloworld equals(TARGET, "helloworld") { message("The target assignment was successful.") }

You can also use this "for not equal" checks the usual way as follows:

!equals(a, b) { ... }

You need to be aware of that as several qmake functions, including this, need to have a local variable around to be able to work with. It is not enough to pass your value to qmake and print the variable out. This is a bit somewhat silly limitation about qmake.

Strictly speaking, you could also use the following function for the comparison, but this is less preferred:

eval(string)

Evaluates the contents of the string using qmake syntax rules and returns true. Definitions and assignments can be used in the string to modify the values of existing variables or create new definitions.

For example:

eval(TARGET = myapp) {
    message($$TARGET)
}
like image 135
lpapp Avatar answered Sep 19 '22 12:09

lpapp