2

Based on this link, I created a Autotools-based build system that accepts Qt UI and RSC files without the need to call QMAKE.

I however wish to separate the source, headers and ui-files into folders in the the following fashion:

${srcdir}
├── Makefile.am
├── main.cc
├── include
│   └── mainwidget.h
├── src
│   └── mainwidget.cc
└── ui
    └── mainwidget.ui

And have the build directory ordered in the following way

${builddir}
├── include
│   └── ui_mainwidget.h
├── Makefile
├── main.o
├── mainwidget.o
└── moc_mainwidget.o

My Makefile.am currently looks like this:

moc_%.cc: %.h
    @MOC@ -o$@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(MOC_CPPFLAGS) $<

ui_%.h: %.ui
    @UIC@ -o $@ $<

qrc_%.cc: %.qrc
    @RCC@ -o $@ $<

bin_PROGRAMS = qthello
BUILT_SOURCES = ui_mainwidget.h

qthello_CXXFLAGS = -I$(srcdir)/include -I$(builddir)/include
qthello_CPPFLAGS = $(QT_CPPFLAGS)

qthello_LDFLAGS = $(QT_LDFLAGS)
qthello_LDADD = $(QT_LIBS)

qthello_SOURCES =       \
    moc_mainwidget.cc   \
    mainwidget.cc       \
    main.cc

Which works fine if the ui-class files are located in $(srcdir), but simply moving them to the desired directories and changing the expected lines in the Makefile.am does not yeld the desired result. That is, doing these changes does not work:

BUILT_SOURCES = include/ui_mainwidget.h
[ ... ]
qthello_SOURCES =           \
    src/moc_mainwidget.cc   \
    src/mainwidget.cc       \
    main.cc

It occurs to me that some changes have to be made to the build rules to ensure that the include, src, ui -directories exist in $(builddir), and that the correct input files are passed. I am however inexperienced in writing such build rules and google does not seem to have the answer.

Are there any easy portable ways of achieving this?

Tom
  • 414
  • 4
  • 17

1 Answers1

1

So I did eventually find a solution to this thanks to this post.

Following is the final Makefile.am

moc_%.cc: ../include/%.h
    $(MKDIR_P) $(@D)
    @MOC@ -o$@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(MOC_CPPFLAGS) $<

ui_%.h: ../ui/%.ui
    $(MKDIR_P) $(@D)
    @UIC@ -o $@ $<

qrc_%.cc: %.qrc
    $(MKDIR_P) $(@D)
    @RCC@ -o $@ $<

clean-local:
    rm -rf ui/ include/

bin_PROGRAMS = qthello

BUILT_SOURCES =               \
    include/ui_mainwidget.h 

qthello_CXXFLAGS =            \
       -I$(srcdir)/include    \
       -I$(builddir)/include

qthello_CPPFLAGS = $(QT_CPPFLAGS)

qthello_LFLAGS = $(QT_LDFLAGS)
qthello_LDADD = $(QT_LIBS)

qthello_SOURCES =              \
    ui/moc_mainwidget.cc       \
    src/mainwidget.cc          \
    main.cc

Keep in mind that AC_PROG_MKDIR_P must be added to configure.ax.

Community
  • 1
  • 1
Tom
  • 414
  • 4
  • 17
  • 1
    Don't know how general this solution is - building outside of the source tree, etc? - but it's still a really useful Q&A. Builds on the principles of the `COMPILE` macro from `Makefile.in` rules too. Nicely done:) – Brett Hale Apr 12 '16 at 08:14