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



  • What about include()?



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



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



  • 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).
    !http://dl.dropbox.com/u/26596688/Selection_002.jpeg(with CONFIG)!
    Second is when i use include() (which is portable but look at project's tree).
    !http://dl.dropbox.com/u/26596688/Selection_003.jpeg(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:
    @##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

    @



  • 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?



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



  • [quote author="p-himik" date="1316477661"]
    Copying .prf file to Qt dir makes me feel like creating global variables :)[/quote]

    But that's the way things work.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.