Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: passing variables to subprojects

The structure of my project is as follow:

Proj
Proj.pro
--subProj
--subProj.pro
----subsubProj
----subsubProj.pro

Is there a way i can instance a global variable in subProj.pro and call it en e.g. subsubProj.pro like:

Proj.pro:

GLOBAL_VAR = true

subsubProj.pro:

message($$GLOBAL_VAR)

Update

Maybe I should more precise with my problem.

The usual behavior in Qt Creator when you right-click on Proj and choose "Build project"Proj"" is that qmake Proj.pro gets invoked then qmake subProj.pro and then subsubProj.pro

What I want to achieve is:

  1. When i build the project "Proj" only Proj.pro and subProj.pro get invoked (NOT subsubProj.pro)
  2. BUT: When i build the project "subProj" the invoked files are subProj.pro and subsubProj.pro

You achieve 1) by adding to subProj.pro:

TEMPLATE = subdirs
dont_invoke_subsub{
SUBDIRS = subsubProj
}

In this case when you do qmake Proj.pro 1) is fulfilled. BUT when you do qmake subProj.pro the subsubProj doesnt get built neither.

So my idea was to hand over a variable from Proj to subProj.

Proj.pro:

GLOBAL_VAR = true;

and subProj retrieves this variable:

subProj.pro

TEMPLATE = subdirs
equals(GLOBAL_VAR, true){
   # do nothing because Proj.pro invokes you
}
else {
   # invoke qmake subsubProj.pro
   SUBDIRS = subsubProj
}
like image 294
Dimitrij Avatar asked Jul 12 '11 10:07

Dimitrij


1 Answers

I managed to do that with the include(...) command via config files.

An other way (but more limited) is to use CONFIG+=GLOBAL_VAR in the qmake arguments list. That technique is quite useful for 'master' switchs.

But with both of them you can't change the GLOBAL_VAR during the pre-build process (qmake step) ...

like image 52
Thomas Vincent Avatar answered Oct 05 '22 04:10

Thomas Vincent