blob: 9075c560d3bc8034abe0fdca03f25051a08ecf31 [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
21cmake_minimum_required(VERSION 2.8)
22
Pascal Bachd5f87e12014-12-12 15:59:17 +010023# Find required packages
Nobuaki Sukegawa28256642014-12-16 03:24:37 +090024if(WITH_BOOSTTHREADS)
25 find_package(Boost 1.53.0 REQUIRED COMPONENTS system thread)
26else()
27 find_package(Boost 1.53.0 REQUIRED)
28endif()
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090029include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
Pascal Bachd5f87e12014-12-12 15:59:17 +010030
31include_directories(src)
32
33# SYSLIBS contains libraries that need to be linked to all lib targets
34set(SYSLIBS "")
35
36# Create the thrift C++ library
37set( thriftcpp_SOURCES
38 src/thrift/Thrift.cpp
39 src/thrift/TApplicationException.cpp
40 src/thrift/VirtualProfiling.cpp
41 src/thrift/concurrency/ThreadManager.cpp
42 src/thrift/concurrency/TimerManager.cpp
43 src/thrift/concurrency/Util.cpp
44 src/thrift/protocol/TDebugProtocol.cpp
45 src/thrift/protocol/TDenseProtocol.cpp
46 src/thrift/protocol/TJSONProtocol.cpp
47 src/thrift/protocol/TBase64Utils.cpp
48 src/thrift/protocol/TMultiplexedProtocol.cpp
49 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
60 src/thrift/server/TServer.cpp
61 src/thrift/server/TSimpleServer.cpp
62 src/thrift/server/TThreadPoolServer.cpp
63 src/thrift/server/TThreadedServer.cpp
64 src/thrift/async/TAsyncChannel.cpp
65 src/thrift/processor/PeekProcessor.cpp
66)
67
68# This files don't work on Windows CE as there is no pipe support
69# TODO: This files won't work with UNICODE support on windows. If fixed this can be re-added.
70if (NOT WINCE)
71 list(APPEND thriftcpp_SOURCES
72 src/thrift/transport/TPipe.cpp
73 src/thrift/transport/TPipeServer.cpp
74 src/thrift/transport/TFileTransport.cpp
75 )
76endif()
77
78
79if (WIN32)
80 list(APPEND thriftcpp_SOURCES
81 src/thrift/windows/TWinsockSingleton.cpp
82 src/thrift/windows/SocketPair.cpp
83 src/thrift/windows/GetTimeOfDay.cpp
84 src/thrift/windows/WinFcntl.cpp
85 )
86 if(NOT WINCE)
87 # This file uses pipes so it currently won't work on Windows CE
88 list(APPEND thriftcpp_SOURCES
89 src/thrift/windows/OverlappedSubmissionThread.cpp
90 )
91 endif()
92endif()
93
94# If OpenSSL is not found just ignore the OpenSSL stuff
95find_package(OpenSSL)
96if(OPENSSL_FOUND AND WITH_OPENSSL)
97 list( APPEND thriftcpp_SOURCES
98 src/thrift/transport/TSSLSocket.cpp
99 src/thrift/transport/TSSLServerSocket.cpp
100 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900101 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100102 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
103endif()
104
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900105# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100106if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100107 set( thriftcpp_threads_SOURCES
108 src/thrift/concurrency/BoostThreadFactory.cpp
109 src/thrift/concurrency/BoostMonitor.cpp
110 src/thrift/concurrency/BoostMutex.cpp
111 )
112 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
113elseif(UNIX AND NOT WITH_STDTHREADS)
114 list(APPEND SYSLIBS pthread)
115 set( thriftcpp_threads_SOURCES
116 src/thrift/concurrency/PosixThreadFactory.cpp
117 src/thrift/concurrency/Mutex.cpp
118 src/thrift/concurrency/Monitor.cpp
119 )
120else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900121 if(UNIX)
122 # need pthread for multi-thread support
123 list(APPEND SYSLIBS pthread)
124 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100125 set( thriftcpp_threads_SOURCES
126 src/thrift/concurrency/StdThreadFactory.cpp
127 src/thrift/concurrency/StdMutex.cpp
128 src/thrift/concurrency/StdMonitor.cpp
129 )
130endif()
131
132# Thrift non blocking server
133set( thriftcppnb_SOURCES
134 src/thrift/server/TNonblockingServer.cpp
135 src/thrift/async/TAsyncProtocolProcessor.cpp
136 src/thrift/async/TEvhttpServer.cpp
137 src/thrift/async/TEvhttpClientChannel.cpp
138)
139
140# Thrift zlib server
141set( thriftcppz_SOURCES
142 src/thrift/transport/TZlibTransport.cpp
143)
144
145# Thrift Qt4 server
146set( thriftcppqt_SOURCES
147 src/thrift/qt/TQIODeviceTransport.cpp
148 src/thrift/qt/TQTcpServer.cpp
149)
150
151# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
152include(ThriftMacros)
153
154ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
155TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
156
157if(WITH_LIBEVENT)
158 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900159 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100160
161 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900162 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${LIBEVENT_LIBRARIES})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100163endif()
164
165if(WITH_ZLIB)
166 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900167 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100168
169 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
170 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
171endif()
172
Pascal Bachd5f87e12014-12-12 15:59:17 +0100173if(WITH_QT4)
Roger Meier5af78c82015-04-12 21:43:12 +0200174 cmake_minimum_required(VERSION 2.8.12)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900175 set(CMAKE_AUTOMOC ON)
176 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100177 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900178 TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100179endif()
180
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900181if(WITH_QT5)
182 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
183 add_subdirectory(src/thrift/qt)
184endif()
185
Pascal Bachd5f87e12014-12-12 15:59:17 +0100186if(MSVC)
187 add_definitions("-DUNICODE -D_UNICODE")
188endif()
189
190# Install the headers
191install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
192 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
193# Copy config.h file
194install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
195 FILES_MATCHING PATTERN "*.h")
196
197if(BUILD_TESTING)
198 add_subdirectory(test)
199endif()