[Moved] qmake and cross-platform .pro files
I have a project with a rather complicated structure (subdirs and subsubdirs). Many of subprojects must contain in their .pro files similar lines. Of cource i don’t want to paste this lines in every project so i wrote .prf file and added in each relevant subproject’s .pro file this:
- CONFIG += ../common_lines
As you can see this file is one level upper in the directory structure. When i run qmake for such projects in windows environment it doesn’t look at common_lines.prf at all. But if i write in .pro files this:
- CONFIG += ..\\common_lines
everything works well.
For portability i wrote:
- CONFIG += unix: ../common_lines win32: ..\\common_lines
It did the trick but it looks ugly and redundant.
Is there any other way to do such thing? And why qmake converts / to \\ and vise versa in such variables as SOURCES but not in CONFIG?
9 replies
If i understand you correctly this does the same cluttering.
Example:
- #project.pro
- SOURCES += main.cpp other.cpp
- HEADERS += other.h
- include( common_sources.pri )
- include( common_settings.pri )
- #common_sources.pri
- SOURCES += first.cpp second.cpp third.cpp
- HEADERS += first.h second.h third.h
- #common_settings.pri
- VARIABLE_1 = value_1
- VARIABLE_2 = value_2
- VARIABLE_3 = value_3
With this scheme Qt Creator builds project’s tree containing all files from common_sources.pri. And when i have many projects with the same common sources these sources anyway will be in the project’s tree.
All i want is to include all common sources implicitly. And adding a relative path to the file containing common sources to the CONFIG variable does it. Except, as mentioned above, different path delimiters (or what is the right name for it?) on different platforms (windows and linux in this case).
As far as I know the sources added in a .pri are relative to the directory of that .pri. The file separator is a slash (”/”) in all .pri and .pro files, this works for me and everyone else that I know of.
So, what’s the problem with the setup of the .pro and two .pri files you outlined above? Does it work or not? You just told us that your .prf solution does not work.
If you always need the common sources you can of course merge the two .pri files into one single file.
Here are two pictures. First is when i use CONFIG (wich is non-portable with slashes).

Second is when i use include() (which is portable but look at project’s tree).

Both ways work but first is more complicated (with unix{}else{} or something like this for portability) and second creates huge redundant tree.
Here are contents of the files:
- ##mainProject.pro
- TEMPLATE = subdirs
- SUBDIRS += \
- project1 \
- project2 \
- project3
- HEADERS += \
- common/common1.h \
- common/common2.h
- SOURCES += \
- common/common1.cpp \
- common/common2.cpp
- OTHER_FILES += \
- common_includes.prf
- ##project1.pro (other projects have the same structure)
- HEADERS += \
- project1.h
- SOURCES += \
- project1.cpp
- #CONFIG += unix: ../common_includes else: ..\\common_includes
- include(../common_includes.prf)
- ##common_includes.prf
- COMMON_DIR = /path/to/common/dir
- HEADERS += \
- $${COMMON_DIR}/common1.h \
- $${COMMON_DIR}/common2.h
- SOURCES += \
- $${COMMON_DIR}/common1.cpp \
- $${COMMON_DIR}/common2.cpp
These different structures lead to the same object files. So their difference is only appearance in the Qt Creator (with common files appearing in every project or just in parent).
Copying .prf file to Qt dir makes me feel like creating global variables :)
I think i’ll use “unix: … else: …”-thing. It’s less redundant than the same files appearing in every project. And it doesn’t make any influence on Qt dir (so i can just copy project’s directory to other computer).
You must log in to post a reply. Not a member yet? Register here!



