I recently came across this issue, too. Splitting the project into subprojects made everything much more complicated, and -at least on my first attempt- flat-out didn't work. Then I tried CONFIG += object_with_source
and CONFIG += object_parallel_to_source
, but both did't seem to work with my Qt version.
So this is how I solved it (for Visual Studio 2010; I don't know if works the same with other versions):
If the project were an ordinary Visual Studio project, not one generated by QMake, you could solve it as described here: Visual Studio 2010 & 2008 can't handle source files with identical names in different folders? (changing the output dir of object files to a relative dir by appending %(RelativeDir)
in the project settings "C/C++" > "Output Files" > "Object File Name").
Obviously, you don't want to do this by hand everytime you create a new Visual Studio project with QMake, so why not automatize it? After all Visual Studio project files are but ordinary XML files. Looking at the diff before and after setting the options reveals it's saved in a single unique tag called ObjectFileName
.
So I wrote this Python script:
import sys
filename = sys.argv[1]
f = open(filename, "r", -1, "utf-8-sig")
lines = f.readlines()
f.close()
f = open(filename, "w", -1, "utf-8-sig")
for line in lines:
line = line.replace("</ObjectFileName>", "%(RelativeDir)\</ObjectFileName>")
f.write(line)
f.close()
..and use it like this in my bat-file that I always call to create the Visual Studio project:
qmake -tp vc myproject.pro
@cd ../scripts
unflatten_vcproj_obj_output.py "../src/myproject.vcxproj"
@pause
Not a beautiful solution, but it works.