blob: 4f2e451d457d05ba33146f67cbbbe52e949f63b8 [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
20
21cmake_minimum_required(VERSION 2.8)
22
23# 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()
Pascal Bachd5f87e12014-12-12 15:59:17 +010029include_directories("${Boost_INCLUDE_DIR}")
30
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 )
101 include_directories("${OPENSSL_INCLUDE_DIR}")
102 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)
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900107 add_definitions("-DUSE_BOOST_THREAD=1")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100108 set( thriftcpp_threads_SOURCES
109 src/thrift/concurrency/BoostThreadFactory.cpp
110 src/thrift/concurrency/BoostMonitor.cpp
111 src/thrift/concurrency/BoostMutex.cpp
112 )
113 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
114elseif(UNIX AND NOT WITH_STDTHREADS)
115 list(APPEND SYSLIBS pthread)
116 set( thriftcpp_threads_SOURCES
117 src/thrift/concurrency/PosixThreadFactory.cpp
118 src/thrift/concurrency/Mutex.cpp
119 src/thrift/concurrency/Monitor.cpp
120 )
121else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900122 add_definitions("-DUSE_STD_THREAD=1")
123 if(UNIX)
124 # need pthread for multi-thread support
125 list(APPEND SYSLIBS pthread)
126 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100127 set( thriftcpp_threads_SOURCES
128 src/thrift/concurrency/StdThreadFactory.cpp
129 src/thrift/concurrency/StdMutex.cpp
130 src/thrift/concurrency/StdMonitor.cpp
131 )
132endif()
133
134# Thrift non blocking server
135set( thriftcppnb_SOURCES
136 src/thrift/server/TNonblockingServer.cpp
137 src/thrift/async/TAsyncProtocolProcessor.cpp
138 src/thrift/async/TEvhttpServer.cpp
139 src/thrift/async/TEvhttpClientChannel.cpp
140)
141
142# Thrift zlib server
143set( thriftcppz_SOURCES
144 src/thrift/transport/TZlibTransport.cpp
145)
146
147# Thrift Qt4 server
148set( thriftcppqt_SOURCES
149 src/thrift/qt/TQIODeviceTransport.cpp
150 src/thrift/qt/TQTcpServer.cpp
151)
152
153# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
154include(ThriftMacros)
155
156ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
157TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
158
159if(WITH_LIBEVENT)
160 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
161 include_directories(${Libevent_INCLUDE_DIR})
162
163 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
164 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${Libevent_LIBRARIES})
165endif()
166
167if(WITH_ZLIB)
168 find_package(ZLIB REQUIRED)
169 include_directories(${ZLIB_INCLUDE_DIR})
170
171 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
172 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
173endif()
174
175
176if(WITH_QT4)
177 find_package(Qt4 REQUIRED)
178 include_directories(${QT_INCLUDES})
179
180 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
181 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${QT_LIBRARIES})
182endif()
183
184if(MSVC)
185 add_definitions("-DUNICODE -D_UNICODE")
186endif()
187
188# Install the headers
189install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
190 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
191# Copy config.h file
192install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
193 FILES_MATCHING PATTERN "*.h")
194
195if(BUILD_TESTING)
196 add_subdirectory(test)
197endif()