Auto moc file generation in Makefile

465 views Asked by At

So i have a pretty standard make file

#!/bin/bash

CXX=g++
CXXFLAGS= -g -Wall

SOURCES=$(wildcard src/*.cpp)
OBJECTS=$(addprefix obj/,$(notdir $(SOURCES:.cpp=.o)))

INCLUDES=-I/usr/include/ -I. -I/usr/include/boost/
LDFLAGS=-L/usr/lib64/
LIBS=-lQtGui -lQtCore

MOC=moc-qt4
UIC=uic-qt4
RM=rm

DEPFILE=.depend
TARGET=Foo

.PHONY=all clean distclean

all: depend $(TARGET)

$(TARGET): $(OBJECTS)
    @echo Linking $@
    $(CXX) $^ $(LDFLAGS) $(LIBS) -o $@

obj/%.o: src/%.cpp
    @echo Compiling $<
    $(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@

ui_%.h: %.ui
    @echo UIC'ing $<
    $(UIC) $< -o $@

src/moc_NodeWindow.cpp: src/NodeWindow.h
    $(MOC) $(CXXFLAGS) $(INCLUDES) $< -o $@

src/moc_NodeEditor.cpp: src/NodeEditor.h
    $(MOC) $(CXXFLAGS) $(INCLUDES) $< -o $@

clean:
    $(RM) $(OBJECTS) src/*~ $(TARGET) $(DEPFILE)

depend: $(DEPFILE)
    @touch $(DEPFILE)

$(DEPFILE):
    @echo Generating dependecies in $@
    @-$(CC) -E -MM $(CFLAGS) $(INCLUDES) $(SOURCES) >> $(DEPFILE)

ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring distclean,$(MAKECMDGOALS)))
-include $(DEP_FILE)
endif
endif

Now I've basically been trying to pick it up as I go along, but I can't get it to automatically compile .cpp file for the ui and moc files.

The rules for the ui and moc files are from the Qt documentation but I'm not sure how to incorporate them into the make all rule.

Any help with what needs to be done?

Cheers

0

There are 0 answers