blob: b97e356c216d1b49b2655a22821ee007b86e8090 [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
Pascal Bachd5f87e12014-12-12 15:59:17 +010038 src/thrift/concurrency/ThreadManager.cpp
39 src/thrift/concurrency/TimerManager.cpp
40 src/thrift/concurrency/Util.cpp
Jim King79c99112015-04-30 07:10:08 -040041 src/thrift/processor/PeekProcessor.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010042 src/thrift/protocol/TDebugProtocol.cpp
43 src/thrift/protocol/TDenseProtocol.cpp
44 src/thrift/protocol/TJSONProtocol.cpp
45 src/thrift/protocol/TBase64Utils.cpp
46 src/thrift/protocol/TMultiplexedProtocol.cpp
47 src/thrift/transport/TTransportException.cpp
48 src/thrift/transport/TFDTransport.cpp
49 src/thrift/transport/TSimpleFileTransport.cpp
50 src/thrift/transport/THttpTransport.cpp
51 src/thrift/transport/THttpClient.cpp
52 src/thrift/transport/THttpServer.cpp
53 src/thrift/transport/TSocket.cpp
54 src/thrift/transport/TSocketPool.cpp
55 src/thrift/transport/TServerSocket.cpp
56 src/thrift/transport/TTransportUtils.cpp
57 src/thrift/transport/TBufferTransports.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
65# This 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
76if (WIN32)
77 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
98# If OpenSSL is not found just ignore the OpenSSL stuff
99find_package(OpenSSL)
100if(OPENSSL_FOUND AND WITH_OPENSSL)
101 list( APPEND thriftcpp_SOURCES
102 src/thrift/transport/TSSLSocket.cpp
103 src/thrift/transport/TSSLServerSocket.cpp
104 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900105 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100106 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
107endif()
108
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900109# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100110if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100111 set( thriftcpp_threads_SOURCES
112 src/thrift/concurrency/BoostThreadFactory.cpp
113 src/thrift/concurrency/BoostMonitor.cpp
114 src/thrift/concurrency/BoostMutex.cpp
115 )
116 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
117elseif(UNIX AND NOT WITH_STDTHREADS)
118 list(APPEND SYSLIBS pthread)
119 set( thriftcpp_threads_SOURCES
120 src/thrift/concurrency/PosixThreadFactory.cpp
121 src/thrift/concurrency/Mutex.cpp
122 src/thrift/concurrency/Monitor.cpp
123 )
124else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900125 if(UNIX)
126 # need pthread for multi-thread support
127 list(APPEND SYSLIBS pthread)
128 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100129 set( thriftcpp_threads_SOURCES
130 src/thrift/concurrency/StdThreadFactory.cpp
131 src/thrift/concurrency/StdMutex.cpp
132 src/thrift/concurrency/StdMonitor.cpp
133 )
134endif()
135
136# Thrift non blocking server
137set( thriftcppnb_SOURCES
138 src/thrift/server/TNonblockingServer.cpp
139 src/thrift/async/TAsyncProtocolProcessor.cpp
140 src/thrift/async/TEvhttpServer.cpp
141 src/thrift/async/TEvhttpClientChannel.cpp
142)
143
144# Thrift zlib server
145set( thriftcppz_SOURCES
146 src/thrift/transport/TZlibTransport.cpp
147)
148
149# Thrift Qt4 server
150set( thriftcppqt_SOURCES
151 src/thrift/qt/TQIODeviceTransport.cpp
152 src/thrift/qt/TQTcpServer.cpp
153)
154
155# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
156include(ThriftMacros)
157
158ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
159TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
160
161if(WITH_LIBEVENT)
162 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900163 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100164
165 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400166 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${LIBEVENT_LIBRARIES})
167 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftnb thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100168endif()
169
170if(WITH_ZLIB)
171 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900172 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100173
174 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400175 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
176 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftz thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100177endif()
178
Pascal Bachd5f87e12014-12-12 15:59:17 +0100179if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900180 set(CMAKE_AUTOMOC ON)
181 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100182 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400183 TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
184 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftqt thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100185endif()
186
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900187if(WITH_QT5)
188 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
189 add_subdirectory(src/thrift/qt)
190endif()
191
Pascal Bachd5f87e12014-12-12 15:59:17 +0100192if(MSVC)
193 add_definitions("-DUNICODE -D_UNICODE")
194endif()
195
Jim King79c99112015-04-30 07:10:08 -0400196add_definitions("-D__STDC_LIMIT_MACROS")
197
Pascal Bachd5f87e12014-12-12 15:59:17 +0100198# Install the headers
199install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
200 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
201# Copy config.h file
202install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
203 FILES_MATCHING PATTERN "*.h")
204
205if(BUILD_TESTING)
206 add_subdirectory(test)
207endif()