12

qmake allows to supply a variables via a command-line interface like this:

qmake "CONFIG += release" "MY_VAR = hello"

So i can use $$MY_VAR inside a .pro file. But is it possible to suply more than one variable such way? I have tried

qmake "CONFIG += release" "MY_VAR = hello" "MY_ANOTHER_VAR = hi"

But it did not work (raises error). Any hints?

x2.
  • 9,554
  • 6
  • 41
  • 62
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
  • What you say is true about supplying any number of variables on the command line of qmake (and ./configure, which is where I ran into the problem), but there was at least one case I ran into where I used quotes to separate my variable assignments, but configure did not understand the associativity of my input. So for example, in the questioners example, it understood the input to be CONFIG += "release MY_VAR = hello" This may not be true typing the command explicitly but when called from a script, levels of quoting get "consumed". – cycollins Nov 05 '22 at 21:15

2 Answers2

19

The question is misleading. You CAN supply any number of variables.

.pro file:

....
message($$VAR1)
message($$VAR2)

qmake run:

qmake ... "VAR1=VALUE1" "VAR2=VALUE2"

compiler output:


09:40:13: Running build steps for project test...
09:40:13: Starting: "c:\qtsdk\desktop\qt\4.8.1\mingw\bin\qmake.exe" D:\tmp\test\test.pro -r -spec win32-g++ "CONFIG+=declarative_debug" "VAR1=VALUE1" "VAR2=VALUE2"
Project MESSAGE: VALUE1
Project MESSAGE: VALUE2
Project MESSAGE: VALUE1
Project MESSAGE: VALUE2
Project MESSAGE: VALUE1
Project MESSAGE: VALUE2
09:40:14: The process "c:\qtsdk\desktop\qt\4.8.1\mingw\bin\qmake.exe" exited normally.
Sergey Skoblikov
  • 5,811
  • 6
  • 40
  • 49
6

qmake can access environment variables via $$() syntax (internal variables are accessed with $${} syntax). This can be used to pass any number of variables to qmake.

grigoryvp
  • 40,413
  • 64
  • 174
  • 277