Reputation: 53
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
Upvotes: 1
Views: 1186
Reputation: 15091
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.
Upvotes: 4