blob: cc73f994d86259159630bcc1bbe35512a2980419 [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
24find_package(Boost 1.53.0 REQUIRED)
25include_directories("${Boost_INCLUDE_DIR}")
26
27include_directories(src)
28
29# SYSLIBS contains libraries that need to be linked to all lib targets
30set(SYSLIBS "")
31
32# Create the thrift C++ library
33set( thriftcpp_SOURCES
34 src/thrift/Thrift.cpp
35 src/thrift/TApplicationException.cpp
36 src/thrift/VirtualProfiling.cpp
37 src/thrift/concurrency/ThreadManager.cpp
38 src/thrift/concurrency/TimerManager.cpp
39 src/thrift/concurrency/Util.cpp
40 src/thrift/protocol/TDebugProtocol.cpp
41 src/thrift/protocol/TDenseProtocol.cpp
42 src/thrift/protocol/TJSONProtocol.cpp
43 src/thrift/protocol/TBase64Utils.cpp
44 src/thrift/protocol/TMultiplexedProtocol.cpp
45 src/thrift/transport/TTransportException.cpp
46 src/thrift/transport/TFDTransport.cpp
47 src/thrift/transport/TSimpleFileTransport.cpp
48 src/thrift/transport/THttpTransport.cpp
49 src/thrift/transport/THttpClient.cpp
50 src/thrift/transport/THttpServer.cpp
51 src/thrift/transport/TSocket.cpp
52 src/thrift/transport/TSocketPool.cpp
53 src/thrift/transport/TServerSocket.cpp
54 src/thrift/transport/TTransportUtils.cpp
55 src/thrift/transport/TBufferTransports.cpp
56 src/thrift/server/TServer.cpp
57 src/thrift/server/TSimpleServer.cpp
58 src/thrift/server/TThreadPoolServer.cpp
59 src/thrift/server/TThreadedServer.cpp
60 src/thrift/async/TAsyncChannel.cpp
61 src/thrift/processor/PeekProcessor.cpp
62)
63
64# This files don't work on Windows CE as there is no pipe support
65# TODO: This files won't work with UNICODE support on windows. If fixed this can be re-added.
66if (NOT WINCE)
67 list(APPEND thriftcpp_SOURCES
68 src/thrift/transport/TPipe.cpp
69 src/thrift/transport/TPipeServer.cpp
70 src/thrift/transport/TFileTransport.cpp
71 )
72endif()
73
74
75if (WIN32)
76 list(APPEND thriftcpp_SOURCES
77 src/thrift/windows/TWinsockSingleton.cpp
78 src/thrift/windows/SocketPair.cpp
79 src/thrift/windows/GetTimeOfDay.cpp
80 src/thrift/windows/WinFcntl.cpp
81 )
82 if(NOT WINCE)
83 # This file uses pipes so it currently won't work on Windows CE
84 list(APPEND thriftcpp_SOURCES
85 src/thrift/windows/OverlappedSubmissionThread.cpp
86 )
87 endif()
88endif()
89
90# If OpenSSL is not found just ignore the OpenSSL stuff
91find_package(OpenSSL)
92if(OPENSSL_FOUND AND WITH_OPENSSL)
93 list( APPEND thriftcpp_SOURCES
94 src/thrift/transport/TSSLSocket.cpp
95 src/thrift/transport/TSSLServerSocket.cpp
96 )
97 include_directories("${OPENSSL_INCLUDE_DIR}")
98 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
99endif()
100
101# WITH_*THREADS selects whicht threading library to use
102if(WITH_BOOSTTHREADS)
103 set( USE_BOOST_THREAD 1)
104 set( thriftcpp_threads_SOURCES
105 src/thrift/concurrency/BoostThreadFactory.cpp
106 src/thrift/concurrency/BoostMonitor.cpp
107 src/thrift/concurrency/BoostMutex.cpp
108 )
109 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
110elseif(UNIX AND NOT WITH_STDTHREADS)
111 list(APPEND SYSLIBS pthread)
112 set( thriftcpp_threads_SOURCES
113 src/thrift/concurrency/PosixThreadFactory.cpp
114 src/thrift/concurrency/Mutex.cpp
115 src/thrift/concurrency/Monitor.cpp
116 )
117else()
118 set( USE_STD_THREAD 1)
119 set( thriftcpp_threads_SOURCES
120 src/thrift/concurrency/StdThreadFactory.cpp
121 src/thrift/concurrency/StdMutex.cpp
122 src/thrift/concurrency/StdMonitor.cpp
123 )
124endif()
125
126# Thrift non blocking server
127set( thriftcppnb_SOURCES
128 src/thrift/server/TNonblockingServer.cpp
129 src/thrift/async/TAsyncProtocolProcessor.cpp
130 src/thrift/async/TEvhttpServer.cpp
131 src/thrift/async/TEvhttpClientChannel.cpp
132)
133
134# Thrift zlib server
135set( thriftcppz_SOURCES
136 src/thrift/transport/TZlibTransport.cpp
137)
138
139# Thrift Qt4 server
140set( thriftcppqt_SOURCES
141 src/thrift/qt/TQIODeviceTransport.cpp
142 src/thrift/qt/TQTcpServer.cpp
143)
144
145# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
146include(ThriftMacros)
147
148ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
149TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
150
151if(WITH_LIBEVENT)
152 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
153 include_directories(${Libevent_INCLUDE_DIR})
154
155 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
156 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${Libevent_LIBRARIES})
157endif()
158
159if(WITH_ZLIB)
160 find_package(ZLIB REQUIRED)
161 include_directories(${ZLIB_INCLUDE_DIR})
162
163 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
164 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
165endif()
166
167
168if(WITH_QT4)
169 find_package(Qt4 REQUIRED)
170 include_directories(${QT_INCLUDES})
171
172 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
173 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${QT_LIBRARIES})
174endif()
175
176if(MSVC)
177 add_definitions("-DUNICODE -D_UNICODE")
178endif()
179
180# Install the headers
181install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
182 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
183# Copy config.h file
184install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
185 FILES_MATCHING PATTERN "*.h")
186
187if(BUILD_TESTING)
188 add_subdirectory(test)
189endif()