blob: bab2e8411917bb2ade7ccc591f52e009aabb0ad8 [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
Pascal Bachd5f87e12014-12-12 15:59:17 +010038 src/thrift/concurrency/ThreadManager.cpp
39 src/thrift/concurrency/TimerManager.cpp
40 src/thrift/concurrency/Util.cpp
Jim King79c99112015-04-30 07:10:08 -040041 src/thrift/processor/PeekProcessor.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050042 src/thrift/protocol/TBase64Utils.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010043 src/thrift/protocol/TDebugProtocol.cpp
44 src/thrift/protocol/TDenseProtocol.cpp
45 src/thrift/protocol/TJSONProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010046 src/thrift/protocol/TMultiplexedProtocol.cpp
Ben Craigcfaadcc2015-07-08 20:50:33 -050047 src/thrift/protocol/TProtocol.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010048 src/thrift/transport/TTransportException.cpp
49 src/thrift/transport/TFDTransport.cpp
50 src/thrift/transport/TSimpleFileTransport.cpp
51 src/thrift/transport/THttpTransport.cpp
52 src/thrift/transport/THttpClient.cpp
53 src/thrift/transport/THttpServer.cpp
54 src/thrift/transport/TSocket.cpp
55 src/thrift/transport/TSocketPool.cpp
56 src/thrift/transport/TServerSocket.cpp
57 src/thrift/transport/TTransportUtils.cpp
58 src/thrift/transport/TBufferTransports.cpp
Jim King5ec805b2015-04-26 07:52:40 -040059 src/thrift/server/TConnectedClient.cpp
Jim King21b68522015-04-26 18:30:26 -040060 src/thrift/server/TServerFramework.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010061 src/thrift/server/TSimpleServer.cpp
62 src/thrift/server/TThreadPoolServer.cpp
63 src/thrift/server/TThreadedServer.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010064)
65
66# This files don't work on Windows CE as there is no pipe support
Jim King9de9b1f2015-04-30 16:03:34 -040067# 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 +010068if (NOT WINCE)
69 list(APPEND thriftcpp_SOURCES
70 src/thrift/transport/TPipe.cpp
71 src/thrift/transport/TPipeServer.cpp
72 src/thrift/transport/TFileTransport.cpp
73 )
74endif()
75
76
77if (WIN32)
78 list(APPEND thriftcpp_SOURCES
79 src/thrift/windows/TWinsockSingleton.cpp
80 src/thrift/windows/SocketPair.cpp
81 src/thrift/windows/GetTimeOfDay.cpp
82 src/thrift/windows/WinFcntl.cpp
83 )
84 if(NOT WINCE)
85 # This file uses pipes so it currently won't work on Windows CE
86 list(APPEND thriftcpp_SOURCES
87 src/thrift/windows/OverlappedSubmissionThread.cpp
88 )
89 endif()
Ben Craig7207c222015-07-06 08:40:35 -050090else()
91 # These files evaluate to nothing on Windows, so omit them from the
92 # Windows build
93 list(APPEND thriftcpp_SOURCES
94 src/thrift/VirtualProfiling.cpp
95 src/thrift/server/TServer.cpp
96 )
Pascal Bachd5f87e12014-12-12 15:59:17 +010097endif()
98
99# If OpenSSL is not found just ignore the OpenSSL stuff
100find_package(OpenSSL)
101if(OPENSSL_FOUND AND WITH_OPENSSL)
102 list( APPEND thriftcpp_SOURCES
103 src/thrift/transport/TSSLSocket.cpp
104 src/thrift/transport/TSSLServerSocket.cpp
105 )
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900106 include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100107 list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
108endif()
109
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900110# WITH_*THREADS selects which threading library to use
Pascal Bachd5f87e12014-12-12 15:59:17 +0100111if(WITH_BOOSTTHREADS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100112 set( thriftcpp_threads_SOURCES
113 src/thrift/concurrency/BoostThreadFactory.cpp
114 src/thrift/concurrency/BoostMonitor.cpp
115 src/thrift/concurrency/BoostMutex.cpp
116 )
117 list(APPEND SYSLIBS "${Boost_LIBRARIES}")
118elseif(UNIX AND NOT WITH_STDTHREADS)
119 list(APPEND SYSLIBS pthread)
120 set( thriftcpp_threads_SOURCES
121 src/thrift/concurrency/PosixThreadFactory.cpp
122 src/thrift/concurrency/Mutex.cpp
123 src/thrift/concurrency/Monitor.cpp
124 )
125else()
Nobuaki Sukegawa28256642014-12-16 03:24:37 +0900126 if(UNIX)
127 # need pthread for multi-thread support
128 list(APPEND SYSLIBS pthread)
129 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100130 set( thriftcpp_threads_SOURCES
131 src/thrift/concurrency/StdThreadFactory.cpp
132 src/thrift/concurrency/StdMutex.cpp
133 src/thrift/concurrency/StdMonitor.cpp
134 )
135endif()
136
137# Thrift non blocking server
138set( thriftcppnb_SOURCES
139 src/thrift/server/TNonblockingServer.cpp
140 src/thrift/async/TAsyncProtocolProcessor.cpp
141 src/thrift/async/TEvhttpServer.cpp
142 src/thrift/async/TEvhttpClientChannel.cpp
143)
144
145# Thrift zlib server
146set( thriftcppz_SOURCES
147 src/thrift/transport/TZlibTransport.cpp
148)
149
150# Thrift Qt4 server
151set( thriftcppqt_SOURCES
152 src/thrift/qt/TQIODeviceTransport.cpp
153 src/thrift/qt/TQTcpServer.cpp
154)
155
156# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
157include(ThriftMacros)
158
159ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES})
160TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS})
161
162if(WITH_LIBEVENT)
163 find_package(Libevent REQUIRED) # Libevent comes with CMake support form upstream
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900164 include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100165
166 ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400167 TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} ${LIBEVENT_LIBRARIES})
168 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftnb thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100169endif()
170
171if(WITH_ZLIB)
172 find_package(ZLIB REQUIRED)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +0900173 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100174
175 ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400176 TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ${ZLIB_LIBRARIES})
177 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftz thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100178endif()
179
Pascal Bachd5f87e12014-12-12 15:59:17 +0100180if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900181 set(CMAKE_AUTOMOC ON)
182 find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100183 ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400184 TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork)
185 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftqt thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100186endif()
187
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900188if(WITH_QT5)
189 # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC
190 add_subdirectory(src/thrift/qt)
191endif()
192
Pascal Bachd5f87e12014-12-12 15:59:17 +0100193if(MSVC)
194 add_definitions("-DUNICODE -D_UNICODE")
195endif()
196
Jim King79c99112015-04-30 07:10:08 -0400197add_definitions("-D__STDC_LIMIT_MACROS")
198
Pascal Bachd5f87e12014-12-12 15:59:17 +0100199# Install the headers
200install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
201 FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc")
202# Copy config.h file
203install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}"
204 FILES_MATCHING PATTERN "*.h")
205
206if(BUILD_TESTING)
207 add_subdirectory(test)
208endif()