]> granicus.if.org Git - nethack/commitdiff
Qt 5 vs 6 'moc'
authorPatR <rankin@nethack.org>
Tue, 1 Feb 2022 21:50:12 +0000 (13:50 -0800)
committerPatR <rankin@nethack.org>
Tue, 1 Feb 2022 21:50:12 +0000 (13:50 -0800)
This is an attempt to address the issue of switching from Qt 5 to
Qt 6 or vice versa on Unix without running 'make spotless'.  Various
*.h files (but not all of them) in win/Qt/ are run through a program
called 'moc' to create new files *.moc that are included by *.cpp.
The problem is that the constructed files use the same names for Qt
5 or 6 but their contents apparently aren't compatible.  This adds
rules (specific to GNU make) that use a pair of timestamp files to
track which version of moc made src/*.moc and to destroy them when
switching Qt versions in order to force their re-creation.

As it stands, a hints file which includes hints/include/compiler.370
is now required in order to build the Qt interface with the Unix
Makefiles.  There's no change for platforms that don't use those and
I've no idea whether something comparable could be done for macOS
Xcode IDE.

The first time make is run with WANT_WIN_QT=1 after this is in place,
all the .moc files will be rebuilt and the subset of .cpp files which
include them will be recompiled.  After that, the .moc files will be
rebuilt as needed--and only as needed--just like any other constructed
files.

sys/unix/Makefile.src
sys/unix/hints/include/compiler.370

index e077aad23c45eae7ac82571a1cd1d7625248a140..7d5de09f0e4950dbde505904c1479a9262ee803d 100644 (file)
@@ -670,35 +670,18 @@ objects.o:
        $(CC) $(CFLAGS) -c -o $@ objects.c
        @rm -f $(MAKEDEFS)
 
-# Qt 3 windowport meta-object-compiler output
+# outdated Qt 3 windowport meta-object-compiler output
 qt3_kde0.moc: ../win/Qt3/qt3_kde0.h
        $(QTDIR)/bin/moc -o qt3kde0.moc ../win/Qt3/qt3_kde0.h
 qt3_win.moc: ../win/Qt3/qt3_win.h
        $(QTDIR)/bin/moc -o qt3win.moc ../win/Qt3/qt3_win.h
 qt3tableview.moc: ../win/Qt3/qt3tableview.h
-       $(QTDIR)/bin/moc -o qt3tableview.moc ../win/Qt/qt3tableview.h
-
-# Qt 4 windowport meta-object-compiler output
-qt_kde0.moc : ../win/Qt/qt_kde0.h
-       $(MOCPATH) -o qt_kde0.moc ../win/Qt/qt_kde0.h
-qt_main.moc : ../win/Qt/qt_main.h
-       $(MOCPATH) -o qt_main.moc ../win/Qt/qt_main.h
-qt_map.moc : ../win/Qt/qt_map.h
-       $(MOCPATH) -o qt_map.moc ../win/Qt/qt_map.h
-qt_menu.moc : ../win/Qt/qt_menu.h
-       $(MOCPATH) -o qt_menu.moc ../win/Qt/qt_menu.h
-qt_msg.moc : ../win/Qt/qt_msg.h
-       $(MOCPATH) -o qt_msg.moc ../win/Qt/qt_msg.h
-qt_plsel.moc : ../win/Qt/qt_plsel.h
-       $(MOCPATH) -o qt_plsel.moc ../win/Qt/qt_plsel.h
-qt_set.moc : ../win/Qt/qt_set.h
-       $(MOCPATH) -o qt_set.moc ../win/Qt/qt_set.h
-qt_stat.moc : ../win/Qt/qt_stat.h
-       $(MOCPATH) -o qt_stat.moc ../win/Qt/qt_stat.h
-qt_xcmd.moc : ../win/Qt/qt_xcmd.h
-       $(MOCPATH) -o qt_xcmd.moc ../win/Qt/qt_xcmd.h
-qt_yndlg.moc : ../win/Qt/qt_yndlg.h
-       $(MOCPATH) -o qt_yndlg.moc ../win/Qt/qt_yndlg.h
+       $(QTDIR)/bin/moc -o qt3tableview.moc ../win/Qt3/qt3tableview.h
+
+# for Qt 5 and 6, template rules to build qt_xyz.moc from corresponding
+# ../win/Qt/qt_xyz.h are in sys/unix/hints/compiler.370 and get added
+# to src/Makefile if the appropriate hints file gets used with setup.sh;
+# so, build support for the Qt interface requires the use of hints...
 
 #      build monst.o and objects.o before executing '$(MAKE) makedefs'
 $(MAKEDEFS): $(FIRSTOBJ) \
@@ -775,7 +758,7 @@ spotless: clean
        -rm -f ../include/nhlua.h
        -rm -f ../include/date.h #created but no longer used, at least by core
        -rm -f ../include/onames.h ../include/pm.h #obsolete generated files
-       -rm -f tile.c *.moc
+       -rm -f tile.c *.moc moc.qt*
        -rm -f ../win/gnome/gn_rip.h
 
 package:
index e9f56d0df287066bfaaa5be1d9e3e832c4728b6b..3d2bf3aa109fc7cd9d9179964237e6618c78d914 100755 (executable)
@@ -114,5 +114,27 @@ endif  # clang-specific ends here
 CFLAGS+=-DGCC_WARN
 CCXXFLAGS+=-DGCC_WARN
 
+ifdef MAKEFILE_SRC
+ifdef WANT_WIN_QT
+# when switching from Qt5 to Qt6 or vice versa, any old .moc files will be
+# incompatible; get rid of them in case user hasn't run 'make spotless';
+# moc.qt5 and moc.qt6 are empty timestamp files and at most one should exist
+ifdef WANT_WIN_QT6
+# Qt 6 builds and runs (with a couple of warnings) but needs more testing
+MOCSTAMP=moc.qt6
+else
+# Qt 5 is currently the default version for nethack 3.7.x's Qt interface
+MOCSTAMP=moc.qt5
+endif
+# rule to build src/qt_foo.moc from win/Qt/qt_foo.h
+%.moc : ../win/Qt/%.h $(MOCSTAMP)
+       $(MOCPATH) -o $@ $<
+moc.qt5::
+       @if test ! -f moc.qt5; then ( rm -f *.moc moc.qt6; touch $@ ); fi;
+moc.qt6::
+       @if test ! -f moc.qt6; then ( rm -f *.moc moc.qt5; touch $@ ); fi;
+endif #WANT_WIN_QT
+endif #MAKFILE_SRC
+
 #end of compiler.370
 #------------------------------------------------------------------------------