[Interest] qmake: Test if environment variable is set.

2015-05-27 Thread Carel Combrink
Hi,

How do one test if an environmental variable is set from qmake?

I have searched a lot but can't get the code working. People and
documentation point to isEmpty() but that does not achieve the correct
result, see below:

My Code in my pro file:

isEmpty(TEST_1) {

message(Test 1: Empty ($$TEST_1))

} else {

message(Test 1: Not empty ($$TEST_1))

}

TEST_2=1

isEmpty(TEST_2) {

message(Test 2: Empty ($$TEST_2))

} else {

message(Test 2: Not empty ($$TEST_2))

}

TEST_3=$(FOO)

isEmpty(TEST_3) {

message(Test 3: Empty ($$TEST_3))

} else {

message(Test 3: Not empty ($$TEST_3))

}


TEST_4=$(PATH)

isEmpty(TEST_4) {

message(Test 4: Empty ($$TEST_4))

} else {

message(Test 4: Not empty ($$TEST_4))

}

TEST_5=

isEmpty(TEST_5) {

message(Test 5: Empty ($$TEST_5))

} else {

message(Test 5: Not empty ($$TEST_5))

}


And the output is:

Project MESSAGE: Test 1: Empty ()

Project MESSAGE: Test 2: Not empty (1)

Project MESSAGE: Test 3: Not empty ()

Project MESSAGE: Test 4: Not empty (/my/actual/path/)

Project MESSAGE: Test 5: Empty ()

So from this one can see that Test 3 does not give the required result.


Am I doing something wrong?

Is this intended behaviour?

How can I proceed to get the correct result?


Qt: 5.3.2

OS: Ubuntu 14.04 x64


Regards,
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] qmake: Test if environment variable is set.

2015-05-27 Thread Michael Sué
Hi,

I would use TEST_3=$$(FOO) instead of TEST_3=$(FOO)

- Michael.


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] qmake: Test if environment variable is set.

2015-05-27 Thread Thiago Macieira
On Wednesday 27 May 2015 09:03:24 Carel Combrink wrote:
 Am I doing something wrong?

Yes, you're expecting qmake to observe environment variables. It does not. 
Make honours and processes them, but that's run after qmake has finished 
running and has written the Makefile. Two separate and independent steps.

 Is this intended behaviour?

Yes.

 How can I proceed to get the correct result?

You cannot with qmake. You need to either make the variable a pure qmake one 
by passing it on the qmake command-line instead of the environment, or you 
skip doing the qmake checks and rely on Make rules only.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] qmake: Test if environment variable is set.

2015-05-27 Thread Thiago Macieira
On Wednesday 27 May 2015 00:10:19 Thiago Macieira wrote:
 On Wednesday 27 May 2015 09:03:24 Carel Combrink wrote:
  Am I doing something wrong?
 
 Yes, you're expecting qmake to observe environment variables. It does not.
 Make honours and processes them, but that's run after qmake has finished
 running and has written the Makefile. Two separate and independent steps.

Actually, I was partially right, but the explanation is wrong.

When you write:

SOURCES = $(FOO)

Then qmake will write to the Makefile:

SOURCES = $(FOO)

and like I said in the email above, Make will expand and do its job.

When you write:
isEmpty(SOURCES)

then qmake looks at SOURCES and sees it's *not* empty. It contains one item: 
$(FOO) (literally).

When you write:
message(Abc $$SOURCES def)

Then qmake will do the replacement and get the string Abc $(FOO) def. At 
that point, it notices the environment expansion and expands that, at that 
time. If you run with debugging enabled, you'll see it saying:

DEBUG 2: literal Abc $(FOO) def
DEBUG 2: evaluated expression = Abc $(FOO) def
DEBUG 1: /dev/stdin:1: calling built-in message(Abc $(FOO) def)
Project MESSAGE: Abc  def

So TEST_3 isn't empty. Only the output from message was empty because it 
performed an extra expansion.

The rest of the email was right:

  Is this intended behaviour?
 
 Yes.
 
  How can I proceed to get the correct result?
 
 You cannot with qmake. You need to either make the variable a pure qmake one
 by passing it on the qmake command-line instead of the environment, or you
 skip doing the qmake checks and rely on Make rules only.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] qmake: Test if environment variable is set.

2015-05-27 Thread Carel Combrink
Thiago,

 So TEST_3 isn't empty. Only the output from message was empty because it
 performed an extra expansion.


Thanks for the explanation, it makes a sense now.

Michael,

 I would use TEST_3=$$(FOO) instead of TEST_3=$(FOO)


This does work correctly thanks.

Reading the documentation on the difference between $$() and $() it makes
sense as Thiago explained.

Thank you both for the help.

Regards,
Carel
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest