blob: 13b41c5c6d2333a7140dae4104382a5bc75b1b02 [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
James E. King IIIc9ac8d22019-01-07 16:46:45 -050020# Remove the following once lib/cpp no longer depends on boost headers:
21include(BoostMacros)
22REQUIRE_BOOST_HEADERS()
23
Pascal Bachd5f87e12014-12-12 15:59:17 +010024include_directories(src)
25
cyy8fdb7582019-02-05 02:57:21 +080026if(NOT BUILD_SHARED_LIBS)
27 add_definitions("-DTHRIFT_STATIC_DEFINE")
28endif()
29
Pascal Bachd5f87e12014-12-12 15:59:17 +010030# Create the thrift C++ library
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +020031set(thriftcpp_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +010032 src/thrift/TApplicationException.cpp
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020033 src/thrift/TOutput.cpp
Jim King79c99112015-04-30 07:10:08 -040034 src/thrift/async/TAsyncChannel.cpp
Stefan Bolus9edecce2018-06-06 20:32:52 +020035 src/thrift/async/TAsyncProtocolProcessor.cpp
ben-craig02bade12015-07-17 08:40:48 -050036 src/thrift/async/TConcurrentClientSyncInfo.h
37 src/thrift/async/TConcurrentClientSyncInfo.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010038 src/thrift/concurrency/ThreadManager.cpp
39 src/thrift/concurrency/TimerManager.cpp
Jim King79c99112015-04-30 07:10:08 -040040 src/thrift/processor/PeekProcessor.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050041 src/thrift/protocol/TBase64Utils.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010042 src/thrift/protocol/TDebugProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010043 src/thrift/protocol/TJSONProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010044 src/thrift/protocol/TMultiplexedProtocol.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050045 src/thrift/protocol/TProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010046 src/thrift/transport/TTransportException.cpp
47 src/thrift/transport/TFDTransport.cpp
48 src/thrift/transport/TSimpleFileTransport.cpp
49 src/thrift/transport/THttpTransport.cpp
50 src/thrift/transport/THttpClient.cpp
51 src/thrift/transport/THttpServer.cpp
52 src/thrift/transport/TSocket.cpp
53 src/thrift/transport/TSocketPool.cpp
54 src/thrift/transport/TServerSocket.cpp
55 src/thrift/transport/TTransportUtils.cpp
56 src/thrift/transport/TBufferTransports.cpp
David Suárez4750f362020-09-09 15:49:37 +020057 src/thrift/transport/SocketCommon.cpp
Jim King5ec805b2015-04-26 07:52:40 -040058 src/thrift/server/TConnectedClient.cpp
Jim King21b68522015-04-26 18:30:26 -040059 src/thrift/server/TServerFramework.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010060 src/thrift/server/TSimpleServer.cpp
61 src/thrift/server/TThreadPoolServer.cpp
62 src/thrift/server/TThreadedServer.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010063)
64
Mario Emmenlauer3db41fa2017-04-07 23:24:07 +020065# These files don't work on Windows CE as there is no pipe support
Jim King9de9b1f2015-04-30 16:03:34 -040066# TODO: These files won't work with UNICODE support on windows. If fixed this can be re-added.
Pascal Bachd5f87e12014-12-12 15:59:17 +010067if (NOT WINCE)
68 list(APPEND thriftcpp_SOURCES
69 src/thrift/transport/TPipe.cpp
70 src/thrift/transport/TPipeServer.cpp
71 src/thrift/transport/TFileTransport.cpp
72 )
73endif()
74
75
Mario Emmenlauer3db41fa2017-04-07 23:24:07 +020076if (WIN32)
Pascal Bachd5f87e12014-12-12 15:59:17 +010077 list(APPEND thriftcpp_SOURCES
78 src/thrift/windows/TWinsockSingleton.cpp
79 src/thrift/windows/SocketPair.cpp
80 src/thrift/windows/GetTimeOfDay.cpp
81 src/thrift/windows/WinFcntl.cpp
82 )
83 if(NOT WINCE)
84 # This file uses pipes so it currently won't work on Windows CE
85 list(APPEND thriftcpp_SOURCES
86 src/thrift/windows/OverlappedSubmissionThread.cpp
87 )
88 endif()
Ben Craig7207c222015-07-06 08:40:35 -050089else()
90 # These files evaluate to nothing on Windows, so omit them from the
91 # Windows build
92 list(APPEND thriftcpp_SOURCES
93 src/thrift/VirtualProfiling.cpp
94 src/thrift/server/TServer.cpp
95 )
Pascal Bachd5f87e12014-12-12 15:59:17 +010096endif()
97
James E. King III17355422019-01-11 23:06:08 -050098# If OpenSSL is not found or disabled just ignore the OpenSSL stuff
Pascal Bachd5f87e12014-12-12 15:59:17 +010099if(OPENSSL_FOUND AND WITH_OPENSSL)
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200100 list(APPEND thriftcpp_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +0100101 src/thrift/transport/TSSLSocket.cpp
102 src/thrift/transport/TSSLServerSocket.cpp
Kevin Wojniak2853af22021-10-20 20:56:29 -0700103 src/thrift/transport/TWebSocketServer.h
104 src/thrift/transport/TWebSocketServer.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100105 )
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200106 if(TARGET OpenSSL::SSL OR TARGET OpenSSL::Crypto)
107 if(TARGET OpenSSL::SSL)
108 list(APPEND SYSLIBS OpenSSL::SSL)
109 endif()
110 if(TARGET OpenSSL::Crypto)
111 list(APPEND SYSLIBS OpenSSL::Crypto)
112 endif()
113 else()
114 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
115 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
116 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100117endif()
118
cyyca8af9b2019-01-11 22:13:12 +0800119if(UNIX)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900120 if(ANDROID)
121 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
122 else()
123 list(APPEND SYSLIBS pthread)
124 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100125endif()
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200126
127set(thriftcpp_threads_SOURCES
cyyca8af9b2019-01-11 22:13:12 +0800128 src/thrift/concurrency/ThreadFactory.cpp
129 src/thrift/concurrency/Thread.cpp
130 src/thrift/concurrency/Monitor.cpp
131 src/thrift/concurrency/Mutex.cpp
132)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100133
134# Thrift non blocking server
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200135set(thriftcppnb_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +0100136 src/thrift/server/TNonblockingServer.cpp
Divya Thaluru808d1432017-08-06 16:36:36 -0700137 src/thrift/transport/TNonblockingServerSocket.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100138 src/thrift/async/TEvhttpServer.cpp
139 src/thrift/async/TEvhttpClientChannel.cpp
140)
141
cyy13e6f9e2019-12-12 21:13:31 +0800142# If OpenSSL is not found or disabled just ignore the OpenSSL stuff
143if(OPENSSL_FOUND AND WITH_OPENSSL)
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200144 list(APPEND thriftcppnb_SOURCES
cyy13e6f9e2019-12-12 21:13:31 +0800145 src/thrift/transport/TNonblockingSSLServerSocket.cpp
146 )
147endif()
148
James E. King III17355422019-01-11 23:06:08 -0500149# Thrift zlib transport
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200150set(thriftcppz_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +0100151 src/thrift/transport/TZlibTransport.cpp
Dave Watson792db4e2015-01-16 11:22:01 -0800152 src/thrift/protocol/THeaderProtocol.cpp
153 src/thrift/transport/THeaderTransport.cpp
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900154 src/thrift/protocol/THeaderProtocol.cpp
155 src/thrift/transport/THeaderTransport.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100156)
157
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200158# Contains the thrift specific ADD_LIBRARY_THRIFT macro
Pascal Bachd5f87e12014-12-12 15:59:17 +0100159include(ThriftMacros)
160
161ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200162target_link_libraries(thrift PUBLIC ${SYSLIBS})
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100163if(WIN32)
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200164 target_link_libraries(thrift PUBLIC ws2_32)
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100165endif()
Joel 'Aaron' Cohen12319302019-01-25 10:42:54 -0500166ADD_PKGCONFIG_THRIFT(thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100167
168if(WITH_LIBEVENT)
Tobias Mayerc8e46cf2020-02-16 10:36:11 +0100169 find_package(Libevent REQUIRED) # Libevent comes with CMake support from upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900170 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100171
172 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200173 target_link_libraries(thriftnb PUBLIC thrift)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +0100174 if(TARGET libevent::core AND TARGET libevent::extra)
175 # libevent was found via its cmake config, use modern style targets
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200176 target_link_libraries(thriftnb PUBLIC libevent::core libevent::extra)
Mario Emmenlauer7553fc52020-11-19 15:19:23 +0100177 else()
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200178 target_link_libraries(thriftnb PUBLIC ${LIBEVENT_LIBRARIES})
Mario Emmenlauer7553fc52020-11-19 15:19:23 +0100179 endif()
Joel 'Aaron' Cohen12319302019-01-25 10:42:54 -0500180 ADD_PKGCONFIG_THRIFT(thrift-nb)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100181endif()
182
183if(WITH_ZLIB)
184 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900185 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100186
187 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Mario Emmenlauerbdb54bc2021-08-31 14:00:16 +0200188 target_link_libraries(thriftz PUBLIC thrift)
189 target_link_libraries(thriftz PUBLIC ${ZLIB_LIBRARIES})
Joel 'Aaron' Cohen12319302019-01-25 10:42:54 -0500190 ADD_PKGCONFIG_THRIFT(thrift-z)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100191endif()
192
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900193if(WITH_QT5)
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900194 add_subdirectory(src/thrift/qt)
Joel 'Aaron' Cohen12319302019-01-25 10:42:54 -0500195 ADD_PKGCONFIG_THRIFT(thrift-qt5)
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900196endif()
197
Pascal Bachd5f87e12014-12-12 15:59:17 +0100198if(MSVC)
199 add_definitions("-DUNICODE -D_UNICODE")
200endif()
201
Pascal Bachd5f87e12014-12-12 15:59:17 +0100202# Install the headers
203install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
204 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
205# Copy config.h file
206install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
207 FILES_MATCHING PATTERN "*.h")
208
209if(BUILD_TESTING)
210 add_subdirectory(test)
211endif()