blob: 9aff53c16bb0736ed0d8a79131a9794a7f719ee7 [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
James E. King, III07f59972017-03-10 06:18:33 -050043option(WITH_BOOST_STATIC "Build with Boost static link library" OFF)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090044set(Boost_USE_STATIC_LIBS ${WITH_BOOST_STATIC})
45if (NOT WITH_BOOST_STATIC)
46 add_definitions(-DBOOST_ALL_DYN_LINK)
47 add_definitions(-DBOOST_TEST_DYN_LINK)
48endif()
49
Pascal Bachd5f87e12014-12-12 15:59:17 +010050# C++
Roger Meier3b99c972015-04-20 22:49:48 +020051option(WITH_CPP "Build C++ Thrift library" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090052if(WITH_CPP)
53 find_package(Boost 1.53 QUIET)
54 # NOTE: Currently the following options are C++ specific,
55 # but in future other libraries might reuse them.
56 # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
57 # has no effect.
58 if(ZLIB_LIBRARY)
59 # FindZLIB.cmake does not normalize path so we need to do it ourselves.
60 file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
61 endif()
62 find_package(ZLIB QUIET)
63 CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
64 "ZLIB_FOUND" OFF)
65 find_package(Libevent QUIET)
66 CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
67 "Libevent_FOUND" OFF)
68 find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork)
69 CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON
70 "QT4_FOUND" OFF)
71 find_package(Qt5 QUIET COMPONENTS Core Network)
72 CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
73 "Qt5_FOUND" OFF)
74 if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3)
75 # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5
76 set(WITH_QT4 OFF)
77 endif()
78 find_package(OpenSSL QUIET)
79 CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
80 "OPENSSL_FOUND" OFF)
cyyc109e012019-01-05 13:45:07 +080081 option(WITH_STDTHREADS "Build with C++ std::thread support" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090082endif()
Roger Meier3b99c972015-04-20 22:49:48 +020083CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
84 "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF)
James E. King, III71eba642017-01-25 20:41:06 -050085CMAKE_DEPENDENT_OPTION(WITH_PLUGIN "Build compiler plugin support" OFF
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090086 "BUILD_COMPILER;BUILD_CPP" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010087
88# C GLib
Roger Meier3b99c972015-04-20 22:49:48 +020089option(WITH_C_GLIB "Build C (GLib) Thrift library" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090090if(WITH_C_GLIB)
91 find_package(GLIB QUIET COMPONENTS gobject)
92endif()
Roger Meier3b99c972015-04-20 22:49:48 +020093CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
94 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090095
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090096if(BUILD_CPP)
97 set(boost_components)
cyyc109e012019-01-05 13:45:07 +080098 if(BUILD_TESTING)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090099 list(APPEND boost_components system thread)
100 endif()
101 if(BUILD_TESTING)
102 list(APPEND boost_components unit_test_framework filesystem chrono program_options)
103 endif()
104 if(boost_components)
105 find_package(Boost 1.53 REQUIRED COMPONENTS ${boost_components})
106 endif()
107elseif(BUILD_C_GLIB AND BUILD_TESTING)
108 find_package(Boost 1.53 REQUIRED)
109endif()
110
Pascal Bachd5f87e12014-12-12 15:59:17 +0100111# Java
Roger Meier3b99c972015-04-20 22:49:48 +0200112option(WITH_JAVA "Build Java Thrift library" ON)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900113if(ANDROID)
114 find_package(Gradle QUIET)
115 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
116 "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF)
117else()
Alex Volanis7004a612018-01-24 10:30:13 -0500118 find_package(Gradlew QUIET)
Pascal Bach665844e2015-12-01 11:02:14 +0100119 find_package(Java QUIET)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900120 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
Alex Volanis7004a612018-01-24 10:30:13 -0500121 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;GRADLEW_FOUND" OFF)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900122endif()
Roger Meier26593812015-04-12 16:10:35 +0200123
124# Python
Roger Meier3b99c972015-04-20 22:49:48 +0200125option(WITH_PYTHON "Build Python Thrift library" ON)
126find_package(PythonInterp QUIET) # for Python executable
127find_package(PythonLibs QUIET) # for Python.h
128CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
Nobuaki Sukegawabf9fa902016-09-04 18:49:21 +0900129 "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100130
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900131# Haskell
132option(WITH_HASKELL "Build Haskell Thrift library" ON)
133find_package(GHC QUIET)
134find_package(Cabal QUIET)
135CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON
136 "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
137
Pascal Bachd5f87e12014-12-12 15:59:17 +0100138# Common library options
139option(WITH_SHARED_LIB "Build shared libraries" ON)
140option(WITH_STATIC_LIB "Build static libraries" ON)
Jim King9de9b1f2015-04-30 16:03:34 -0400141if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB)
142 message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!")
143endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100144
145#NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt
146
147# Visual Studio only options
148if(MSVC)
Jim King9de9b1f2015-04-30 16:03:34 -0400149option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100150endif(MSVC)
151
Roger Meier3b99c972015-04-20 22:49:48 +0200152macro(MESSAGE_DEP flag summary)
153if(NOT ${flag})
154 message(STATUS " - ${summary}")
155endif()
156endmacro(MESSAGE_DEP flag summary)
157
Pascal Bachd5f87e12014-12-12 15:59:17 +0100158macro(PRINT_CONFIG_SUMMARY)
159message(STATUS "----------------------------------------------------------")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100160message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
161message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100162message(STATUS "Build configuration Summary")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100163message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}")
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900164message(STATUS " Build compiler plugin support: ${WITH_PLUGIN}")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100165message(STATUS " Build with unit tests: ${BUILD_TESTING}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900166MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100167message(STATUS " Build examples: ${BUILD_EXAMPLES}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900168MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100169message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100170message(STATUS " Language libraries:")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100171message(STATUS " Build C++ library: ${BUILD_CPP}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500172MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200173MESSAGE_DEP(Boost_FOUND "Boost headers missing")
James E. King, III43e959b2017-04-04 13:04:29 -0400174message(STATUS " C++ Language Level: ${CXX_LANGUAGE_LEVEL}")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100175message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500176MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200177MESSAGE_DEP(GLIB_FOUND "GLib missing")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100178message(STATUS " Build Java library: ${BUILD_JAVA}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500179MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900180if(ANDROID)
181 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
182else()
183 MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
Alex Volanis7004a612018-01-24 10:30:13 -0500184 MESSAGE_DEP(GRADLEW_FOUND "Gradle Wrapper missing")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900185endif()
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100186message(STATUS " Build Python library: ${BUILD_PYTHON}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500187MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200188MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100189message(STATUS " Build Haskell library: ${BUILD_HASKELL}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500190MESSAGE_DEP(WITH_HASKELL "Disabled by WITH_HASKELL=OFF")
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900191MESSAGE_DEP(GHC_FOUND "GHC missing")
192MESSAGE_DEP(CABAL_FOUND "Cabal missing")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100193message(STATUS " Library features:")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100194message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}")
195message(STATUS " Build static libraries: ${WITH_STATIC_LIB}")
James E. King, III07f59972017-03-10 06:18:33 -0500196message(STATUS " Build with Boost static link library: ${WITH_BOOST_STATIC}")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100197message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}")
James E. King, III07f59972017-03-10 06:18:33 -0500198message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
199message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}")
200message(STATUS " Build with Qt4 support: ${WITH_QT4}")
201message(STATUS " Build with Qt5 support: ${WITH_QT5}")
202message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100203message(STATUS "----------------------------------------------------------")
204endmacro(PRINT_CONFIG_SUMMARY)