QMake - pass variable to child projects

放肆的年华 提交于 2019-12-11 05:31:47

问题


I have a qmake project with these project files:

. parent1.pro
. parent2.pro  
. child_common.pro

parent1 and parent2 are both subdirs project and have child_common as a subdir.

Is there a way for me to define a variable usable by child_common that have a different value based on which parent the child is used by?

For instance: if I'm compiling parent1, child_common should have a variable MY_VAR=A. If I'm compiling parent2 it should have MY_VAR=B


回答1:


Well, in fact it's not how the things are supposed to be done (as qmake never allows to pass its variables onto the SUBDIRS subprojects), so you may eventually end up having two separate child_common instances. However, if all your projects belong to the same directory subtree, you can make use of the qmake's cache file in the following way.

First, create an empty cache file in your common root subdirectory: touch .qmake.cache (or .qmake.stash, or .qmake.super). Then add the following to all your "parent" projects:

MY_VAR = A # or B
cache(MY_VAR, set) # or "set stash", or "set super"

Now MY_VAR should be visible inside any of your subprojects, as long as the cache file exists in the parent directory. But notice that the changes of the cache contents do not automatically imply the (sub)project rebuild.



来源:https://stackoverflow.com/questions/54073133/qmake-pass-variable-to-child-projects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!