Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables between *.pro files

I have the following *.pro files :

the one which heads the solution

# head - pro file :
TEMPLATE = subdirs
CONFIG = qt thread ordered

# save root directory
PROJECT_ROOT_DIRECTORY = $$_PRO_FILE_PWD_
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") // output : "Master pro file path : [/Path/To/Directory]"

# project subdirs
SUBDIRS += PROJECT1

and

# PROJECT1 - pro file :
TEMPLATE = app

# etc.

# output 'PROJECT_ROOT_DIRECTORY ' contents
message("Master pro file path : "$${PROJECT_ROOT_DIRECTORY}) // output :  "Master pro file path : []"

How do I pass variables between the 2 pro files (here the variable is PROJECT_ROOT_DIRECTORY) ?

Edit :

This is the same question as this this one, but I don't see how the "another option is to" answer can help me.

like image 602
azf Avatar asked Jul 07 '12 14:07

azf


1 Answers

You could put the variable definitions in a .pri file, which you then include in all .pro files you want. Note that you need to tell the .pro files in your subdirectories the path where to find the .pri file.

head.pro:

# head - pro file :
TEMPLATE = subdirs
CONFIG = qt thread ordered

# configuration
include(config.pri)
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") # output : "Master pro file path : [/Path/To/Directory]"

# project subdirs
SUBDIRS += PROJECT1

config.pri:

# save root directory
PROJECT_ROOT_DIRECTORY = $$PWD // not $$_PRO_FILE_PWD_!

project1/project1.pro:

# PROJECT1 - pro file :
TEMPLATE = app

# configuration
include(../config.pri)  # note that you need to put "../" before the .pri path
message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") # should now output :  "Master pro file path : [/Path/To/Directory]"
like image 173
leemes Avatar answered Oct 05 '22 21:10

leemes