Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qmake creates build artifacts in source directory even when building in out-of-source build directory



  • Hi!

    Can someone explain why qmake creates build artifacts in source directory even when building in out-of-source build directory?

    Given the following directory tree:

    .
    ├── build
    ├── src
    │   ├── app
    │   ├── controller
    │   └── ui
    ├── tests
    │   ├── mock-ui
    │   └── tests
    └── tests-build
        ├── mock-ui
        └── tests
    

    where build is the directory for building source files in src and tests-build is the directory for building sources in tests, and the following tests.pro project file in tests:

    TEMPLATE = subdirs
    CONFIG += ordered
    
    SUBDIRS = \
        mock-ui \
        ../src/controller \
        tests
    
    tests.depends = controller mock-ui
    

    when I run

    cd tests-build
    qmake ../tests
    make check
    

    then controller project build artifacts appear in src/controller instead of tests-build where they should appear.

    Is this because the controller project is outside of the test subdirs project root? How can I fix this?

    Thanks in advance for any tips!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Why is contoller outside of the subdir project ?

    Note that qmake is not cmake, you usually do out of source builds, not "in a folder inside the sources". IIRC, there was an issue with how the paths were generated when inside a subfolder but I'm not 100% sure.



  • @SGaist thanks for the welcome!

    Note that both build directories are outside the sources, so they are already out of source builds:

    .
    ├── build <-- build directory for sources in src
    ├── src
    ├── tests
    └── tests-build <-- build directory for sources in tests
    

    The tests subdirs project is a QTest project for testing controller . controller is a separate static library module that should be unaware of tests, hence it lies outside of tests in src.

    Note that mock-ui and tests build artifacts end up in tests-build as expected, only controller misbehaves.


  • Lifetime Qt Champion

    Can you show the complete structure of your project ?



  • @SGaist sure, here it goes:

    .
    ├── build
    ├── src
    │   ├── app
    │   │   ├── app.pro
    │   │   ├── main.cpp
    │   │   └── parseargs.hpp
    │   ├── common.pri
    │   ├── controller
    │   │   ├── controller.cpp
    │   │   ├── controller.hpp
    │   │   ├── controller.pro
    │   │   └── monitorthread.hpp
    │   ├── ui
    │   │   ├── ui.cpp
    │   │   ├── ui.hpp
    │   │   └── ui.pro
    │   └── foo.pro
    ├── tests
    │   ├── mock-ui
    │   │   ├── mock-ui.cpp
    │   │   ├── mock-ui.hpp
    │   │   └── mock-ui.pro
    │   ├── tests
    │   │   ├── main.cpp
    │   │   └── tests.pro
    │   └── foo-tests.pro
    └── tests-build
    

    Thanks for looking into this!


  • Lifetime Qt Champion

    Are they all separated projects ?


  • Lifetime Qt Champion

    Hi @Mrts,

    usually the SUBDIRS pro file is top-level, i.e. all referenced pro files are below it.

    That gives you one build directory with the same hierarchy as your source folders.

    And please: Don't use CONFIG+=ORDERED!

    Regards

    https://blog.rburchell.com/2013/10/every-time-you-configordered-kitten-dies.html



  • @aha_1980, thanks, I removed CONFIG += ORDERED.

    I prefer to keep tests separate from source, so I guess I have to live with this limitation.


Log in to reply