blob: adedcc807c2f6437d0e5ed6a83aa4a845aa76eb4 [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
23# Additional components
24option(BUILD_COMPILER "Build Thrift compiler" ON)
25option(BUILD_TESTING "Build with unit tests" ON)
26option(BUILD_EXAMPLES "Build examples" ON)
Marco Molteni7f477922015-04-15 20:46:48 +020027option(BUILD_LIBRARIES "Build Thrift libraries" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010028
29# Libraries to build
30
31# Each language library can be enabled or disabled using the WITH_<LANG> flag.
32# By default CMake checks if the required dependencies for a language are present
33# and enables the library if all are found. This means the default is to build as
34# much as possible but leaving out libraries if their dependencies are not met.
35
36# C++
Roger Meier3b99c972015-04-20 22:49:48 +020037option(WITH_CPP "Build C++ Thrift library" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010038find_package(Boost 1.53 QUIET)
Roger Meier3b99c972015-04-20 22:49:48 +020039CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
40 "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010041# NOTE: Currently the following options are C++ specific,
42# but in future other libraries might reuse them.
Marco Molteni83494252015-04-16 13:50:20 +020043# So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
Pascal Bachd5f87e12014-12-12 15:59:17 +010044# has no effect.
45find_package(ZLIB QUIET)
46CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
47 "ZLIB_FOUND" OFF)
48find_package(Libevent QUIET)
49CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
50 "Libevent_FOUND" OFF)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090051find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork)
Pascal Bachd5f87e12014-12-12 15:59:17 +010052CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON
53 "QT4_FOUND" OFF)
Nobuaki Sukegawa66228772014-12-07 21:45:33 +090054find_package(Qt5 QUIET COMPONENTS Core Network)
55CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
56 "Qt5_FOUND" OFF)
57if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3)
58 # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5
59 set(WITH_QT4 OFF)
60endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010061find_package(OpenSSL QUIET)
62CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090063 "OPENSSL_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010064option(WITH_BOOSTTHREADS "Build with Boost thread support" OFF)
65option(WITH_STDTHREADS "Build with C++ std::thread support" OFF)
66
67# C GLib
Roger Meier3b99c972015-04-20 22:49:48 +020068option(WITH_C_GLIB "Build C (GLib) Thrift library" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010069find_package(GLIB QUIET COMPONENTS gobject)
Roger Meier3b99c972015-04-20 22:49:48 +020070CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
71 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010072# Java
Roger Meier3b99c972015-04-20 22:49:48 +020073option(WITH_JAVA "Build Java Thrift library" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010074find_package(Java QUIET)
Sergei Nikulov9d8c1bf2015-01-30 13:29:33 +030075find_package(Ant QUIET)
Roger Meier3b99c972015-04-20 22:49:48 +020076CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
77 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;ANT_FOUND" OFF)
Roger Meier26593812015-04-12 16:10:35 +020078
79# Python
Roger Meier3b99c972015-04-20 22:49:48 +020080option(WITH_PYTHON "Build Python Thrift library" ON)
81find_package(PythonInterp QUIET) # for Python executable
82find_package(PythonLibs QUIET) # for Python.h
83CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
84 "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010085
86# Common library options
87option(WITH_SHARED_LIB "Build shared libraries" ON)
88option(WITH_STATIC_LIB "Build static libraries" ON)
Jim King9de9b1f2015-04-30 16:03:34 -040089if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB)
90 message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!")
91endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010092
93#NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt
94
95# Visual Studio only options
96if(MSVC)
Jim King9de9b1f2015-04-30 16:03:34 -040097option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010098endif(MSVC)
99
Roger Meier3b99c972015-04-20 22:49:48 +0200100macro(MESSAGE_DEP flag summary)
101if(NOT ${flag})
102 message(STATUS " - ${summary}")
103endif()
104endmacro(MESSAGE_DEP flag summary)
105
Pascal Bachd5f87e12014-12-12 15:59:17 +0100106macro(PRINT_CONFIG_SUMMARY)
107message(STATUS "----------------------------------------------------------")
108message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
109message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
110message(STATUS "Build configuration Summary")
111message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}")
112message(STATUS " Build with unit tests: ${BUILD_TESTING}")
113message(STATUS " Build examples: ${BUILD_EXAMPLES}")
Roger Meier26593812015-04-12 16:10:35 +0200114message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100115message(STATUS " Language libraries:")
Roger Meier3b99c972015-04-20 22:49:48 +0200116message(STATUS " Build C++ library: ${BUILD_CPP}")
117MESSAGE_DEP(WITH_CPP "Disabled by via WITH_CCP=OFF")
118MESSAGE_DEP(Boost_FOUND "Boost headers missing")
119message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
120MESSAGE_DEP(WITH_C_GLIB "Disabled by via WITH_C_GLIB=OFF")
121MESSAGE_DEP(GLIB_FOUND "GLib missing")
122message(STATUS " Build Java library: ${BUILD_JAVA}")
123MESSAGE_DEP(WITH_JAVA "Disabled by via WITH_JAVA=OFF")
124MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
125MESSAGE_DEP(ANT_FOUND "Ant missing")
126message(STATUS " Build Python library: ${BUILD_PYTHON}")
127MESSAGE_DEP(WITH_PYTHON "Disabled by via WITH_PYTHON=OFF")
128MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100129message(STATUS " Library features:")
130message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}")
131message(STATUS " Build static libraries: ${WITH_STATIC_LIB}")
132message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
133message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
134message(STATUS " Build with Qt4 support: ${WITH_QT4}")
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900135message(STATUS " Build with Qt5 support: ${WITH_QT5}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100136message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}")
137message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}")
138message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}")
139message(STATUS "----------------------------------------------------------")
140endmacro(PRINT_CONFIG_SUMMARY)