Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qmake: Avoid file name conflicts in different folders without introducing libraries

Tags:

gnu-make

qt

qmake

I have a project with some folders which happen to 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

Per default, qmake generates a Makefile which will produce a build tree like this:

conflict.o
main.o
target

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

I can't to change their names because they are generated using an external tool and forcing different file names would imply to change their contents, so this is not an option.

I also don't want to use qmake SUBDIRS template because this would imply that (1) every subdir is built separately as a library and thus very much complicate the overall build process (in my eyes at least) and (2) in the top level directory I can't have any source files. Or am I wrong?

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

foo/
    conflict.o

bar/
    conflict.o

main.o
target

Or are there any other solutions neither requiring to rename the source files nor introducing something complicated like static libraries? I just can't believe that Qt didn't solve this (in my eyes simple) problem for years. (I already hat this problem 4 years ago but could rename the files in that project, while here I can't.)

If it's important: I use Qt 4.8 on both Ubuntu with G++ and Windows with mingw32.

like image 653
leemes Avatar asked Nov 01 '12 20:11

leemes


1 Answers

Are you tied to qmake? If not, an alternative could be to use cmake. I just verified 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 a source file in the top level directory (main.cpp). This properly builds the executable - the object files are created in sub directories like

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

cmake also includes support for Qt4, to automatically pull in the required include paths and libraries. It might require some effort to migrate from qmake to cmake, but given the requirements you have I would give it a try.

like image 103
Andreas Fester Avatar answered Oct 19 '22 18:10

Andreas Fester