Results 1 to 6 of 6

Thread: qmake: dependency of application on common shared library

  1. #1
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default qmake: dependency of application on common shared library

    Hello,

    Using Qt Creator 0.9.1 (Qt 4.5.0), I created several projects:

    1.) a shared library common to applications using the lib template and stored in projects/common/
    2.) two applications using the app template in projects/app*, relying on the shared library to be built if needed and copied into the respective target dir (debug|release).

    Is there a place to define dependencies similar to what MS Visual Studio allows with the concept of a solution, i.e. information that goes beyond a single project such as which project depends on what other project as well as automatic pre and post build actions?

    The Qt Create's qmake help talks about PRE_TARGETDEPS and POST_TARGETDEPS, DEPENDPATH and target.depends. Unfortunately the explanations are quite brief and I could not derive a solution for this quit simple and standard problem.

    Thanks for your help,
    peter

  2. #2
    Join Date
    May 2008
    Posts
    155
    Thanked 15 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qmake: dependency of application on common shared library

    Quote Originally Posted by PeterWurmsdobler View Post
    Hello,

    Using Qt Creator 0.9.1 (Qt 4.5.0), I created several projects:

    1.) a shared library common to applications using the lib template and stored in projects/common/
    2.) two applications using the app template in projects/app*, relying on the shared library to be built if needed and copied into the respective target dir (debug|release).

    Is there a place to define dependencies similar to what MS Visual Studio allows with the concept of a solution, i.e. information that goes beyond a single project such as which project depends on what other project as well as automatic pre and post build actions?

    The Qt Create's qmake help talks about PRE_TARGETDEPS and POST_TARGETDEPS, DEPENDPATH and target.depends. Unfortunately the explanations are quite brief and I could not derive a solution for this quit simple and standard problem.

    Thanks for your help,
    peter
    What about creating a .pro with TEMPLATE=subdirs and SUBDIRS=projekt1 path/to/project2 and possibly CONFIG += ordered?

  3. #3
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qmake: dependency of application on common shared library

    Hello,

    thanks for your answer. I thought about that and discarded the approach as this would only solve the problem of a correct build sequence. There are still two issues:

    1.) You would build the top project which builds all, even if you only need one branch project and the referenced shared library.

    2.) The library is still not copied from its output dir into the applications output directory.

    Cheers,
    peter

  4. #4
    Join Date
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qmake: dependency of application on common shared library

    The idea of using top project with subdir + ordered was right. You can have two top project files, both containing the path to your library. And then just parametrize the installation process of the library file (or its header files) with variable, that you set in the top project file.

    For example, in the library .pro file you can add:

    QMAKE_POST_LINK = make install
    list_of_files_to_install.files = interface.h library.so
    list_of_files_to_install.path = $$MY_LIBRARY_DEST_PATH
    INSTALLS +=list_of_files_to_install

    And the top project for your first application just appends:

    MY_LIBRARY_DEST_PATH=$$PWD/app1

    The same for your second application:

    MY_LIBRARY_DEST_PATH=$$PWD/app2


    There is no need for magic PRE_TARGETDEPS, ... options.
    Last edited by seim; 15th January 2009 at 00:51.

  5. #5
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qmake: dependency of application on common shared library

    Hello,

    Thanks again for your idea. However, I do not fully agree with this approach as the library pushes the output to its "clients", so it has to know by whom it is being used. This would be like the model has to know about its views in a model/view paradigm.

    Another issue is, if you are only interested in one leaf project and the parent project (library) it depends on, you need to compile the top level project, which would compile all leaf projects.

    In my opinion, it should be the other way round. If an application requires a library, it should pull it in, even if it means to copy necessary files into the project.

    I tried to add an additional build step for the project setting where I copy the .dll from the library path (debug|release) into the respective application build dir. However, it did not work under Windows.

    Still searching for a proper solution.
    peter

  6. #6
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qmake: dependency of application on common shared library

    I'm working in a similar issue though I didn't use Qt Creator.

    I have a library stored in one path in Subversion. It's currently being brought into to my project via SVN's externals - but that's beside the point here. Needless to say, it's a shared set of static libraries that multiple applications will be using. Each project it gets brought into needs to ensure that it (or its respective subprojects) get built before the project itself is built. The structure is basically as follows

    Qt Code:
    1. application\
    2. application.pro
    3. application.sln
    4. application.vcproj
    5. deps\
    6. lib\
    7. lib.debug\
    8. include\
    9. src\
    10. src.pro
    11. <subproject>\
    12. <subproject>.pro
    13. <subproject files>
    To copy to clipboard, switch view to plain text mode 

    The src.pro uses the 'subdirs' template, and each project under it puts its output (static library and PRL file) into lib or lib.debug (for release and debug builds respectively). I find this works very well as then the application only has to know about one (or two) places for linking.

    I do, however, have the same problem - I want the application to be able to build the static libraries it needs by simply adding something to the application's project file (e.g. application.pro). Thus far I have tried:

    Qt Code:
    1. include (deps/src/src.pro)
    To copy to clipboard, switch view to plain text mode 

    However, that doesn't seem to work and I have to manually run the library build before the applications build. This is complicated by having to support both VS and Qmake/Make (under Linux).

    Further, I have numerous static libraries being generated and it'd be nice to be able to only build what I actually need and use.

    Per working directly Qt via Visual Studios, I found the following to be helpful to run from a 'build' directory in parallel to the 'src' directory for the shared libraries:

    Qt Code:
    1. $ qmake -tp vc -r ../src/src.pro
    To copy to clipboard, switch view to plain text mode 

    This generates the required solutions and project files, but requires that anyone modifying the qmake project files also update the solutions/projects by re-running this command when they're done and committing the results into source control. Fortunately it can be run on Windows _or_ other systems (e.g. Linux) (Okay for now, but not good as a long term solution.)

    As the OP stated - we need to be able to build the dependency. Using the SUBDIR template for the application doesn't seem like a solution - since it would require an entirely different application source layout that just doesn't make sense for the project - I don't need two directories for what could be accomplished in one.

    Scripting is problematic as there would have to be a script for Windows and a script for everything else.

    I think QMake could easily resolve this solution - whether it already does (if so how?) or by modification to do so. Something like the include solution would be great.

    In reading through the docs, the 'features' solution sounds like a good possibility, but it doesn't seem like Qt supports having features in sub-projects in this manner.

Similar Threads

  1. Replies: 11
    Last Post: 18th May 2007, 11:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.