I have run into a problem with how qmake generates the targets for moc files, when I have the same file name in different subdirectories.

For instance, in my .pro file, I have the following:

Qt Code:
  1. DESTDIR = Objs
  2. MOC_DIR = Mocs
  3. UI_DIR = Uics
  4. RCC_DIR = Rccs
  5.  
  6. HEADERS += Images/Types.h
  7. HEADERS += Images/Cache.h
  8. HEADERS += Sounds/Types.h
  9. HEADERS += Sounds/Cache.h
  10.  
  11. SOURCES += Images/Cache.cpp
  12. SOURCES += Sounds/Cache.cpp
  13.  
  14. CONFIG += warn_on staticlib
  15. TEMPLATE = lib
To copy to clipboard, switch view to plain text mode 

The Images/Cache.h and Sounds/Cache.h both include class definitions that inherit from QObject in order to provide signals and slots. When I run qmake on the file, it generates the following for the moc targets inside the Makefile:

Qt Code:
  1. Mocs/moc_Cache.cpp: Images/Types.h \
  2. Images/Cache.h \
  3. /usr/lib/qt4/bin/moc
  4. /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Images/Cache.h -o Mocs/moc_Cache.cpp
  5.  
  6. Mocs/moc_Cache.cpp: Sounds/Types.h \
  7. Sounds/Cache.h \
  8. /usr/lib/qt4/bin/moc
  9. /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Sounds/Cache.h -o Mocs/moc_Cache.cpp
To copy to clipboard, switch view to plain text mode 

This clearly shows a problem, which make warns about when it is run. The moc_Cache.cpp target is generated from two different files. I'm looking for suggestions about whether there might be easy ways to fix the output, or if I need to start having different names for every file in my projects.

Along the way, I did see the "new_moc" example in the qmake advanced configuration section, that would appear to offer a way to fix this, but I was unable to get it to find only the files that should have moc run on them, as opposed to all header files.