blob: 342e04092a72c70ec08f20327f490256cafe964c [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
21include(CMakeDependentOption)
22
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090023set(THRIFT_COMPILER "" CACHE FILEPATH "External Thrift compiler to use during build")
24
Pascal Bachd5f87e12014-12-12 15:59:17 +010025# Additional components
26option(BUILD_COMPILER "Build Thrift compiler" ON)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090027
28if(BUILD_COMPILER OR EXISTS ${THRIFT_COMPILER})
29 set(HAVE_COMPILER ON)
30endif()
31CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
32CMAKE_DEPENDENT_OPTION(BUILD_EXAMPLES "Build examples" ON "HAVE_COMPILER" OFF)
33CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF)
Marco Molteni7f477922015-04-15 20:46:48 +020034option(BUILD_LIBRARIES "Build Thrift libraries" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010035
36# Libraries to build
37
38# Each language library can be enabled or disabled using the WITH_<LANG> flag.
39# By default CMake checks if the required dependencies for a language are present
40# and enables the library if all are found. This means the default is to build as
41# much as possible but leaving out libraries if their dependencies are not met.
42
43# C++
Roger Meier3b99c972015-04-20 22:49:48 +020044option(WITH_CPP "Build C++ Thrift library" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010045find_package(Boost 1.53 QUIET)
Roger Meier3b99c972015-04-20 22:49:48 +020046CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
47 "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010048# NOTE: Currently the following options are C++ specific,
49# but in future other libraries might reuse them.
Marco Molteni83494252015-04-16 13:50:20 +020050# So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
Pascal Bachd5f87e12014-12-12 15:59:17 +010051# has no effect.
Nobuaki Sukegawae8c71d82015-11-23 19:51:37 +090052if(ZLIB_LIBRARY)
53 # FindZLIB.cmake does not normalize path so we need to do it ourselves.
54 file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
55endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010056find_package(ZLIB QUIET)
57CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
58 "ZLIB_FOUND" OFF)
59find_package(Libevent QUIET)
60CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
61 "Libevent_FOUND" OFF)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090062find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +010063CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON
64 "QT4_FOUND" OFF)
Nobuaki Sukegawa66228772014-12-07 21:45:33 +090065find_package(Qt5 QUIET COMPONENTS Core Network)
66CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
67 "Qt5_FOUND" OFF)
68if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3)
69 # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5
70 set(WITH_QT4 OFF)
71endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010072find_package(OpenSSL QUIET)
73CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090074 "OPENSSL_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010075option(WITH_STDTHREADS "Build with C++ std::thread support" OFF)
Sergei Nikulov34e0bb62015-09-02 13:06:22 +030076CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF
77 "NOT WITH_STDTHREADS;Boost_FOUND" OFF)
78
Pascal Bachd5f87e12014-12-12 15:59:17 +010079
80# C GLib
Roger Meier3b99c972015-04-20 22:49:48 +020081option(WITH_C_GLIB "Build C (GLib) Thrift library" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010082find_package(GLIB QUIET COMPONENTS gobject)
Roger Meier3b99c972015-04-20 22:49:48 +020083CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
84 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010085# Java
Roger Meier3b99c972015-04-20 22:49:48 +020086option(WITH_JAVA "Build Java Thrift library" ON)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090087if(ANDROID)
88 find_package(Gradle QUIET)
89 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
90 "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF)
91else()
Pascal Bach665844e2015-12-01 11:02:14 +010092 find_package(Java QUIET)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090093 find_package(Ant QUIET)
94 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
95 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;ANT_FOUND" OFF)
96endif()
Roger Meier26593812015-04-12 16:10:35 +020097
98# Python
Roger Meier3b99c972015-04-20 22:49:48 +020099option(WITH_PYTHON "Build Python Thrift library" ON)
100find_package(PythonInterp QUIET) # for Python executable
101find_package(PythonLibs QUIET) # for Python.h
102CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
103 "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100104
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900105# Haskell
106option(WITH_HASKELL "Build Haskell Thrift library" ON)
107find_package(GHC QUIET)
108find_package(Cabal QUIET)
109CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON
110 "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
111
Pascal Bachd5f87e12014-12-12 15:59:17 +0100112# Common library options
113option(WITH_SHARED_LIB "Build shared libraries" ON)
114option(WITH_STATIC_LIB "Build static libraries" ON)
Jim King9de9b1f2015-04-30 16:03:34 -0400115if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB)
116 message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!")
117endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100118
119#NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt
120
121# Visual Studio only options
122if(MSVC)
Jim King9de9b1f2015-04-30 16:03:34 -0400123option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100124endif(MSVC)
125
Roger Meier3b99c972015-04-20 22:49:48 +0200126macro(MESSAGE_DEP flag summary)
127if(NOT ${flag})
128 message(STATUS " - ${summary}")
129endif()
130endmacro(MESSAGE_DEP flag summary)
131
Pascal Bachd5f87e12014-12-12 15:59:17 +0100132macro(PRINT_CONFIG_SUMMARY)
133message(STATUS "----------------------------------------------------------")
134message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
135message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
136message(STATUS "Build configuration Summary")
137message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}")
138message(STATUS " Build with unit tests: ${BUILD_TESTING}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900139MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100140message(STATUS " Build examples: ${BUILD_EXAMPLES}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900141MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Roger Meier26593812015-04-12 16:10:35 +0200142message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100143message(STATUS " Language libraries:")
Roger Meier3b99c972015-04-20 22:49:48 +0200144message(STATUS " Build C++ library: ${BUILD_CPP}")
145MESSAGE_DEP(WITH_CPP "Disabled by via WITH_CCP=OFF")
146MESSAGE_DEP(Boost_FOUND "Boost headers missing")
147message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
148MESSAGE_DEP(WITH_C_GLIB "Disabled by via WITH_C_GLIB=OFF")
149MESSAGE_DEP(GLIB_FOUND "GLib missing")
150message(STATUS " Build Java library: ${BUILD_JAVA}")
151MESSAGE_DEP(WITH_JAVA "Disabled by via WITH_JAVA=OFF")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900152if(ANDROID)
153 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
154else()
155 MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
156 MESSAGE_DEP(ANT_FOUND "Ant missing")
157endif()
Roger Meier3b99c972015-04-20 22:49:48 +0200158message(STATUS " Build Python library: ${BUILD_PYTHON}")
159MESSAGE_DEP(WITH_PYTHON "Disabled by via WITH_PYTHON=OFF")
160MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900161message(STATUS " Build Haskell library: ${BUILD_HASKELL}")
162MESSAGE_DEP(WITH_HASKELL "Disabled by via WITH_HASKELL=OFF")
163MESSAGE_DEP(GHC_FOUND "GHC missing")
164MESSAGE_DEP(CABAL_FOUND "Cabal missing")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100165message(STATUS " Library features:")
166message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}")
167message(STATUS " Build static libraries: ${WITH_STATIC_LIB}")
168message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
169message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
170message(STATUS " Build with Qt4 support: ${WITH_QT4}")
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900171message(STATUS " Build with Qt5 support: ${WITH_QT5}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100172message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}")
173message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}")
174message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}")
175message(STATUS "----------------------------------------------------------")
176endmacro(PRINT_CONFIG_SUMMARY)