Qmake steps to create and install libs, headers and build a test app? Possible?

  • Apologies in advance for this rather verbose question, but I'm not sure how to ask it more succinctly.

    I have just recently started learning about about Qt and qmake and I'm having a bit of trouble wrapping my head around setting up qmake properly. To help me sort things out I created a little test project that at the top level is a "subdirs" template. Within that directory are two sub-directories; The .pro file in one subdir is a "lib" template, and the other is an "app" template.

    I've managed to configure the top level "subdirs" .pro file such that it knows how to add the headers from the "lib" sub project to a system wide common area "include" directory (by using the "INSTALLS" directive). Also, the lib project correctly creates and dumps the library (.dll and .a) in a common area "lib" directory for use by other projects.

    So... I kinda figured that there must be some way to actually configure the .pro file to perform the following steps in this order but I can't figure out how to do it.

    1. Compile and install the lib to the common area "lib" dir.

    2. Distribute the header to the common area "include" dir.

    3. Compile the App such that it links to the library in the common lib dir, and can find the library headers in the common include dir.

    The only way I can see to do it is by hand configuring "Build Settings" which is saved in that machine specific ".pro.user" file. How I pulled off getting steps 1,2 & 3 is by creating a "make install" step, that sits between the first "qmake" step and the actual "make" step, such that the most up-do-date header file gets copied from the lib dir the common "include" directory before make attempts to compile the "app".

    The thing is, it seems that these .pro.user files are kind of transitory. They are only valid for a given machine, and if I'm hand creating steps in it so that this whole package compiles properly, then what use is that to a colleague who might check the project out of a git repo onto his machine so he can try it out and build the libs and the app etc.? The .pro.user file is kind of useless to him since it hard codes various paths into it that are specific to my setup and he will probably have to set up his own .pro.user file. Somehow I have to communicate to him to configure the "Build Settings" in a certain way. Seems error prone and complicated.

    So... how do I do this in a general way that doesn't require hand configuring the "Build Settings". If it's not possible, and this is really how one does it, that's fine - I just want to know.

    Perhaps the idea of building libs and installing them should be totally logically separate from building apps that use them, that is, these should be two separate projects entirely. That might be an answer too - it's possible that my approach isn't sensible. Except one can think of the "app" as perhaps being the "test suite" for the libs, and it might be nice to have them all bundled together. Anyway that was my thinking fwiw.

    Thanks very much for any and all help!

    Kind Regards,

  • A common solution is to build the application using the libraries and headers files found within the source directory. If you want that your application can be built using both (system-wide and local) just add a conditional to your .pro file.
    // toplevel.pro

    SUBDIRS += lib app
    CONFIG += ordered // make sure lib is built before app

    // app.pro

    exists(/usr/include/yourproject.h) { // system-wide includes installed
    INCLUDEPATH += /usr/include
    LIBS += -L/usr/lib
    else {
    INCLUDEPATH += ../include
    LIBS += -L../lib
    Brain to terminal. Not tested.

    make install then copies the includes and libraries to their system-wide places, so that other applications can use it as well.

    A more sophisticated solution would be using "qmake features":http://doc.qt.nokia.com/latest/qmake-advanced-usage.html#adding-new-configuration-features as for example "QCA":http://delta.affinix.com/qca/ does.

Log in to reply

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