我有以下* .pro文件:
领导解决方案的人
# 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
和
# PROJECT1 - pro file :
TEMPLATE = app
# etc.
# output 'PROJECT_ROOT_DIRECTORY ' contents
message("Master pro file path : "$${PROJECT_ROOT_DIRECTORY}) // output : "Master pro file path : []"
如何在2个pro文件之间传递变量(此处变量为PROJECT_ROOT_DIRECTORY
)?
修改:
这是与此this one相同的问题,但我不知道“另一个选项”的答案如何帮助我。
答案 0 :(得分:8)
您可以将变量定义放在.pri
文件中,然后将其包含在所需的所有.pro
文件中。请注意,您需要告诉子目录中的.pro
个文件找到.pri
文件的路径。
<强> 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]"