blob: 8e334d9c23f383cac91061e7dbb6ee4a2bd36599 [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()
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090031CMAKE_DEPENDENT_OPTION(BUILD_EXAMPLES "Build examples" ON "HAVE_COMPILER" OFF)
James E. King III278528c2019-01-11 12:17:44 -050032CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090033CMAKE_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 III278528c2019-01-11 12:17:44 -050043if (NOT Boost_USE_STATIC_LIBS)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090044 add_definitions(-DBOOST_ALL_DYN_LINK)
45 add_definitions(-DBOOST_TEST_DYN_LINK)
46endif()
47
Pascal Bachd5f87e12014-12-12 15:59:17 +010048# C++
Roger Meier3b99c972015-04-20 22:49:48 +020049option(WITH_CPP "Build C++ Thrift library" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090050if(WITH_CPP)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090051 # NOTE: Currently the following options are C++ specific,
52 # but in future other libraries might reuse them.
53 # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
54 # has no effect.
55 if(ZLIB_LIBRARY)
56 # FindZLIB.cmake does not normalize path so we need to do it ourselves.
57 file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
58 endif()
59 find_package(ZLIB QUIET)
60 CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
61 "ZLIB_FOUND" OFF)
62 find_package(Libevent QUIET)
63 CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
64 "Libevent_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090065 find_package(Qt5 QUIET COMPONENTS Core Network)
66 CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
67 "Qt5_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090068 find_package(OpenSSL QUIET)
69 CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
70 "OPENSSL_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090071endif()
Roger Meier3b99c972015-04-20 22:49:48 +020072CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
James E. King IIIc9ac8d22019-01-07 16:46:45 -050073 "BUILD_LIBRARIES;WITH_CPP" OFF)
James E. King, III71eba642017-01-25 20:41:06 -050074CMAKE_DEPENDENT_OPTION(WITH_PLUGIN "Build compiler plugin support" OFF
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090075 "BUILD_COMPILER;BUILD_CPP" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +010076
77# C GLib
Roger Meier3b99c972015-04-20 22:49:48 +020078option(WITH_C_GLIB "Build C (GLib) Thrift library" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090079if(WITH_C_GLIB)
80 find_package(GLIB QUIET COMPONENTS gobject)
81endif()
Roger Meier3b99c972015-04-20 22:49:48 +020082CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
83 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090084
James E. King IIIc9ac8d22019-01-07 16:46:45 -050085 #if(BUILD_C_GLIB AND BUILD_TESTING)
86 # find_package(Boost 1.53 REQUIRED)
87 #endif()
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090088
Pascal Bachd5f87e12014-12-12 15:59:17 +010089# Java
Roger Meier3b99c972015-04-20 22:49:48 +020090option(WITH_JAVA "Build Java Thrift library" ON)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090091if(ANDROID)
92 find_package(Gradle QUIET)
93 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
94 "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF)
95else()
Alex Volanis7004a612018-01-24 10:30:13 -050096 find_package(Gradlew QUIET)
Pascal Bach665844e2015-12-01 11:02:14 +010097 find_package(Java QUIET)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090098 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
Alex Volanis7004a612018-01-24 10:30:13 -050099 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;GRADLEW_FOUND" OFF)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900100endif()
Roger Meier26593812015-04-12 16:10:35 +0200101
102# Python
Roger Meier3b99c972015-04-20 22:49:48 +0200103option(WITH_PYTHON "Build Python Thrift library" ON)
104find_package(PythonInterp QUIET) # for Python executable
105find_package(PythonLibs QUIET) # for Python.h
106CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
James E. King III278528c2019-01-11 12:17:44 -0500107 "BUILD_LIBRARIES;WITH_PYTHON;PYTHONINTERP_FOUND;PYTHONLIBS_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100108
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900109# Haskell
110option(WITH_HASKELL "Build Haskell Thrift library" ON)
111find_package(GHC QUIET)
112find_package(Cabal QUIET)
113CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON
114 "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
115
Pascal Bachd5f87e12014-12-12 15:59:17 +0100116# Common library options
James E. King III278528c2019-01-11 12:17:44 -0500117# https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
118# Default on Windows is static, shared mode library support needs work...
119CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF "WIN32" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100120
James E. King III278528c2019-01-11 12:17:44 -0500121if (WITH_SHARED_LIB)
122 message(WARNING "WITH_SHARED_LIB is deprecated; use -DBUILD_SHARED_LIBS=ON instead")
123 set(BUILD_SHARED_LIBS ON)
124elseif (WITH_STATIC_LIB)
125 if (WITH_SHARED_LIB)
126 message(FATAL_ERROR "Cannot build shared and static together; set BUILD_SHARED_LIBS instead.")
127 endif ()
128 message(WARNING "WITH_STATIC_LIB is deprecated; use -DBUILD_SHARED_LIBS=OFF instead")
129 set(BUILD_SHARED_LIBS OFF)
130endif ()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100131
132# Visual Studio only options
133if(MSVC)
James E. King III278528c2019-01-11 12:17:44 -0500134 option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100135endif(MSVC)
136
Roger Meier3b99c972015-04-20 22:49:48 +0200137macro(MESSAGE_DEP flag summary)
138if(NOT ${flag})
James E. King III278528c2019-01-11 12:17:44 -0500139 message(STATUS " - ${summary}")
Roger Meier3b99c972015-04-20 22:49:48 +0200140endif()
141endmacro(MESSAGE_DEP flag summary)
142
Pascal Bachd5f87e12014-12-12 15:59:17 +0100143macro(PRINT_CONFIG_SUMMARY)
144message(STATUS "----------------------------------------------------------")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100145message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
146message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100147message(STATUS "Build configuration Summary")
James E. King IIIef32bc12019-01-17 14:08:44 -0500148if (UNIX)
149 message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
150endif ()
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100151message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}")
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900152message(STATUS " Build compiler plugin support: ${WITH_PLUGIN}")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100153message(STATUS " Build with unit tests: ${BUILD_TESTING}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900154MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100155message(STATUS " Build examples: ${BUILD_EXAMPLES}")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900156MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100157message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100158message(STATUS " Language libraries:")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100159message(STATUS " Build C++ library: ${BUILD_CPP}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500160MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF")
James E. King, III43e959b2017-04-04 13:04:29 -0400161message(STATUS " C++ Language Level: ${CXX_LANGUAGE_LEVEL}")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100162message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500163MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200164MESSAGE_DEP(GLIB_FOUND "GLib missing")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100165message(STATUS " Build Java library: ${BUILD_JAVA}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500166MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900167if(ANDROID)
168 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
169else()
170 MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
Alex Volanis7004a612018-01-24 10:30:13 -0500171 MESSAGE_DEP(GRADLEW_FOUND "Gradle Wrapper missing")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900172endif()
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100173message(STATUS " Build Python library: ${BUILD_PYTHON}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500174MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200175MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100176message(STATUS " Build Haskell library: ${BUILD_HASKELL}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500177MESSAGE_DEP(WITH_HASKELL "Disabled by WITH_HASKELL=OFF")
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900178MESSAGE_DEP(GHC_FOUND "GHC missing")
179MESSAGE_DEP(CABAL_FOUND "Cabal missing")
James E. King III278528c2019-01-11 12:17:44 -0500180if (BUILD_CPP)
181 message(STATUS " Library features:")
182 message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
183 message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
James E. King III278528c2019-01-11 12:17:44 -0500184 message(STATUS " Build with Qt5 support: ${WITH_QT5}")
185 message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
186endif ()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100187message(STATUS "----------------------------------------------------------")
188endmacro(PRINT_CONFIG_SUMMARY)