blob: a0b97437cdc496340cc747a5d967369e2689999d [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
Dave Watson792db4e2015-01-16 11:22:01 -080049 src/thrift/protocol/THeaderProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010050 src/thrift/transport/TTransportException.cpp
51 src/thrift/transport/TFDTransport.cpp
52 src/thrift/transport/TSimpleFileTransport.cpp
53 src/thrift/transport/THttpTransport.cpp
54 src/thrift/transport/THttpClient.cpp
55 src/thrift/transport/THttpServer.cpp
56 src/thrift/transport/TSocket.cpp
57 src/thrift/transport/TSocketPool.cpp
58 src/thrift/transport/TServerSocket.cpp
59 src/thrift/transport/TTransportUtils.cpp
60 src/thrift/transport/TBufferTransports.cpp
Dave Watson792db4e2015-01-16 11:22:01 -080061 src/thrift/transport/THeaderTransport.cpp
Jim King5ec805b2015-04-26 07:52:40 -040062 src/thrift/server/TConnectedClient.cpp
Jim King21b68522015-04-26 18:30:26 -040063 src/thrift/server/TServerFramework.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010064 src/thrift/server/TSimpleServer.cpp
65 src/thrift/server/TThreadPoolServer.cpp
66 src/thrift/server/TThreadedServer.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010067)
68
69# This files don't work on Windows CE as there is no pipe support
Jim King9de9b1f2015-04-30 16:03:34 -040070# 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 +010071if (NOT WINCE)
72 list(APPEND thriftcpp_SOURCES
73 src/thrift/transport/TPipe.cpp
74 src/thrift/transport/TPipeServer.cpp
75 src/thrift/transport/TFileTransport.cpp
76 )
77endif()
78
79
80if (WIN32)
81 list(APPEND thriftcpp_SOURCES
82 src/thrift/windows/TWinsockSingleton.cpp
83 src/thrift/windows/SocketPair.cpp
84 src/thrift/windows/GetTimeOfDay.cpp
85 src/thrift/windows/WinFcntl.cpp
86 )
87 if(NOT WINCE)
88 # This file uses pipes so it currently won't work on Windows CE
89 list(APPEND thriftcpp_SOURCES
90 src/thrift/windows/OverlappedSubmissionThread.cpp
91 )
92 endif()
Ben Craig7207c222015-07-06 08:40:35 -050093else()
94 # These files evaluate to nothing on Windows, so omit them from the
95 # Windows build
96 list(APPEND thriftcpp_SOURCES
97 src/thrift/VirtualProfiling.cpp
98 src/thrift/server/TServer.cpp
99 )
Pascal Bachd5f87e12014-12-12 15:59:17 +0100100endif()
101
102# If OpenSSL is not found just ignore the OpenSSL stuff
103find_package(OpenSSL)
104if(OPENSSL_FOUND AND WITH_OPENSSL)
105 list( APPEND thriftcpp_SOURCES
106 src/thrift/transport/TSSLSocket.cpp
107 src/thrift/transport/TSSLServerSocket.cpp
108 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900109 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100110 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
111endif()
112
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900113# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100114if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100115 set( thriftcpp_threads_SOURCES
116 src/thrift/concurrency/BoostThreadFactory.cpp
117 src/thrift/concurrency/BoostMonitor.cpp
118 src/thrift/concurrency/BoostMutex.cpp
119 )
120 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
121elseif(UNIX AND NOT WITH_STDTHREADS)
122 list(APPEND SYSLIBS pthread)
123 set( thriftcpp_threads_SOURCES
124 src/thrift/concurrency/PosixThreadFactory.cpp
125 src/thrift/concurrency/Mutex.cpp
126 src/thrift/concurrency/Monitor.cpp
127 )
128else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900129 if(UNIX)
130 # need pthread for multi-thread support
131 list(APPEND SYSLIBS pthread)
132 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100133 set( thriftcpp_threads_SOURCES
134 src/thrift/concurrency/StdThreadFactory.cpp
135 src/thrift/concurrency/StdMutex.cpp
136 src/thrift/concurrency/StdMonitor.cpp
137 )
138endif()
139
140# Thrift non blocking server
141set( thriftcppnb_SOURCES
142 src/thrift/server/TNonblockingServer.cpp
143 src/thrift/async/TAsyncProtocolProcessor.cpp
144 src/thrift/async/TEvhttpServer.cpp
145 src/thrift/async/TEvhttpClientChannel.cpp
146)
147
148# Thrift zlib server
149set( thriftcppz_SOURCES
150 src/thrift/transport/TZlibTransport.cpp
Dave Watson792db4e2015-01-16 11:22:01 -0800151 src/thrift/protocol/THeaderProtocol.cpp
152 src/thrift/transport/THeaderTransport.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100153)
154
155# Thrift Qt4 server
156set( thriftcppqt_SOURCES
157 src/thrift/qt/TQIODeviceTransport.cpp
158 src/thrift/qt/TQTcpServer.cpp
159)
160
161# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
162include(ThriftMacros)
163
164ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
165TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
166
167if(WITH_LIBEVENT)
168 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900169 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100170
171 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400172 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${LIBEVENT_LIBRARIES})
173 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftnb thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100174endif()
175
176if(WITH_ZLIB)
177 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900178 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100179
180 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400181 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
182 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftz thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100183endif()
184
Pascal Bachd5f87e12014-12-12 15:59:17 +0100185if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900186 set(CMAKE_AUTOMOC ON)
187 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100188 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400189 TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
190 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftqt thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100191endif()
192
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900193if(WITH_QT5)
194 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
195 add_subdirectory(src/thrift/qt)
196endif()
197
Pascal Bachd5f87e12014-12-12 15:59:17 +0100198if(MSVC)
199 add_definitions("-DUNICODE -D_UNICODE")
200endif()
201
Jim King79c99112015-04-30 07:10:08 -0400202add_definitions("-D__STDC_LIMIT_MACROS")
203
Pascal Bachd5f87e12014-12-12 15:59:17 +0100204# Install the headers
205install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
206 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
207# Copy config.h file
208install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
209 FILES_MATCHING PATTERN "*.h")
210
211if(BUILD_TESTING)
212 add_subdirectory(test)
213endif()