Qmake: avoid file name conflicts in different folders without entering libraries

I have a project with some folders that contain source files with the same names.

My source tree looks like this:

project.pro foo/ conflict.h conflict.cpp bar/ conflict.h conflict.cpp some.h other.h files.h main.cpp 

By default, qmake creates a Makefile that will generate an assembly tree as follows:

 conflict.o main.o target 

Where conflict.o is the object file obtained for both foo/conflict.cpp and foo/conflict.h .

I can’t change my names because they are generated using an external tool and forcing different file names will mean changing their contents, therefore this is not an option.

I also do not want to use the qmake SUBDIRS template, since this will mean that (1) each subdirectory is created separately as a library and, thus, greatly complicates the general assembly process (at least in my eyes) and (2) in the top-level directory of I cannot have any source files. Or am I wrong?

Can't I just tell qmake to write object files to separate directories in the assembly directory? So my build tree will look like this:

 foo/ conflict.o bar/ conflict.o main.o target 

Or are there any other solutions that do not require renaming the source files or introducing something as complex as static libraries? I just can't believe that Qt has not solved this problem (in my eyes simple) for many years. (I already had this problem 4 years ago, but I can rename the files in this project, but here I cannot.)

If this is important: I am using Qt 4.8 for both Ubuntu with g ++ and Windows using mingw32.

+7
source share
1 answer

Are you attached to qmake ? If not, an alternative could be to use cmake . I just checked your usecase with a simple CMakeLists.txt like

 cmake_minimum_required (VERSION 2.6) project (conflict) add_executable(conflict foo/conflict.cpp bar/conflict.cpp main.cpp) 

which even included the source file in the top-level directory (main.cpp). This correctly creates an executable file - object files are created in subdirectories, for example

 ./CMakeFiles/conflict.dir/main.cpp.o ./CMakeFiles/conflict.dir/bar/conflict.cpp.o ./CMakeFiles/conflict.dir/foo/conflict.cpp.o 

cmake also includes Qt4 support to automatically insert the necessary paths and include libraries. This may take some effort to move from qmake to cmake, but given the requirements that you have, I would try.

+2
source

All Articles