Makefile中自动生成moc文件

时间:2015-06-14 22:33:55

标签: c++ qt makefile g++ moc

所以我有一个非常标准的制作文件

#!/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

现在我已经基本上一直在试图接受它,但是我无法自动编译uc和moc文件的.cpp文件。

ui和moc文件的规则来自Qt文档,但我不确定如何将它们合并到make all规则中。

对需要做什么的任何帮助?

干杯

0 个答案:

没有答案