I have a Makefile.am like the following to compile MOC files for Qt using automake.
bin_PROGRAMS = test
test_qtheaders = window.h
test_moc_sources = $(test_qtheaders:.h=_moc.cpp)
test_SOURCES = \
main.cpp \
main-window.cpp \
window.cpp \
$(test_moc_sources)
test_CPPFLAGS = -I/usr/include -I/usr/local/include -I$(QT5_INCL) -I$(QT5_INCL)/QtWidgets -I$(QT5_INCL)/QtCore
test_LDFLAGS = -L/usr/lib64 -L/usr/local/lib64 -L/usr/local/lib -L$(QT5_LIBS)
test_LDADD = -lrt -lQt5Core -lQt5Gui -lQt5Widgets
SUFFIXES = .h _moc.cpp
# this suffix rule is not finding the headers from src/includes/gui
.h_moc.cpp:
$(QT_MOC) -o $@ $(test_CPPFLAGS) $(CPPFLAGS) $<
I get the following error.
make[4]: *** No rule to make target 'window_moc.cpp', needed by 'test-window_moc.o'. Stop.
My directory structure is as follows:
myproj
|- configure.ac
|- Makefile.am
|- ...
` src
|- Makefile.am
|- includes
| `- gui
| |- main-window.h
| `- window.h // file required to generate *.cpp.
|
`- gui
|- Makefile.am
|- main.cpp
|- main-window.cpp
`- window.cpp // output of MOC, does not yet exist.
If I place the main-window.h file in src/gui directory, the MOC will find it and build. Adding the src/includes/gui path to the test_CPPFLAGS doesn't do it. I also tried adding ../../includes/gui/$< to the command, but to no avail.
So my question is, how does one tell the suffix rule where to find a file if it's in an outside directory of the Makefile.am?