THRIFT-2098 Add support for Qt5+
diff --git a/.gitignore b/.gitignore
index 0b7d463..65bb2ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,6 +81,7 @@
/lib/cpp/Release/
/lib/cpp/Release-mt/
/lib/cpp/src/thrift/qt/moc_TQTcpServer.cpp
+/lib/cpp/src/thrift/qt/moc__TQTcpServer.cpp
/lib/cpp/src/thrift/config.h
/lib/cpp/src/thrift/stamp-h2
/lib/cpp/test/Benchmark
diff --git a/cmake/DefineOptions.cmake b/cmake/DefineOptions.cmake
index adc750b..d7144ea 100644
--- a/cmake/DefineOptions.cmake
+++ b/cmake/DefineOptions.cmake
@@ -50,6 +50,13 @@
find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork)
CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON
"QT4_FOUND" OFF)
+find_package(Qt5 QUIET COMPONENTS Core Network)
+CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
+ "Qt5_FOUND" OFF)
+if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3)
+ # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5
+ set(WITH_QT4 OFF)
+endif()
find_package(OpenSSL QUIET)
CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
"OpenSSL_FOUND" OFF)
@@ -95,6 +102,7 @@
message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
message(STATUS " Build with Qt4 support: ${WITH_QT4}")
+message(STATUS " Build with Qt5 support: ${WITH_QT5}")
message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}")
message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}")
message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}")
diff --git a/configure.ac b/configure.ac
index 5b3d186..a53875d 100755
--- a/configure.ac
+++ b/configure.ac
@@ -156,11 +156,26 @@
AC_PATH_PROGS([QT_MOC], [moc-qt4 moc])
have_qt=$success
fi
+
+ AX_THRIFT_LIB(qt5, [Qt5], yes)
+ have_qt5=no
+ qt_reduce_reloc=""
+ if test "$with_qt5" = "yes"; then
+ PKG_CHECK_MODULES([QT5], [Qt5Core >= 5.0, Qt5Network >= 5.0],
+ [have_qt5=yes;qt_reduce_reloc=`$PKG_CONFIG --variable=qt_config Qt5Core | grep "reduce_relocations"`],
+ [have_qt5=no])
+ fi
+ if test "$have_qt5" = "yes"; then
+ AC_PATH_PROGS([QT5_MOC], [moc-qt5 moc])
+ have_qt5=$success
+ fi
fi
AM_CONDITIONAL([WITH_CPP], [test "$have_cpp" = "yes"])
AM_CONDITIONAL([AMX_HAVE_LIBEVENT], [test "$have_libevent" = "yes"])
AM_CONDITIONAL([AMX_HAVE_ZLIB], [test "$have_zlib" = "yes"])
AM_CONDITIONAL([AMX_HAVE_QT], [test "$have_qt" = "yes"])
+AM_CONDITIONAL([AMX_HAVE_QT5], [test "$have_qt5" = "yes"])
+AM_CONDITIONAL([QT5_REDUCE_RELOCATIONS], [test "x$qt_reduce_reloc" != "x"])
AX_THRIFT_LIB(c_glib, [C (GLib)], yes)
if test "$with_c_glib" = "yes"; then
@@ -649,6 +664,7 @@
lib/cpp/thrift-nb.pc
lib/cpp/thrift-z.pc
lib/cpp/thrift-qt.pc
+ lib/cpp/thrift-qt5.pc
lib/cpp/thrift.pc
lib/c_glib/Makefile
lib/c_glib/thrift_c_glib.pc
@@ -726,7 +742,8 @@
echo "C++ Library:"
echo " Build TZlibTransport ...... : $have_zlib"
echo " Build TNonblockingServer .. : $have_libevent"
- echo " Build TQTcpServer (Qt) .... : $have_qt"
+ echo " Build TQTcpServer (Qt4) .... : $have_qt"
+ echo " Build TQTcpServer (Qt5) .... : $have_qt5"
fi
if test "$have_java" = "yes" ; then
echo
diff --git a/contrib/installCXXDependencies.sh b/contrib/installCXXDependencies.sh
index 59a3406..2128da4 100644
--- a/contrib/installCXXDependencies.sh
+++ b/contrib/installCXXDependencies.sh
@@ -21,9 +21,9 @@
# Mainly aiming Travis CI's Ubuntu machines for now
# see what we need: http://thrift.apache.org/docs/install/ubuntu
-
# General dependencies
sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu/ trusty main restricted" -y
sudo apt-get update -qq
-sudo apt-get install -qq libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libboost-thread-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev make cmake libqt4-dev git debhelper bc
+
+sudo apt-get install -qq libpango-1.0-0 libqt4-dev qtbase5-dev qtbase5-dev-tools qt5-default libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libboost-thread-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev make cmake git debhelper bc
dpkg -S /usr/include/boost/version.hpp
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}