From ad92d8d9cb1872289f3d4d3c29cef357faacfb89 Mon Sep 17 00:00:00 2001
From: Mathieu L Bouchard <matju@artengine.ca>
Date: Sat, 2 Aug 2014 22:40:08 -0400
Subject: [PATCH] settings for compiling & linking C++/Qt code to Pd

---
 pd/src/configure.in |  2 +-
 pd/src/g_qt.cpp     | 22 ++++++++++++++++++++++
 pd/src/g_qt.h       |  1 +
 pd/src/makefile.in  | 29 +++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 pd/src/g_qt.cpp
 create mode 100644 pd/src/g_qt.h

diff --git a/pd/src/configure.in b/pd/src/configure.in
index edc36d78e..ade5660b1 100644
--- a/pd/src/configure.in
+++ b/pd/src/configure.in
@@ -10,7 +10,7 @@ AC_SUBST(portmidi, no)
 AC_SUBST(binarymode, -m755)
 AC_SUBST(fftw, no)
 AC_SUBST(tk, yes)
-AC_SUBST(qt, yes)
+AC_SUBST(qt, no)
 AC_SUBST(PDLIB)
 AC_SUBST(CPPFLAGS)
 AC_SUBST(MORECFLAGS)
diff --git a/pd/src/g_qt.cpp b/pd/src/g_qt.cpp
new file mode 100644
index 000000000..72ba28b38
--- /dev/null
+++ b/pd/src/g_qt.cpp
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <QtWidgets/QApplication>
+#include "g_qt.h"
+
+int tv_ms_diff (timeval &a, timeval &b) {
+	return (a.tv_sec-b.tv_sec)*1000 + (a.tv_usec-b.tv_usec)/1000;
+}
+
+void qt_thread_main () {
+	int argc=0; char **argv=0;
+    //QApplication app(argc,argv);
+
+	timeval t0,t1;
+	gettimeofday(&t0,0);
+	for (;;) {
+		gettimeofday(&t1,0);
+		fprintf(stderr, "Qt thread running... (%d s)\n", tv_ms_diff(t1,t0));
+		sleep(2);
+	}
+}
diff --git a/pd/src/g_qt.h b/pd/src/g_qt.h
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/pd/src/g_qt.h
@@ -0,0 +1 @@
+
diff --git a/pd/src/makefile.in b/pd/src/makefile.in
index f2e39f567..971b3c4af 100644
--- a/pd/src/makefile.in
+++ b/pd/src/makefile.in
@@ -84,6 +84,10 @@ TYPE_PUNNING_OBJ = $(TYPE_PUNNING_SRC:.c=.o)
 OPT_SAFE_OBJ = $(OPT_SAFE_SRC:.c=.o) 
 OBJ = $(SRC:.c=.o) 
 
+ifeq ($(QTGUI), yes)
+	OBJ += g_qt.moc.o g_qt.o
+endif
+
 GSRC =  @GUISRC@
 
 GOBJ = $(GSRC:.c=.o)
@@ -102,6 +106,16 @@ ifneq ($(PD_TEST_VERSION),)
 	PD_VERSION := $(PD_VERSION)-$(PD_TEST_VERSION)
 endif
 
+# C++/Qt
+CXX = g++
+CXXFLAGS =
+MOC = moc
+QT_INCLUDE = -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore
+ifeq ($(QTGUI),yes)
+  LDFLAGS += -L/usr/lib/i386-linux-gnu
+  LIB += -lQt5Core -lQt5Gui -lQt5Widgets
+endif
+
 #
 #  ------------------ targets ------------------------------------
 #
@@ -126,6 +140,15 @@ $(GOBJ) : %.o : %.c
 $(ASIOOBJ): %.o : %.cpp
 	$(CXX) $(CFLAGS) $(INCLUDE) -c -o $(OBJ_DIR)/$*.o $*.cpp
 
+../obj/g_qt.moc.cpp : g_qt.h
+	$(MOC) $(CPPFLAGS) $(QT_INCLUDE) $< -o ../obj/$@
+
+../obj/g_qt.moc.o : ../obj/g_qt.moc.cpp
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(QT_INCLUDE) -c ../obj/g_qt.moc.cpp -o ../obj/g_qt.moc.o
+
+../obj/g_qt.o : g_qt.cpp
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(QT_INCLUDE) -fPIC -c g_qt.cpp -o ../obj/g_qt.o
+
 pd: $(PDEXEC)
 
 ifneq ($(GSRC),)
@@ -148,8 +171,13 @@ $(BIN_DIR)/pdsend: u_pdsend.c $(BIN_DIR)
 $(BIN_DIR)/pdreceive: u_pdreceive.c $(BIN_DIR)
 	$(CC) $(CFLAGS)  $(STRIPFLAG) -o $(BIN_DIR)/pdreceive u_pdreceive.c
 
+ifeq ($(QTGUI),yes)
+$(PDEXEC): $(OBJ) $(BIN_DIR)
+	cd ../obj;  $(CXX) $(LDFLAGS) $(DBG_CFLAGS) -o $(PDEXEC) $(OBJ) $(LIB)
+else
 $(PDEXEC): $(OBJ) $(BIN_DIR)
 	cd ../obj;  $(CC) $(LDFLAGS) $(DBG_CFLAGS) -o $(PDEXEC) $(OBJ) $(LIB)
+endif
 
 $(BIN_DIR)/pd-gui: $(GOBJ) $(GSRC)
 	cd ../obj; $(CC) $(INCLUDE) -o $(BIN_DIR)/$(GUINAME) $(GOBJ) $(GLIB)
@@ -259,6 +287,7 @@ install: all tkpath tkdnd
 	@echo "Pd install succeeded."
 
 local-clean:	
+	-rm -f -- ../obj/*.moc.cpp
 	-rm -f -- $(OBJ)
 	-rm -f ../obj/* $(PDEXEC) $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \
 	    $(BIN_DIR)/pdreceive $(BIN_DIR)/pd-watchdog m_stamp.c
-- 
GitLab