Let's say I have a Qt application where I have two classes with the same name in two different namespaces:
namespace namespace1
{
class SomeClass;
}
namespace namespace2
{
class SomeClass;
}
and I have a project directory structure according to it:
-->src/
-->namespace1/
-->someclass.cpp
-->namespace2/
-->someclass.cpp
When I compile the application with qmake, it puts all object (.o) files to one directory - so it creates someclass.o file first and then it rewrites it with the second someclass.o - which is a name collision so it is bad.
Why does qmake not take into account the directory structure of the source files and why does it not create something like namespace1_someclass.o and namespace2_someclass.o?
Yes, I can put my classes to one directory and name them namespace1_someclass.cpp and namespace2_someclass.cpp and there will be no name collisions, but this causes little inconvenience while looking at the source files in the project explorer in Qt Creator because when there are lot of source files in the project, it is much less readable than if there was the directory structure which I can expand or collapse.
One more extreme is to have the directory structure like this:
-->src/
-->namespace1/
-->namespace1_someclass.cpp
-->namespace2/
-->namespace2_someclass.cpp
which solves name collision but it redundantly duplicates the namespace names - and therefore again less readable.
Why does qmake not have at least an option to put the object files to the directory structure according to the source files? Do creators of Qt not see that this is an important feature?
And one more thing - you could recommend me to use cmake tool instead of qmake but I see the use of cmake much much much more difficult than qmake and qmake does its job excellent for me so far - except object files placement.
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 yournamespace
directories, and in this you can specify different output directories for your object files.main.pro
:n1.pro
andn2.pro
: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 thatqmake
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 yourCMake
distribution, making the inclusion of "heavy" libraries such asOpenCV
as easy asFIND_PACKAGE(OpenCV REQUIRED)
.It even has out-of-the-box support for
Qt
. In fact, I use it for a larger software project whereQt
is used for the GUI part. We decided onCMake
because we required platform independence and multiple libraries which we could not easily add viaqmake
.All in all, use the build system you are comfortable with (as long as your build system does not inhibit your software development).