blob: 83ebe9e6f0fc300311314d4b3024d9a5ec8cef0f [file] [log] [blame]
Pascal Bachd5f87e12014-12-12 15:59:17 +01001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Roger Meier5af78c82015-04-12 21:43:12 +020020
Pascal Bachd5f87e12014-12-12 15:59:17 +010021# Find required packages
22set(Boost_USE_STATIC_LIBS ON) # Force the use of static boost test framework
Ben Craig1684c422015-04-24 08:52:44 -050023find_package(Boost 1.53.0 REQUIRED COMPONENTS chrono system thread unit_test_framework)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090024include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
Pascal Bachd5f87e12014-12-12 15:59:17 +010025
26#Make sure gen-cpp files can be included
27include_directories("${CMAKE_CURRENT_BINARY_DIR}")
28
29# Create the thrift C++ test library
30set(testgencpp_SOURCES
31 gen-cpp/DebugProtoTest_types.cpp
32 gen-cpp/DebugProtoTest_types.h
33 gen-cpp/EnumTest_types.cpp
34 gen-cpp/EnumTest_types.h
35 gen-cpp/OptionalRequiredTest_types.cpp
36 gen-cpp/OptionalRequiredTest_types.h
37 gen-cpp/Recursive_types.cpp
38 gen-cpp/Recursive_types.h
39 gen-cpp/ThriftTest_types.cpp
40 gen-cpp/ThriftTest_types.h
41 gen-cpp/TypedefTest_types.cpp
42 gen-cpp/TypedefTest_types.h
43 ThriftTest_extras.cpp
44 DebugProtoTest_extras.cpp
45)
46
47add_library(testgencpp STATIC ${testgencpp_SOURCES})
48target_link_libraries(testgencpp thrift)
49
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090050set(testgencpp_cob_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +010051 gen-cpp/ChildService.cpp
52 gen-cpp/ChildService.h
Ben Craig1684c422015-04-24 08:52:44 -050053 gen-cpp/EmptyService.cpp
54 gen-cpp/EmptyService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +010055 gen-cpp/ParentService.cpp
56 gen-cpp/ParentService.h
57 gen-cpp/proc_types.cpp
58 gen-cpp/proc_types.h
59)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090060add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
61target_link_libraries(testgencpp_cob thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +010062
63
64add_executable(Benchmark Benchmark.cpp)
65target_link_libraries(Benchmark testgencpp)
66add_test(NAME Benchmark COMMAND Benchmark)
67
68set(UnitTest_SOURCES
69 UnitTestMain.cpp
70 TMemoryBufferTest.cpp
71 TBufferBaseTest.cpp
72 Base64Test.cpp
73 ToStringTest.cpp
74 TypedefTest.cpp
Roger Meier3815e0b2015-04-04 16:26:30 +020075 TServerSocketTest.cpp
Ben Craig1684c422015-04-24 08:52:44 -050076 TServerTransportTest.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010077)
78
79if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS)
80 list(APPEND UnitTest_SOURCES RWMutexStarveTest.cpp)
81endif()
82
83add_executable(UnitTests ${UnitTest_SOURCES})
84target_link_libraries(UnitTests testgencpp thrift ${Boost_LIBRARIES})
85add_test(NAME UnitTests COMMAND UnitTests)
86
Ben Craig1684c422015-04-24 08:52:44 -050087add_executable(TSocketInterruptTest TSocketInterruptTest.cpp)
88target_link_libraries(TSocketInterruptTest
89 testgencpp
90 ${Boost_LIBRARIES}
91 #-lrt
92)
93if (NOT MSVC)
94target_link_libraries(TSocketInterruptTest -lrt)
95endif ()
96add_test(NAME TSocketInterruptTest COMMAND TSocketInterruptTest)
97
98add_executable(TServerIntegrationTest TServerIntegrationTest.cpp)
99target_link_libraries(TServerIntegrationTest
100 testgencpp_cob
101 ${Boost_LIBRARIES}
102)
103if (NOT MSVC)
104target_link_libraries(TServerIntegrationTest -lrt)
105endif ()
106add_test(NAME TServerIntegrationTest COMMAND TServerIntegrationTest)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100107
108if(WITH_ZLIB)
109add_executable(TransportTest TransportTest.cpp)
110target_link_libraries(TransportTest
111 testgencpp
112 thriftz
113 ${Boost_LIBRARIES}
114 ${ZLIB_LIBRARIES}
115)
116add_test(NAME TransportTest COMMAND TransportTest)
117
118add_executable(ZlibTest ZlibTest.cpp)
119target_link_libraries(ZlibTest
120 testgencpp
121 thriftz
122 ${Boost_LIBRARIES}
123 ${ZLIB_LIBRARIES}
124)
125add_test(NAME ZlibTest COMMAND ZlibTest)
126endif(WITH_ZLIB)
127
128
129add_executable(EnumTest EnumTest.cpp)
130target_link_libraries(EnumTest
131 testgencpp
132 ${Boost_LIBRARIES}
133)
134add_test(NAME EnumTest COMMAND EnumTest)
135
136add_executable(TFileTransportTest TFileTransportTest.cpp)
137target_link_libraries(TFileTransportTest
138 testgencpp
139 ${Boost_LIBRARIES}
140)
141add_test(NAME TFileTransportTest COMMAND TFileTransportTest)
142
143add_executable(TFDTransportTest TFDTransportTest.cpp)
144target_link_libraries(TFDTransportTest
145 thrift
146)
147add_test(NAME TFDTransportTest COMMAND TFDTransportTest)
148
149add_executable(TPipedTransportTest TPipedTransportTest.cpp)
150target_link_libraries(TPipedTransportTest
151 thrift
152)
153add_test(NAME TPipedTransportTest COMMAND TPipedTransportTest)
154
155set(AllProtocolsTest_SOURCES
156 AllProtocolTests.cpp
157 AllProtocolTests.tcc
158 GenericHelpers
159 )
160
161add_executable(AllProtocolsTest ${AllProtocolsTest_SOURCES})
162target_link_libraries(AllProtocolsTest
163 testgencpp
164)
165add_test(NAME AllProtocolsTest COMMAND AllProtocolsTest)
166
167add_executable(DebugProtoTest DebugProtoTest.cpp)
168target_link_libraries(DebugProtoTest
169 testgencpp
170)
171add_test(NAME DebugProtoTest COMMAND DebugProtoTest)
172
173add_executable(JSONProtoTest JSONProtoTest.cpp)
174target_link_libraries(JSONProtoTest
175 testgencpp
176)
177add_test(NAME JSONProtoTest COMMAND JSONProtoTest)
178
179add_executable(OptionalRequiredTest OptionalRequiredTest.cpp)
180target_link_libraries(OptionalRequiredTest
181 testgencpp
182)
183add_test(NAME OptionalRequiredTest COMMAND OptionalRequiredTest)
184
185add_executable(RecursiveTest RecursiveTest.cpp)
186target_link_libraries(RecursiveTest
187 testgencpp
188)
189add_test(NAME RecursiveTest COMMAND RecursiveTest)
190
191add_executable(SpecializationTest SpecializationTest.cpp)
192target_link_libraries(SpecializationTest
193 testgencpp
194)
195add_test(NAME SpecializationTest COMMAND SpecializationTest)
196
197set(concurrency_test_SOURCES
198 concurrency/Tests.cpp
199 concurrency/ThreadFactoryTests.h
200 concurrency/ThreadManagerTests.h
201 concurrency/TimerManagerTests.h
202)
203add_executable(concurrency_test ${concurrency_test_SOURCES})
204target_link_libraries(concurrency_test
205 thrift
206)
207add_test(NAME concurrency_test COMMAND concurrency_test)
208
209set(link_test_SOURCES
210 link/LinkTest.cpp
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900211 gen-cpp/ParentService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +0100212 link/TemplatedService1.cpp
213 link/TemplatedService2.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100214)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900215
Pascal Bachd5f87e12014-12-12 15:59:17 +0100216add_executable(link_test ${link_test_SOURCES})
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900217target_link_libraries(concurrency_test testgencpp_cob thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100218add_test(NAME link_test COMMAND link_test)
219
220if(WITH_LIBEVENT)
221set(processor_test_SOURCES
222 processor/ProcessorTest.cpp
223 processor/EventLog.cpp
224 processor/ServerThread.cpp
225 processor/EventLog.h
226 processor/Handlers.h
227 processor/ServerThread.h
228)
229add_executable(processor_test ${processor_test_SOURCES})
230target_link_libraries(processor_test
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900231 testgencpp_cob
Pascal Bachd5f87e12014-12-12 15:59:17 +0100232 thrift
233 thriftnb
234 ${Boost_LIBRARIES}
235)
236add_test(NAME processor_test COMMAND processor_test)
Nobuaki Sukegawa8016af82015-01-02 23:14:22 +0900237
238set(TNonblockingServerTest_SOURCES TNonblockingServerTest.cpp)
239add_executable(TNonblockingServerTest ${TNonblockingServerTest_SOURCES})
240include_directories(${LIBEVENT_INCLUDE_DIRS})
241target_link_libraries(TNonblockingServerTest
242 testgencpp_cob
243 thrift
244 thriftnb
245 ${LIBEVENT_LIBRARIES}
246 ${Boost_LIBRARIES}
247)
248add_test(NAME TNonblockingServerTest COMMAND TNonblockingServerTest)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100249endif()
250
251if(OPENSSL_FOUND AND WITH_OPENSSL)
252add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp)
253target_link_libraries(OpenSSLManualInitTest
254 thrift
255 ${OPENSSL_LIBRARIES}
256 ${Boost_LIBRARIES}
257)
258add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest)
259endif()
260
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900261if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900262set(CMAKE_AUTOMOC ON)
263find_package(Qt4 REQUIRED COMPONENTS QtTest)
264set(TQTcpServerTest_SOURCES
265 qt/TQTcpServerTest.cpp
266)
267add_executable(TQTcpServerTest ${TQTcpServerTest_SOURCES})
268target_link_libraries(TQTcpServerTest testgencpp_cob thriftqt thrift Qt4::QtTest)
269add_test(NAME TQTcpServerTest COMMAND TQTcpServerTest)
270endif()
271
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900272if(WITH_QT5)
273add_subdirectory(qt)
274endif()
275
Pascal Bachd5f87e12014-12-12 15:59:17 +0100276#
277# Common thrift code generation rules
278#
279
280
Ben Craig1684c422015-04-24 08:52:44 -0500281add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +0100282 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
283)
284
285add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h
286 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
287)
288
289add_custom_command(OUTPUT gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h
290 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift
291)
292
293add_custom_command(OUTPUT gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h
294 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
295)
296
297add_custom_command(OUTPUT gen-cpp/Recursive_types.cpp gen-cpp/Recursive_types.h
298 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift
299)
300
301add_custom_command(OUTPUT gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp
302 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
303)
304
305add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h
306 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
307)
308
309add_custom_command(OUTPUT gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h
310 COMMAND thrift-compiler --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
311)