THRIFT-2098 Add support for Qt5+
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index 25b551e..7838726 100755
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -180,6 +180,11 @@
     TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
 endif()
 
+if(WITH_QT5)
+    # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
+    add_subdirectory(src/thrift/qt)
+endif()
+
 if(MSVC)
     add_definitions("-DUNICODE -D_UNICODE")
 endif()
diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am
index 857569a..c95b43d 100755
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -22,6 +22,9 @@
 moc_%.cpp: %.h
 	$(QT_MOC) $(QT_CFLAGS) $< -o $@
 
+moc__%.cpp: %.h
+	$(QT5_MOC) $(QT5_CFLAGS) $< -o $@
+
 SUBDIRS = .
 
 if WITH_TESTS
@@ -48,6 +51,10 @@
 lib_LTLIBRARIES += libthriftqt.la
 pkgconfig_DATA += thrift-qt.pc
 endif
+if AMX_HAVE_QT5
+lib_LTLIBRARIES += libthriftqt5.la
+pkgconfig_DATA += thrift-qt5.pc
+endif
 
 AM_CXXFLAGS = -Wall -Wextra -pedantic
 AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(OPENSSL_INCLUDES) -I$(srcdir)/src
@@ -112,16 +119,28 @@
                          src/thrift/qt/TQTcpServer.cpp
 CLEANFILES = $(libthriftqt_la_MOC)
 
+libthriftqt5_la_MOC = src/thrift/qt/moc__TQTcpServer.cpp
+libthriftqt5_la_SOURCES = $(libthriftqt5_la_MOC) \
+                         src/thrift/qt/TQIODeviceTransport.cpp \
+                         src/thrift/qt/TQTcpServer.cpp
+CLEANFILES = $(libthriftqt5_la_MOC)
+
 # Flags for the various libraries
 libthriftnb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBEVENT_CPPFLAGS)
 libthriftz_la_CPPFLAGS  = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS)
 libthriftqt_la_CPPFLAGS = $(AM_CPPFLAGS) $(QT_CFLAGS)
+libthriftqt5_la_CPPFLAGS = $(AM_CPPFLAGS) $(QT5_CFLAGS)
+if QT5_REDUCE_RELOCATIONS
+libthriftqt5_la_CPPFLAGS += -fPIC
+endif
 libthriftnb_la_CXXFLAGS = $(AM_CXXFLAGS)
 libthriftz_la_CXXFLAGS  = $(AM_CXXFLAGS)
 libthriftqt_la_CXXFLAGS  = $(AM_CXXFLAGS)
+libthriftqt5_la_CXXFLAGS  = $(AM_CXXFLAGS)
 libthriftnb_la_LDFLAGS  = -release $(VERSION) $(BOOST_LDFLAGS)
 libthriftz_la_LDFLAGS   = -release $(VERSION) $(BOOST_LDFLAGS)
 libthriftqt_la_LDFLAGS   = -release $(VERSION) $(BOOST_LDFLAGS) $(QT_LIBS)
+libthriftqt5_la_LDFLAGS   = -release $(VERSION) $(BOOST_LDFLAGS) $(QT5_LIBS)
 
 include_thriftdir = $(includedir)/thrift
 include_thrift_HEADERS = \
@@ -242,6 +261,7 @@
              thrift.pc.in \
              thrift-z.pc.in \
              thrift-qt.pc.in \
+             thrift-qt5.pc.in \
              $(WINDOWS_DIST)
 
 style-local:
diff --git a/lib/cpp/src/thrift/qt/CMakeLists.txt b/lib/cpp/src/thrift/qt/CMakeLists.txt
new file mode 100644
index 0000000..1758b3e
--- /dev/null
+++ b/lib/cpp/src/thrift/qt/CMakeLists.txt
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+cmake_minimum_required(VERSION 2.8.12)
+
+set( thriftcppqt5_SOURCES
+    TQIODeviceTransport.cpp
+    TQTcpServer.cpp
+)
+set(CMAKE_AUTOMOC ON)
+find_package(Qt5 REQUIRED COMPONENTS Core Network)
+ADD_LIBRARY_THRIFT(thriftqt5 ${thriftcppqt5_SOURCES})
+TARGET_LINK_LIBRARIES_THRIFT(thriftqt5 Qt5::Core Qt5::Network)
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 9a7d245..b524dd7 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -234,6 +234,10 @@
 add_test(NAME TQTcpServerTest COMMAND TQTcpServerTest)
 endif()
 
+if(WITH_QT5)
+add_subdirectory(qt)
+endif()
+
 #
 # Common thrift code generation rules
 #
diff --git a/lib/cpp/test/qt/CMakeLists.txt b/lib/cpp/test/qt/CMakeLists.txt
new file mode 100644
index 0000000..e899791
--- /dev/null
+++ b/lib/cpp/test/qt/CMakeLists.txt
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+cmake_minimum_required(VERSION 2.8.12)
+
+set(CMAKE_AUTOMOC ON)
+find_package(Qt5 REQUIRED COMPONENTS Test)
+set(TQTcpServerTest_Qt5_SOURCES
+    TQTcpServerTest.cpp
+)
+add_executable(TQTcpServerTest_Qt5 ${TQTcpServerTest_Qt5_SOURCES})
+target_link_libraries(TQTcpServerTest_Qt5 testgencpp_cob thriftqt5 thrift Qt5::Test)
+add_test(NAME TQTcpServerTest_Qt5 COMMAND TQTcpServerTest_Qt5)
+
diff --git a/lib/cpp/thrift-qt5.pc.in b/lib/cpp/thrift-qt5.pc.in
new file mode 100755
index 0000000..a8b1666
--- /dev/null
+++ b/lib/cpp/thrift-qt5.pc.in
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Thrift
+Description: Thrift Qt5 API
+Version: @VERSION@
+Requires: thrift = @VERSION@
+Libs: -L${libdir} -lthriftqt5
+Cflags: -I${includedir}