THRIFT-2903 Qt4 library built with CMake does not work
diff --git a/cmake/DefineOptions.cmake b/cmake/DefineOptions.cmake
index 6a3a85d..adc750b 100644
--- a/cmake/DefineOptions.cmake
+++ b/cmake/DefineOptions.cmake
@@ -47,7 +47,7 @@
find_package(Libevent QUIET)
CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
"Libevent_FOUND" OFF)
-find_package(Qt4 QUIET)
+find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork)
CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON
"QT4_FOUND" OFF)
find_package(OpenSSL QUIET)
diff --git a/contrib/installCXXDependencies.sh b/contrib/installCXXDependencies.sh
index f34e26b..59a3406 100644
--- a/contrib/installCXXDependencies.sh
+++ b/contrib/installCXXDependencies.sh
@@ -25,5 +25,5 @@
# 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 libqt4-dev git debhelper bc
+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
dpkg -S /usr/include/boost/version.hpp
diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt
index 4f2e451..25b551e 100755
--- a/lib/cpp/CMakeLists.txt
+++ b/lib/cpp/CMakeLists.txt
@@ -172,13 +172,12 @@
TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
endif()
-
if(WITH_QT4)
- find_package(Qt4 REQUIRED)
- include_directories(${QT_INCLUDES})
-
+ cmake_minimum_required(VERSION 2.8.12)
+ set(CMAKE_AUTOMOC ON)
+ find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
- TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${QT_LIBRARIES})
+ TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
endif()
if(MSVC)
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index cb68505..9a7d245 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -47,7 +47,7 @@
add_library(testgencpp STATIC ${testgencpp_SOURCES})
target_link_libraries(testgencpp thrift)
-set(processortest_SOURCES
+set(testgencpp_cob_SOURCES
gen-cpp/ChildService.cpp
gen-cpp/ChildService.h
gen-cpp/ParentService.cpp
@@ -55,6 +55,8 @@
gen-cpp/proc_types.cpp
gen-cpp/proc_types.h
)
+add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
+target_link_libraries(testgencpp_cob thrift)
add_executable(Benchmark Benchmark.cpp)
@@ -182,11 +184,13 @@
set(link_test_SOURCES
link/LinkTest.cpp
+ gen-cpp/ParentService.h
link/TemplatedService1.cpp
link/TemplatedService2.cpp
- gen-cpp/ParentService.h
)
+
add_executable(link_test ${link_test_SOURCES})
+target_link_libraries(concurrency_test testgencpp_cob thrift)
add_test(NAME link_test COMMAND link_test)
if(WITH_LIBEVENT)
@@ -200,6 +204,7 @@
)
add_executable(processor_test ${processor_test_SOURCES})
target_link_libraries(processor_test
+ testgencpp_cob
thrift
thriftnb
${Boost_LIBRARIES}
@@ -217,6 +222,18 @@
add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest)
endif()
+if(WITH_QT4)
+cmake_minimum_required(VERSION 2.8.12)
+set(CMAKE_AUTOMOC ON)
+find_package(Qt4 REQUIRED COMPONENTS QtTest)
+set(TQTcpServerTest_SOURCES
+ qt/TQTcpServerTest.cpp
+)
+add_executable(TQTcpServerTest ${TQTcpServerTest_SOURCES})
+target_link_libraries(TQTcpServerTest testgencpp_cob thriftqt thrift Qt4::QtTest)
+add_test(NAME TQTcpServerTest COMMAND TQTcpServerTest)
+endif()
+
#
# Common thrift code generation rules
#
diff --git a/lib/cpp/test/qt/TQTcpServerTest.cpp b/lib/cpp/test/qt/TQTcpServerTest.cpp
new file mode 100644
index 0000000..79c0dfc
--- /dev/null
+++ b/lib/cpp/test/qt/TQTcpServerTest.cpp
@@ -0,0 +1,89 @@
+#define BOOST_TEST_MODULE TQTcpServerTest
+#include <QTest>
+#include <boost/smart_ptr.hpp>
+#include <iostream>
+
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <QHostAddress>
+
+#include "thrift/protocol/TBinaryProtocol.h"
+#include "thrift/async/TAsyncProcessor.h"
+#include "thrift/qt/TQTcpServer.h"
+#include "thrift/qt/TQIODeviceTransport.h"
+
+#include "gen-cpp/ParentService.h"
+
+using namespace apache::thrift;
+
+struct AsyncHandler : public test::ParentServiceCobSvIf {
+ std::vector<std::string> strings;
+ virtual void addString(tcxx::function<void()> cob, const std::string& s) {
+ strings.push_back(s);
+ cob();
+ }
+ virtual void getStrings(tcxx::function<void(std::vector<std::string> const& _return)> cob) {
+ cob(strings);
+ }
+
+ // Overrides not used in this test
+ virtual void incrementGeneration(tcxx::function<void(int32_t const& _return)> cob) {}
+ virtual void getGeneration(tcxx::function<void(int32_t const& _return)> cob) {}
+ virtual void getDataWait(tcxx::function<void(std::string const& _return)> cob,
+ const int32_t length) {}
+ virtual void onewayWait(tcxx::function<void()> cob) {}
+ virtual void exceptionWait(
+ tcxx::function<void()> cob,
+ tcxx::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */,
+ const std::string& message) {}
+ virtual void unexpectedExceptionWait(tcxx::function<void()> cob, const std::string& message) {}
+};
+
+class TQTcpServerTest : public QObject {
+ void init() {
+ // setup server
+ serverSocket.reset(new QTcpServer);
+ server.reset(new async::TQTcpServer(serverSocket,
+ boost::make_shared<test::ParentServiceAsyncProcessor>(
+ boost::make_shared<AsyncHandler>()),
+ boost::make_shared<protocol::TBinaryProtocolFactory>()));
+ QVERIFY(serverSocket->listen(QHostAddress::LocalHost));
+ int port = serverSocket->serverPort();
+ QVERIFY(port > 0);
+
+ // setup client
+ socket.reset(new QTcpSocket);
+ client.reset(new test::ParentServiceClient(boost::make_shared<protocol::TBinaryProtocol>(
+ boost::make_shared<transport::TQIODeviceTransport>(socket))));
+ socket->connectToHost(QHostAddress::LocalHost, port);
+ QVERIFY(socket->waitForConnected());
+ }
+
+ void cleanup() {
+ socket->close();
+ serverSocket->close();
+ }
+
+ void test_communicate() {
+ client->addString("foo");
+ client->addString("bar");
+
+ std::vector<std::string> reply;
+ client->getStrings(reply);
+ QCOMPARE(reply[0], "foo");
+ QCOMPARE(reply[1], "foo");
+ }
+
+ boost::shared_ptr<QTcpServer> serverSocket;
+ boost::shared_ptr<async::TQTcpServer> server;
+ boost::shared_ptr<QTcpSocket> socket;
+ boost::shared_ptr<test::ParentServiceClient> client;
+};
+
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+QTEST_GUILESS_MAIN(TQTcpServerTest);
+#else
+#undef QT_GUI_LIB
+QTEST_MAIN(TQTcpServerTest);
+#endif
+#include "TQTcpServerTest.moc"