blob: 8ea054675e34e05a2f2040bda8e9512777d0b112 [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()
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090026include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
Pascal Bachd5f87e12014-12-12 15:59:17 +010027
28include_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
35 src/thrift/Thrift.cpp
36 src/thrift/TApplicationException.cpp
37 src/thrift/VirtualProfiling.cpp
38 src/thrift/concurrency/ThreadManager.cpp
39 src/thrift/concurrency/TimerManager.cpp
40 src/thrift/concurrency/Util.cpp
41 src/thrift/protocol/TDebugProtocol.cpp
42 src/thrift/protocol/TDenseProtocol.cpp
43 src/thrift/protocol/TJSONProtocol.cpp
44 src/thrift/protocol/TBase64Utils.cpp
45 src/thrift/protocol/TMultiplexedProtocol.cpp
46 src/thrift/transport/TTransportException.cpp
47 src/thrift/transport/TFDTransport.cpp
48 src/thrift/transport/TSimpleFileTransport.cpp
49 src/thrift/transport/THttpTransport.cpp
50 src/thrift/transport/THttpClient.cpp
51 src/thrift/transport/THttpServer.cpp
52 src/thrift/transport/TSocket.cpp
53 src/thrift/transport/TSocketPool.cpp
54 src/thrift/transport/TServerSocket.cpp
55 src/thrift/transport/TTransportUtils.cpp
56 src/thrift/transport/TBufferTransports.cpp
Jim King5ec805b2015-04-26 07:52:40 -040057 src/thrift/server/TConnectedClient.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010058 src/thrift/server/TServer.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
63 src/thrift/async/TAsyncChannel.cpp
64 src/thrift/processor/PeekProcessor.cpp
65)
66
67# This files don't work on Windows CE as there is no pipe support
68# TODO: This files won't work with UNICODE support on windows. If fixed this can be re-added.
69if (NOT WINCE)
70 list(APPEND thriftcpp_SOURCES
71 src/thrift/transport/TPipe.cpp
72 src/thrift/transport/TPipeServer.cpp
73 src/thrift/transport/TFileTransport.cpp
74 )
75endif()
76
77
78if (WIN32)
79 list(APPEND thriftcpp_SOURCES
80 src/thrift/windows/TWinsockSingleton.cpp
81 src/thrift/windows/SocketPair.cpp
82 src/thrift/windows/GetTimeOfDay.cpp
83 src/thrift/windows/WinFcntl.cpp
84 )
85 if(NOT WINCE)
86 # This file uses pipes so it currently won't work on Windows CE
87 list(APPEND thriftcpp_SOURCES
88 src/thrift/windows/OverlappedSubmissionThread.cpp
89 )
90 endif()
91endif()
92
93# If OpenSSL is not found just ignore the OpenSSL stuff
94find_package(OpenSSL)
95if(OPENSSL_FOUND AND WITH_OPENSSL)
96 list( APPEND thriftcpp_SOURCES
97 src/thrift/transport/TSSLSocket.cpp
98 src/thrift/transport/TSSLServerSocket.cpp
99 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900100 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100101 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
102endif()
103
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900104# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100105if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100106 set( thriftcpp_threads_SOURCES
107 src/thrift/concurrency/BoostThreadFactory.cpp
108 src/thrift/concurrency/BoostMonitor.cpp
109 src/thrift/concurrency/BoostMutex.cpp
110 )
111 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
112elseif(UNIX AND NOT WITH_STDTHREADS)
113 list(APPEND SYSLIBS pthread)
114 set( thriftcpp_threads_SOURCES
115 src/thrift/concurrency/PosixThreadFactory.cpp
116 src/thrift/concurrency/Mutex.cpp
117 src/thrift/concurrency/Monitor.cpp
118 )
119else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900120 if(UNIX)
121 # need pthread for multi-thread support
122 list(APPEND SYSLIBS pthread)
123 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100124 set( thriftcpp_threads_SOURCES
125 src/thrift/concurrency/StdThreadFactory.cpp
126 src/thrift/concurrency/StdMutex.cpp
127 src/thrift/concurrency/StdMonitor.cpp
128 )
129endif()
130
131# Thrift non blocking server
132set( thriftcppnb_SOURCES
133 src/thrift/server/TNonblockingServer.cpp
134 src/thrift/async/TAsyncProtocolProcessor.cpp
135 src/thrift/async/TEvhttpServer.cpp
136 src/thrift/async/TEvhttpClientChannel.cpp
137)
138
139# Thrift zlib server
140set( thriftcppz_SOURCES
141 src/thrift/transport/TZlibTransport.cpp
142)
143
144# Thrift Qt4 server
145set( thriftcppqt_SOURCES
146 src/thrift/qt/TQIODeviceTransport.cpp
147 src/thrift/qt/TQTcpServer.cpp
148)
149
150# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
151include(ThriftMacros)
152
153ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
154TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
155
156if(WITH_LIBEVENT)
157 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900158 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100159
160 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Marco Molteni98201b02015-04-17 10:18:35 +0200161 TARGET_LINK_LIBRARIES_THRIFT(thriftnb thrift ${SYSLIBS} ${LIBEVENT_LIBRARIES})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100162endif()
163
164if(WITH_ZLIB)
165 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900166 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100167
168 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Marco Molteni98201b02015-04-17 10:18:35 +0200169 TARGET_LINK_LIBRARIES_THRIFT(thriftz thrift ${SYSLIBS} ${ZLIB_LIBRARIES})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100170endif()
171
Pascal Bachd5f87e12014-12-12 15:59:17 +0100172if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900173 set(CMAKE_AUTOMOC ON)
174 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100175 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Marco Molteni98201b02015-04-17 10:18:35 +0200176 TARGET_LINK_LIBRARIES_THRIFT(thriftqt thrift ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100177endif()
178
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900179if(WITH_QT5)
180 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
181 add_subdirectory(src/thrift/qt)
182endif()
183
Pascal Bachd5f87e12014-12-12 15:59:17 +0100184if(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()