[PATCH 2/2] Ensure that uic is always run before any C++ source is compiled

Thiago Macieira thiago at macieira.org
Thu Oct 3 15:38:50 UTC 2013


It's very, very hard to scan for dependencies with a plain make. So
let's give up and simply enforce that all *.ui files need to be
processed before a *.cpp gets compiled.

This introduces the make target "uicables" (similar to the "mocables"
target that qmake produces) that will compile all .ui files. This
target is now a dependency of all .cpp builds.

In addition, tell make where to find .ui files and their corresponding
ui_*.h files.

Signed-off-by: Thiago Macieira <thiago at macieira.org>
---
 Makefile | 13 ++++++++++++-
 Rules.mk | 27 +++++++++++++++------------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index 1e193eb..2946692 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,18 @@ SOURCES = \
 	main.cpp \
 	$(RESFILE)
 
+FORMS = \
+	qt-ui/about.ui \
+	qt-ui/divecomputermanagementdialog.ui \
+	qt-ui/diveplanner.ui \
+	qt-ui/downloadfromdivecomputer.ui \
+	qt-ui/maintab.ui \
+	qt-ui/mainwindow.ui \
+	qt-ui/preferences.ui \
+	qt-ui/printoptions.ui \
+	qt-ui/renumber.ui \
+	qt-ui/subsurfacewebservices.ui \
+	qt-ui/tableview.ui
 
 RESOURCES = $(NAME).qrc
 
@@ -155,7 +167,6 @@ MSGLANGS=$(notdir $(wildcard po/*.po))
 # Add files to the following variables if the auto-detection based on the
 # filename fails
 OBJS_NEEDING_MOC =
-OBJS_NEEDING_UIC =
 HEADERS_NEEDING_MOC =
 
 include Rules.mk
diff --git a/Rules.mk b/Rules.mk
index 4329bae..4cb5e19 100644
--- a/Rules.mk
+++ b/Rules.mk
@@ -38,6 +38,11 @@ MOC_OBJS = $(HEADERS_NEEDING_MOC:.h=.moc.o)
 
 ALL_OBJS = $(OBJS) $(MOC_OBJS)
 
+# handling of uic
+UIC_HEADERS = $(patsubst %.ui, ui_%.h, $(subst qt-ui/,,$(FORMS)))
+vpath %.ui qt-ui
+vpath ui_%.h .uic
+
 # Files for using Qt Creator
 CREATOR_FILES = $(NAME).config $(NAME).creator $(NAME).files $(NAME).includes
 
@@ -47,6 +52,8 @@ $(TARGET): gen_version_file $(ALL_OBJS) $(MSGOBJS) $(INFOPLIST)
 	@$(PRETTYECHO) '    LINK' $(TARGET)
 	$(COMPILE_PREFIX)$(CXX) $(LDFLAGS) -o $(TARGET) $(ALL_OBJS) $(LIBS)
 
+uicables: $(UIC_HEADERS)
+
 gen_version_file $(VERSION_FILE):
 ifneq ($(STORED_VERSION_STRING),$(VERSION_STRING))
 	$(info updating $(VERSION_FILE) to $(VERSION_STRING))
@@ -178,10 +185,10 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $
 	@mkdir -p .dep/$(@D)
 	$(COMPILE_PREFIX)$(CC) $(CFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<
 
-%.o: %.cpp
+%.o: %.cpp uicables
 	@$(PRETTYECHO) '    CXX' $<
 	@mkdir -p .dep/$(@D)
-	$(COMPILE_PREFIX)$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -MD -MF .dep/$@.dep -c -o $@ $<
+	$(COMPILE_PREFIX)$(CXX) $(CXXFLAGS) $(EXTRA_FLAGS) -I.uic -Iqt-ui -MD -MF .dep/$@.dep -c -o $@ $<
 
 # This rule is for running the moc on QObject subclasses defined in the .h
 # files.
@@ -203,16 +210,12 @@ MOCFLAGS = $(filter -I%, $(CXXFLAGS) $(EXTRA_FLAGS)) $(filter -D%, $(CXXFLAGS) $
 %.qrc:
 
 # This creates the ui headers.
-ui_%.h: %.ui
+ui_%.h: %.ui .uic
 	@$(PRETTYECHO) '    UIC' $<
-	$(COMPILE_PREFIX)$(UIC) $< -o $@
+	$(COMPILE_PREFIX)$(UIC) $< -o .uic/$@
 
-# This forces the creation of ui headers with the wrong path
-# This is required because the -MG option to the compiler outputs
-# unknown files with no path prefix
-ui_%.h: qt-ui/%.ui
-	@$(PRETTYECHO) '    UIC' $<
-	$(COMPILE_PREFIX)$(UIC) $< -o qt-ui/$@
+.uic:
+	$(COMPILE_PREFIX)mkdir $@
 
 share/locale/%.UTF-8/LC_MESSAGES/$(NAME).mo: po/%.po po/%.aliases
 	@$(PRETTYECHO) '    MSGFMT' $*.po
@@ -242,13 +245,13 @@ doc:
 
 clean:
 	rm -f $(ALL_OBJS) *~ $(NAME) $(NAME).exe po/*~ po/$(NAME)-new.pot \
-		$(VERSION_FILE) $(HEADERS_NEEDING_MOC:.h=.moc) *.moc qt-ui/*.moc qt-ui/ui_*.h
+		$(VERSION_FILE) $(HEADERS_NEEDING_MOC:.h=.moc) *.moc qt-ui/*.moc .uic/*.h
 	rm -f $(RESOURCES:.qrc=.qrc.cpp)
 	rm -rf share
 
 confclean: clean
 	rm -f $(CONFIGFILE)
-	rm -rf .dep
+	rm -rf .dep .uic
 
 distclean: confclean
 	rm -f $(CREATOR_FILES)
-- 
1.7.11.7



More information about the subsurface mailing list