Why does qmake put all object (.o) files to one directory?

随声附和 提交于 2019-11-29 09:05:53
max

You can actually put object files alongside source files by using:

CONFIG += object_parallel_to_source

or

CONFIG += object_with_source

depending on your qmake version.

Source: https://wiki.qt.io/Undocumented_QMake#Config_features

Depending on what you are trying to build, you may be able to use the subdirs template in qmake to do this. You'll need to put a project file in each of your namespace directories, and in this you can specify different output directories for your object files.

-->src/main.pro
  -->namespace1/n1.pro
    -->someclass.cpp
  -->namespace2/n2.pro
    -->someclass.cpp

main.pro:

TEMPLATE = subdirs
SUBDIRS  = namespace1 namespace2

n1.pro and n2.pro:

include("../common.pri")
OBJECTS_DIR = $${PWD}
TARGET = some_target
TEMPLATE = some_qmake_template

common.pri: configurations common to both projects.

Concerning your fears that CMake might be too complicated: I have been working on projects using both build systems. While I agree that qmake is probably easier to begin with, CMake definitely has its merits, too:

  • It makes out-of-source builds very easy. Just execute cmake <Path to source> in your build directory. This is great when your sources are on an NFS share, for example, and you want the object files to be placed on a local file system.

  • Its support for finding additional libraries is very powerful. Lots of FindXXX.cmake files are already shipped with your CMake distribution, making the inclusion of "heavy" libraries such as OpenCV as easy as FIND_PACKAGE(OpenCV REQUIRED).

  • It even has out-of-the-box support for Qt. In fact, I use it for a larger software project where Qt is used for the GUI part. We decided on CMake because we required platform independence and multiple libraries which we could not easily add via qmake.

All in all, use the build system you are comfortable with (as long as your build system does not inhibit your software development).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!