[qmake] Link to a static library using shadow builds



  • Hi, I just created a new project and I am having trouble with qmake variables. Neither the documentation, nor the "undocumented qmake":http://www.qtcentre.org/wiki/index.php?title=Undocumented_qmake, nor even the mighty Google seems to have the answer I'm looking for. My project is organized like that:

    @MyProject/
    - MyProject.pro # subdirs project template
    Main/
    - Main.pro # this is the app project that depends on MyLib
    MyLib/
    - MyLib.pro # this is a custom MyProject-specific static library@

    How am I supposed to refer to the MyLib library in the Main.pro project file, to notify the linker to use the generated binary? The best I could come up with was:

    @# in Main.pro:
    LIBS += $${OUT_PWD}/../MyLib/debug/MyLib.lib@

    I know this would have to be customized to handle both release and debug builds and that the target name will change on other platforms but that's not really an issue, I just wanted it to work for now (and it does).

    But I thought that there may be another solution, more clever or better to use. I tried using $$DESTDIR but it doesn't seem to be defined. I'm trying to use shadow builds to avoid doing all the rubbish I usually do, ie setting DESTDIR, OBJECTS_DIR, MOC_DIR, etc. that is a pain to setup (if I don't copy/paste an existing project) but at least with this method I can control where the binaries will go, therefore I'm able to link to them reliably.

    Maybe this is the correct way to use qmake and it's not that hacky after all, but creating a post here will hopefully get the attention of guys more clever than I am :)



  • Honestly, I do not see a problem with this because you are using reletive paths, so your project "bundle" is moveable :)

    What is the "rubbish" that you normally do that you want to avoid doing?

    I did the following to make all my output go to the same place (just an example of how you can manipulate where things end up...):
    @# Set the output paths
    BUILD_DIR = ../_out
    DESTDIR = $$BUILD_DIR
    OBJECTS_DIR = $$BUILD_DIR
    MOC_DIR = $$BUILD_DIR
    RCC_DIR = $$BUILD_DIR
    UI_DIR = $$BUILD_DIR@

    So maybe in your lib project you can place your .lib more precisely?



  • I don't know, maybe it was the fact that QtCreator's default behaviour (with shadow builds activated) is to create a separate directory for debug and release and then inside each folder, it creates another debug and release sub-folder. Well, this may be true only on Windows but it should at least create one sub-folder:

    @build-MyProject-MyKit-Debug/
    Debug/
    Release/
    build-MyProject-MyKit-Release/
    Debug/
    Release/
    MyProject/@

    I did set all the output paths but finally removed them because I wasn't sure that if someone else checks out the code and deactivates the shadow builds (I know there are many people that don't like this option), I want it to work as well, without "polluting" the source folders. Re-using your example, I think this would be optimal when building outside of the source tree, but would be terrible when building inside it:

    @BUILD_DIR = ./ # removes debug and release folders@

    The other disadvantage that I can see is that dumping everything in the same directory for debug and release is fine as long as you are building in separate folders, but again if you disable those shadow builds it going to create silly debug/release object mixing which everybody really want to avoid.

    I guess there is no solution that handle all cases, is fool-proof and optimal in every cases. The default behaviour seems to be good enough and I think I'm going to stick to it, without defining DESTDIR, OBJECTS_DIR, MOC_DIR, etc.



  • Hi Uflex,

    My internet went down at work so slow reply :(

    Just thought I would add to your comments, which are all very valid. That you can also switch where you want your output files to go dependant on release/debug type of build. I always turn off shadow build and ensure a build path (weather inside or outside the source area) of its own. So you can have:

    @
    DEBUG {
    BUILD_DIR = ./out/debug
    }
    RELEASE {
    BUILD_DIR = ./out/release
    }
    @

    Ok, this code is syntactically incorrect as I am on my laptop and cant remember the exact syntax, but you can do something like that, the .pro file is very powerful to do almost anything you want. You can also do post linker steps and manually move files around etc....

    I setup my project so that it can be put anywhere and always creates the same folder structures, which is useful when lots of people are working on the softare via SVN (or similar)...

    If you have a specific thing you want to do (maybe I missed it) I am fairly sure its possible....


Log in to reply
 

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