September 14, 2011

p-himik p-himik
Robot Herder
254 posts

[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:

  1. 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:
  1. CONFIG += ..\\common_lines

everything works well.
For portability i wrote:
  1. 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

September 17, 2011

Volker Volker
Mad Scientist
5250 posts

What about include()?

September 18, 2011

p-himik p-himik
Robot Herder
254 posts

The problem of include() is that qmake reads included file in advance. So if included file contains some common .cpp files these files will be in the source thee of all projects which use that included file. It makes cluttering in project tree view in Qt Creator.

September 18, 2011

Volker Volker
Mad Scientist
5250 posts

You could split your project into multiple includes: one containing the settings (wich you can include in “external” projects too) and on with the file list(s).

September 18, 2011

p-himik p-himik
Robot Herder
254 posts

If i understand you correctly this does the same cluttering.
Example:

  1. #project.pro
  2. SOURCES += main.cpp other.cpp
  3. HEADERS += other.h
  4. include( common_sources.pri )
  5. include( common_settings.pri )
  6.  
  7. #common_sources.pri
  8. SOURCES += first.cpp second.cpp third.cpp
  9. HEADERS += first.h second.h third.h
  10.  
  11. #common_settings.pri
  12. VARIABLE_1 = value_1
  13. VARIABLE_2 = value_2
  14. 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).

September 18, 2011

Volker Volker
Mad Scientist
5250 posts

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.

September 19, 2011

p-himik p-himik
Robot Herder
254 posts

Here are two pictures. First is when i use CONFIG (wich is non-portable with slashes).
with CONFIG
Second is when i use include() (which is portable but look at project’s tree).
with include
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:

  1. ##mainProject.pro
  2. TEMPLATE = subdirs
  3.  
  4. SUBDIRS += \
  5.     project1 \
  6.     project2 \
  7.     project3
  8.  
  9. HEADERS += \
  10.     common/common1.h \
  11.     common/common2.h
  12.  
  13. SOURCES += \
  14.     common/common1.cpp \
  15.     common/common2.cpp
  16.  
  17. OTHER_FILES += \
  18.     common_includes.prf
  19.  
  20. ##project1.pro (other projects have the same structure)
  21. HEADERS += \
  22.     project1.h
  23.  
  24. SOURCES += \
  25.     project1.cpp
  26.  
  27. #CONFIG += unix: ../common_includes else: ..\\common_includes
  28. include(../common_includes.prf)
  29.  
  30. ##common_includes.prf
  31. COMMON_DIR = /path/to/common/dir
  32.  
  33. HEADERS += \
  34.     $${COMMON_DIR}/common1.h \
  35.     $${COMMON_DIR}/common2.h
  36.  
  37. SOURCES += \
  38.     $${COMMON_DIR}/common1.cpp \
  39.     $${COMMON_DIR}/common2.cpp

September 20, 2011

Volker Volker
Mad Scientist
5250 posts

For me these are different project structures and they do not seem to be equivalent.

Regarding your .prf solution: Why don’t you copy that .prf file into the Qt installation dir?

September 20, 2011

p-himik p-himik
Robot Herder
254 posts

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).

September 20, 2011

Volker Volker
Mad Scientist
5250 posts
p-himik wrote:
Copying .prf file to Qt dir makes me feel like creating global variables :)

But that’s the way things work.

 
  ‹‹ QTCreator 2.3.0 debugger detects wrong ABI.      Analyze tool in Qt Creator ››

You must log in to post a reply. Not a member yet? Register here!