Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 21 | cmake_minimum_required(VERSION 2.8) |
| 22 | |
| 23 | # Find required packages |
Nobuaki Sukegawa | 2825664 | 2014-12-16 03:24:37 +0900 | [diff] [blame^] | 24 | if(WITH_BOOSTTHREADS) |
| 25 | find_package(Boost 1.53.0 REQUIRED COMPONENTS system thread) |
| 26 | else() |
| 27 | find_package(Boost 1.53.0 REQUIRED) |
| 28 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 29 | include_directories("${Boost_INCLUDE_DIR}") |
| 30 | |
| 31 | include_directories(src) |
| 32 | |
| 33 | # SYSLIBS contains libraries that need to be linked to all lib targets |
| 34 | set(SYSLIBS "") |
| 35 | |
| 36 | # Create the thrift C++ library |
| 37 | set( 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. |
| 70 | if (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 | ) |
| 76 | endif() |
| 77 | |
| 78 | |
| 79 | if (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() |
| 92 | endif() |
| 93 | |
| 94 | # If OpenSSL is not found just ignore the OpenSSL stuff |
| 95 | find_package(OpenSSL) |
| 96 | if(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}") |
| 103 | endif() |
| 104 | |
Nobuaki Sukegawa | 2825664 | 2014-12-16 03:24:37 +0900 | [diff] [blame^] | 105 | # WITH_*THREADS selects which threading library to use |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 106 | if(WITH_BOOSTTHREADS) |
Nobuaki Sukegawa | 2825664 | 2014-12-16 03:24:37 +0900 | [diff] [blame^] | 107 | add_definitions("-DUSE_BOOST_THREAD=1") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 108 | 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}") |
| 114 | elseif(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 | ) |
| 121 | else() |
Nobuaki Sukegawa | 2825664 | 2014-12-16 03:24:37 +0900 | [diff] [blame^] | 122 | add_definitions("-DUSE_STD_THREAD=1") |
| 123 | if(UNIX) |
| 124 | # need pthread for multi-thread support |
| 125 | list(APPEND SYSLIBS pthread) |
| 126 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 127 | set( thriftcpp_threads_SOURCES |
| 128 | src/thrift/concurrency/StdThreadFactory.cpp |
| 129 | src/thrift/concurrency/StdMutex.cpp |
| 130 | src/thrift/concurrency/StdMonitor.cpp |
| 131 | ) |
| 132 | endif() |
| 133 | |
| 134 | # Thrift non blocking server |
| 135 | set( 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 |
| 143 | set( thriftcppz_SOURCES |
| 144 | src/thrift/transport/TZlibTransport.cpp |
| 145 | ) |
| 146 | |
| 147 | # Thrift Qt4 server |
| 148 | set( 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 |
| 154 | include(ThriftMacros) |
| 155 | |
| 156 | ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES}) |
| 157 | TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS}) |
| 158 | |
| 159 | if(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}) |
| 165 | endif() |
| 166 | |
| 167 | if(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}) |
| 173 | endif() |
| 174 | |
| 175 | |
| 176 | if(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}) |
| 182 | endif() |
| 183 | |
| 184 | if(MSVC) |
| 185 | add_definitions("-DUNICODE -D_UNICODE") |
| 186 | endif() |
| 187 | |
| 188 | # Install the headers |
| 189 | install(DIRECTORY "src/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}" |
| 190 | FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc") |
| 191 | # Copy config.h file |
| 192 | install(DIRECTORY "${CMAKE_BINARY_DIR}/thrift" DESTINATION "${INCLUDE_INSTALL_DIR}" |
| 193 | FILES_MATCHING PATTERN "*.h") |
| 194 | |
| 195 | if(BUILD_TESTING) |
| 196 | add_subdirectory(test) |
| 197 | endif() |