13

Greetings,

I've got a .pro file that looks like:

TEMPLATE = subdirs
SUBDIRS = foo bar

I want to set a variable, or define, or something in my subdirs .pro file that can be read in both the foo and bar .pro files.

I've tried to set an environment variable with:

export TEST=something

but that does not work, message($$(TEST)) always shows nothing (like TEST is unset).

Dan O
  • 4,323
  • 5
  • 29
  • 44
  • As an aside I am using OS X 10.4 – Dan O Sep 20 '09 at 09:03
  • http://lists.trolltech.com/qt-interest/2005-02/thread00337-0.html seems like a possibility for doing what i want to do! – Dan O Sep 20 '09 at 09:11
  • Troubadours answer may answer the question you had in mind, but it does not answer the question you posted (which is much more interesting). user176164 was on the right track. But it is Matt who has the correct answer, see [here](https://stackoverflow.com/a/54126938/2712726). – Patrick Fromberg Jul 15 '19 at 22:00

2 Answers2

18

Just place them in a common .pri file eg. common.pri and use qmake's own include syntax to include it i.e.

include(path/common.pri)

where path is the path to common.pri relative to the including .pro file.

Troubadour
  • 13,334
  • 2
  • 38
  • 57
  • I ended up doing this in the end, because qmake only searches for the .qmake.cache in the current directory or its parent. This was too restrictive for me. – Dan O Sep 21 '09 at 02:27
11

Another option is to place the common variables in a file called ".qmake.cache" stored in the root dir of the project. This way you don't need to include any .pri files in the subdir projects.

  • The fact that this will be a hidden file on my operating system is a bit of a bummer, but at least I don't have to taint my subdir projects with weird includes, thanks! – Dan O Sep 20 '09 at 18:02
  • 2
    This is insane! :) +1 – Яois Sep 18 '14 at 13:17