blob: 33cefcb1bd4c9fa41d12f8695bdf6b29831a38ba [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
Pascal Bachd5f87e12014-12-12 15:59:17 +010020# Find required packages
Nobuaki Sukegawa28256642014-12-16 03:24:37 +090021if(WITH_BOOSTTHREADS)
22 find_package(Boost 1.53.0 REQUIRED COMPONENTS system thread)
23else()
24 find_package(Boost 1.53.0 REQUIRED)
25endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010026
Jim King9de9b1f2015-04-30 16:03:34 -040027include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
Pascal Bachd5f87e12014-12-12 15:59:17 +010028include_directories(src)
29
30# SYSLIBS contains libraries that need to be linked to all lib targets
31set(SYSLIBS "")
32
33# Create the thrift C++ library
34set( thriftcpp_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +010035 src/thrift/TApplicationException.cpp
Konrad Grochowski24ea0bf2015-05-07 14:59:29 +020036 src/thrift/TOutput.cpp
Jim King79c99112015-04-30 07:10:08 -040037 src/thrift/async/TAsyncChannel.cpp
ben-craig02bade12015-07-17 08:40:48 -050038 src/thrift/async/TConcurrentClientSyncInfo.h
39 src/thrift/async/TConcurrentClientSyncInfo.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010040 src/thrift/concurrency/ThreadManager.cpp
41 src/thrift/concurrency/TimerManager.cpp
42 src/thrift/concurrency/Util.cpp
Jim King79c99112015-04-30 07:10:08 -040043 src/thrift/processor/PeekProcessor.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050044 src/thrift/protocol/TBase64Utils.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010045 src/thrift/protocol/TDebugProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010046 src/thrift/protocol/TJSONProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010047 src/thrift/protocol/TMultiplexedProtocol.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050048 src/thrift/protocol/TProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010049 src/thrift/transport/TTransportException.cpp
50 src/thrift/transport/TFDTransport.cpp
51 src/thrift/transport/TSimpleFileTransport.cpp
52 src/thrift/transport/THttpTransport.cpp
53 src/thrift/transport/THttpClient.cpp
54 src/thrift/transport/THttpServer.cpp
55 src/thrift/transport/TSocket.cpp
56 src/thrift/transport/TSocketPool.cpp
57 src/thrift/transport/TServerSocket.cpp
58 src/thrift/transport/TTransportUtils.cpp
59 src/thrift/transport/TBufferTransports.cpp
Jim King5ec805b2015-04-26 07:52:40 -040060 src/thrift/server/TConnectedClient.cpp
Jim King21b68522015-04-26 18:30:26 -040061 src/thrift/server/TServerFramework.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010062 src/thrift/server/TSimpleServer.cpp
63 src/thrift/server/TThreadPoolServer.cpp
64 src/thrift/server/TThreadedServer.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010065)
66
67# This files don't work on Windows CE as there is no pipe support
Jim King9de9b1f2015-04-30 16:03:34 -040068# 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 +010069if (NOT WINCE)
70 list(APPEND thriftcpp_SOURCES
71 src/thrift/transport/TPipe.cpp
72 src/thrift/transport/TPipeServer.cpp
73 src/thrift/transport/TFileTransport.cpp
74 )
75endif()
76
77
78if (WIN32)
79 list(APPEND thriftcpp_SOURCES
80 src/thrift/windows/TWinsockSingleton.cpp
81 src/thrift/windows/SocketPair.cpp
82 src/thrift/windows/GetTimeOfDay.cpp
83 src/thrift/windows/WinFcntl.cpp
84 )
85 if(NOT WINCE)
86 # This file uses pipes so it currently won't work on Windows CE
87 list(APPEND thriftcpp_SOURCES
88 src/thrift/windows/OverlappedSubmissionThread.cpp
89 )
90 endif()
Ben Craig7207c222015-07-06 08:40:35 -050091else()
92 # These files evaluate to nothing on Windows, so omit them from the
93 # Windows build
94 list(APPEND thriftcpp_SOURCES
95 src/thrift/VirtualProfiling.cpp
96 src/thrift/server/TServer.cpp
97 )
Pascal Bachd5f87e12014-12-12 15:59:17 +010098endif()
99
100# If OpenSSL is not found just ignore the OpenSSL stuff
101find_package(OpenSSL)
102if(OPENSSL_FOUND AND WITH_OPENSSL)
103 list( APPEND thriftcpp_SOURCES
104 src/thrift/transport/TSSLSocket.cpp
105 src/thrift/transport/TSSLServerSocket.cpp
106 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900107 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100108 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
109endif()
110
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900111# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100112if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100113 set( thriftcpp_threads_SOURCES
114 src/thrift/concurrency/BoostThreadFactory.cpp
115 src/thrift/concurrency/BoostMonitor.cpp
116 src/thrift/concurrency/BoostMutex.cpp
117 )
118 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
119elseif(UNIX AND NOT WITH_STDTHREADS)
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 +0100125 set( thriftcpp_threads_SOURCES
126 src/thrift/concurrency/PosixThreadFactory.cpp
127 src/thrift/concurrency/Mutex.cpp
128 src/thrift/concurrency/Monitor.cpp
129 )
130else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900131 if(UNIX)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900132 if(ANDROID)
133 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
134 else()
135 list(APPEND SYSLIBS pthread)
136 endif()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900137 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100138 set( thriftcpp_threads_SOURCES
139 src/thrift/concurrency/StdThreadFactory.cpp
140 src/thrift/concurrency/StdMutex.cpp
141 src/thrift/concurrency/StdMonitor.cpp
142 )
143endif()
144
145# Thrift non blocking server
146set( thriftcppnb_SOURCES
147 src/thrift/server/TNonblockingServer.cpp
148 src/thrift/async/TAsyncProtocolProcessor.cpp
149 src/thrift/async/TEvhttpServer.cpp
150 src/thrift/async/TEvhttpClientChannel.cpp
151)
152
153# Thrift zlib server
154set( thriftcppz_SOURCES
155 src/thrift/transport/TZlibTransport.cpp
Dave Watson792db4e2015-01-16 11:22:01 -0800156 src/thrift/protocol/THeaderProtocol.cpp
157 src/thrift/transport/THeaderTransport.cpp
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900158 src/thrift/protocol/THeaderProtocol.cpp
159 src/thrift/transport/THeaderTransport.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100160)
161
162# Thrift Qt4 server
163set( thriftcppqt_SOURCES
164 src/thrift/qt/TQIODeviceTransport.cpp
165 src/thrift/qt/TQTcpServer.cpp
166)
167
168# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
169include(ThriftMacros)
170
171ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100172if(WIN32)
173 TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS} ws2_32)
174else()
175 TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
176endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100177
178if(WITH_LIBEVENT)
179 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900180 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100181
182 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400183 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${LIBEVENT_LIBRARIES})
184 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftnb thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100185endif()
186
187if(WITH_ZLIB)
188 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900189 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100190
191 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400192 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
193 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftz thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100194endif()
195
Pascal Bachd5f87e12014-12-12 15:59:17 +0100196if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900197 set(CMAKE_AUTOMOC ON)
198 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100199 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400200 TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
201 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftqt thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100202endif()
203
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900204if(WITH_QT5)
205 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
206 add_subdirectory(src/thrift/qt)
207endif()
208
Pascal Bachd5f87e12014-12-12 15:59:17 +0100209if(MSVC)
210 add_definitions("-DUNICODE -D_UNICODE")
211endif()
212
Jim King79c99112015-04-30 07:10:08 -0400213add_definitions("-D__STDC_LIMIT_MACROS")
214
Pascal Bachd5f87e12014-12-12 15:59:17 +0100215# Install the headers
216install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
217 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
218# Copy config.h file
219install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
220 FILES_MATCHING PATTERN "*.h")
221
222if(BUILD_TESTING)
223 add_subdirectory(test)
224endif()