PDA

View Full Version : QMake Shared/Global/Inherited Variables between projects



Sogartar
7th December 2010, 19:29
Hi,
My question is, if there is a way to declare a variable in a PRO file, so it is visible in all subproject?
I have a project that has different build options, where different flags to the compiler are passed. I want to have a base PRO file for each of the different builds and in these PRO files to define the different flags.
The horrible alternative is to create different versions of every subproject.
I am also aware that I can pass to QMake a variable that defines which build to execute, but in Qt Creator those are kept in the .user file, which is not under version control and is not share amongst developers.

yeye_olive
10th December 2010, 08:05
The way I do this is that I put the parts common to all subprojects in a .pri file, say common.pri, which I include from each subproject's .pro file using include(path/to/common.pri) (say include(../common.pri) if your subprojects are in subdirectories of the directory containing common.pri).

Then you can set global flags in common.pri that will affect the build process in each subproject (e.g. debug vs release, custom CONFIG variables, etc.).

Sogartar
10th December 2010, 13:43
The way I do this is that I put the parts common to all subprojects in a .pri file, say common.pri, which I include from each subproject's .pro file using include(path/to/common.pri) (say include(../common.pri) if your subprojects are in subdirectories of the directory containing common.pri).

Then you can set global flags in common.pri that will affect the build process in each subproject (e.g. debug vs release, custom CONFIG variables, etc.).

Thank you for your reply, but in this scenario how are you going to choose between, let's say, build_option_1, build_option_2 and build_option_3?

wysota
10th December 2010, 13:57
You add CONFIG += build_option_1 (or equivalent) to the project file you want to build with option 1.

totem
7th July 2012, 15:14
Hi

I have the following *.pro files :


# 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) ?

Marco Medri
5th December 2018, 15:40
How did you solve it in the end?

ChrisW67
28th January 2019, 05:05
How did you solve it in the end?
Using an include() file...


# master.pro
TEMPLATE = subdirs
CONFIG += ordered

include(master.pri)
message("Master PROJECT_ROOT_DIRECTORY: "$${PROJECT_ROOT_DIRECTORY})

# project subdirs
SUBDIRS += project1


# master.pri
PROJECT_ROOT_DIRECTORY = $${PWD}


# project1/project1.pro
include(../master.pri)

TEMPLATE = app
TARGET = project1
INCLUDEPATH += .

# Input
SOURCES += main.cpp

# output 'PROJECT_ROOT_DIRECTORY ' contents
message("$${TARGET} PROJECT_ROOT_DIRECTORY: "$${PROJECT_ROOT_DIRECTORY})

Output:


chrisw@newton /tmp/master $ qmake
Info: creating stash file /tmp/master/.qmake.stash
Project MESSAGE: Master PROJECT_ROOT_DIRECTORY: /tmp/master

chrisw@newton /tmp/master $ make
cd project1/ && ( test -e Makefile || /usr/lib64/qt5/bin/qmake -o Makefile /tmp/master/project1/project1.pro ) && make -f Makefile
Project MESSAGE: project1 PROJECT_ROOT_DIRECTORY: /tmp/master
make[1]: Entering directory '/tmp/master/project1'
...
make[1]: Leaving directory '/tmp/master/project1'

alemuntoni
23rd January 2020, 12:36
Hi,
I also need to access a qmake variable from some subdirs projects, but in my case I need access to the OUT_PWD of master.pro.
The solution given by @ChrisW67 does not work in this case (the OUT_PWD of project1 is printed).
I need to access to the value of OUT_PWD computed in master.pro inside project1.
Is there any way to have access to this value from a subdir project?