开发者

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 fulfill开发者_如何学运维ed. 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
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜