Build subdirs template project



  • I am writing a multiple projects managed by SUBDIRS template, my source code tree:

    / SubdirProject
    ├─ SubdirProject.pro
    ├─ /BarLib
    ├─── BarLib.pro
    ├─── barlib.h
    ├─── barlib_global.h
    ├─── barlib.cpp
    ├─ /FooApp
    └─── main.cpp
    

    I want to build this project to this build tree:

    /build
    ├─ FooApp.exe
    ├─ /lib
    └─── Barlib.dll
    

    however, my actually build tree like this:

    /build
    ├─BarLib
    │  ├─build
    │  │  ├─debug
    │  │  │  ├─ .moc
    │  │  │  ├─ .obj
    │  │  │  └─ Barlib.dll
    │  │  └─release
    │  │  │  ├─ .moc
    │  │  │  ├─ .obj
    │  │  │  └─ Barlib.dll
    │  ├─debug
    │  └─release
    └─FooApp
        ├─build
        │  ├─debug
        │  │  ├─ .moc
        │  │  ├─ .obj
        │  │  └─ FooApp.exe
        │  └─release
        │      ├─.moc
        │      ├─ .obj
        │      └─ FooApp.exe    
        ├─debug
        └─release
    

    Here are my .pro files:
    SubdirProject.pro file

    TEMPLATE = subdirs
    
    SUBDIRS += \
        BarLib \
        FooApp
    
    CONFIG += ordered
    

    Barlib.pro file

    // .. whatever
    
    release: DESTDIR = build/release
    debug:   DESTDIR = build/debug
    
    OBJECTS_DIR = $$DESTDIR/.obj
    MOC_DIR = $$DESTDIR/.moc
    RCC_DIR = $$DESTDIR/.qrc
    UI_DIR = $$DESTDIR/.ui
    

    FooApp.pro file

    // .. whatever
    
    release: DESTDIR = build/release
    debug:   DESTDIR = build/debug
    
    OBJECTS_DIR = $$DESTDIR/.obj
    MOC_DIR = $$DESTDIR/.moc
    RCC_DIR = $$DESTDIR/.qrc
    UI_DIR = $$DESTDIR/.ui
    

    How do I modify my project file that I can make my project be built to the build tree below? Futhermore, I have specify the OBJECT_DIR variable, why there are empty directory created, such as Barlib/release, Barlin/debug, etc ?

    Here is complete code: https://gist.github.com/floatflower/400f9150429a56590f280a0c49ae243f



  • Hi @FloatFlower.Huang

    The additional debug and release folders are created on Windows because on Windows you cannot mix debug and release objects in one executable. Please see https://bugreports.qt.io/browse/QTBUG-52347 for more clarification.

    If you use shadow-building and never mix objects, than you can set CONFIG-=debug_and_release in your pro files and then you get the same behavior on Windows as on Linux or macOS.

    Addional mark: I saw CONFIG += ordered in your top pro file. Don't use it! There are better ways: https://blog.rburchell.com/2013/10/every-time-you-configordered-kitten-dies.html


Log in to reply
 

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