blob: 928e19b165d1c906fa0e6acff3e470cc2bc54f5c [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()
James E. King III278528c2019-01-11 12:17:44 -050031CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090032CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF)
Marco Molteni7f477922015-04-15 20:46:48 +020033option(BUILD_LIBRARIES "Build Thrift libraries" ON)
Pascal Bachd5f87e12014-12-12 15:59:17 +010034
35# Libraries to build
36
37# Each language library can be enabled or disabled using the WITH_<LANG> flag.
38# By default CMake checks if the required dependencies for a language are present
39# and enables the library if all are found. This means the default is to build as
40# much as possible but leaving out libraries if their dependencies are not met.
41
James E. King III278528c2019-01-11 12:17:44 -050042if (NOT Boost_USE_STATIC_LIBS)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090043 add_definitions(-DBOOST_ALL_DYN_LINK)
44 add_definitions(-DBOOST_TEST_DYN_LINK)
45endif()
46
James E. King IIIb1d63e72019-01-22 14:16:39 -050047# as3
48option(WITH_AS3 "Build ActionScript 3 Thrift Library" ON)
49if (WITH_AS3)
50 set(POSSIBLE_PATHS "${FLEX_HOME}/bin" "$ENV{FLEX_HOME}/bin")
51 find_program(HAVE_COMPC NAMES compc HINTS ${POSSIBLE_PATHS})
52endif ()
53CMAKE_DEPENDENT_OPTION(BUILD_AS3 "Build as3 library" ON
54 "BUILD_LIBRARIES;WITH_AS3;HAVE_COMPC" OFF)
55
Pascal Bachd5f87e12014-12-12 15:59:17 +010056# C++
Roger Meier3b99c972015-04-20 22:49:48 +020057option(WITH_CPP "Build C++ Thrift library" ON)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090058if(WITH_CPP)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090059 # NOTE: Currently the following options are C++ specific,
60 # but in future other libraries might reuse them.
61 # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
62 # has no effect.
63 if(ZLIB_LIBRARY)
64 # FindZLIB.cmake does not normalize path so we need to do it ourselves.
65 file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
66 endif()
67 find_package(ZLIB QUIET)
68 CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
69 "ZLIB_FOUND" OFF)
70 find_package(Libevent QUIET)
71 CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
72 "Libevent_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090073 find_package(Qt5 QUIET COMPONENTS Core Network)
74 CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
75 "Qt5_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090076endif()
Roger Meier3b99c972015-04-20 22:49:48 +020077CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
James E. King IIIc9ac8d22019-01-07 16:46:45 -050078 "BUILD_LIBRARIES;WITH_CPP" OFF)
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)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090082if(WITH_C_GLIB)
83 find_package(GLIB QUIET COMPONENTS gobject)
84endif()
Roger Meier3b99c972015-04-20 22:49:48 +020085CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
86 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
Nobuaki Sukegawa33744b02016-01-03 14:24:39 +090087
Kevin Wojniakdbb95e42020-01-25 12:37:23 -080088# OpenSSL
89if(WITH_CPP OR WITH_C_GLIB)
James E. King III61080c62024-10-04 18:58:14 +000090 find_package(OpenSSL)
Kevin Wojniakdbb95e42020-01-25 12:37:23 -080091 CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
92 "OPENSSL_FOUND" OFF)
93endif()
94
Pascal Bachd5f87e12014-12-12 15:59:17 +010095# Java
Roger Meier3b99c972015-04-20 22:49:48 +020096option(WITH_JAVA "Build Java Thrift library" ON)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090097if(ANDROID)
98 find_package(Gradle QUIET)
99 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
100 "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF)
101else()
Jiayu Liu5d220eb2022-04-19 04:18:58 +0200102 find_package(Gradle QUIET)
Pascal Bach665844e2015-12-01 11:02:14 +0100103 find_package(Java QUIET)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900104 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
Jiayu Liu5d220eb2022-04-19 04:18:58 +0200105 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;GRADLE_FOUND" OFF)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900106endif()
Roger Meier26593812015-04-12 16:10:35 +0200107
Mario Emmenlauer61d50202019-10-23 17:32:34 +0200108# Javascript
109option(WITH_JAVASCRIPT "Build Javascript Thrift library" ON)
110CMAKE_DEPENDENT_OPTION(BUILD_JAVASCRIPT "Build Javascript library" ON
Mario Emmenlauer93171d22019-10-23 17:32:34 +0200111 "BUILD_LIBRARIES;WITH_JAVASCRIPT;NOT WIN32; NOT CYGWIN" OFF)
Mario Emmenlauer61d50202019-10-23 17:32:34 +0200112
113# NodeJS
114option(WITH_NODEJS "Build NodeJS Thrift library" ON)
115CMAKE_DEPENDENT_OPTION(BUILD_NODEJS "Build NodeJS library" ON
116 "BUILD_LIBRARIES;WITH_NODEJS" OFF)
117
Roger Meier26593812015-04-12 16:10:35 +0200118# Python
Roger Meier3b99c972015-04-20 22:49:48 +0200119option(WITH_PYTHON "Build Python Thrift library" ON)
Carel Combrink23e29d62025-11-10 14:00:18 +0200120find_package(Python3
121 COMPONENTS
122 Interpreter # for Python executable
123 Development # for Python.h
Carel Combrinkcdd8e3b2025-11-10 15:16:18 +0200124 )
Roger Meier3b99c972015-04-20 22:49:48 +0200125CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
Carel Combrink23e29d62025-11-10 14:00:18 +0200126 "BUILD_LIBRARIES;WITH_PYTHON;Python3_Interpreter_FOUND;Python3_Development_FOUND" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100127
128# Common library options
James E. King III278528c2019-01-11 12:17:44 -0500129# https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
130# Default on Windows is static, shared mode library support needs work...
Mario Emmenlauer1e243a72020-06-24 10:57:00 +0200131if(WIN32)
132 set(DEFAULT_BUILD_SHARED_LIBS ON)
133else()
134 set(DEFAULT_BUILD_SHARED_LIBS OFF)
135endif()
136option(BUILD_SHARED_LIBS "Build shared libraries" ${DEFAULT_BUILD_SHARED_LIBS})
Pascal Bachd5f87e12014-12-12 15:59:17 +0100137
James E. King III278528c2019-01-11 12:17:44 -0500138if (WITH_SHARED_LIB)
139 message(WARNING "WITH_SHARED_LIB is deprecated; use -DBUILD_SHARED_LIBS=ON instead")
140 set(BUILD_SHARED_LIBS ON)
141elseif (WITH_STATIC_LIB)
142 if (WITH_SHARED_LIB)
143 message(FATAL_ERROR "Cannot build shared and static together; set BUILD_SHARED_LIBS instead.")
144 endif ()
145 message(WARNING "WITH_STATIC_LIB is deprecated; use -DBUILD_SHARED_LIBS=OFF instead")
146 set(BUILD_SHARED_LIBS OFF)
147endif ()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100148
149# Visual Studio only options
150if(MSVC)
Mario Emmenlauer654968a2021-08-02 21:25:22 +0200151 option(WITH_MT "Build using the static runtime 'MT' instead of the shared DLL-specific runtime 'MD' (MSVC only)" OFF)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100152endif(MSVC)
153
Roger Meier3b99c972015-04-20 22:49:48 +0200154macro(MESSAGE_DEP flag summary)
155if(NOT ${flag})
James E. King III278528c2019-01-11 12:17:44 -0500156 message(STATUS " - ${summary}")
Roger Meier3b99c972015-04-20 22:49:48 +0200157endif()
158endmacro(MESSAGE_DEP flag summary)
159
Pascal Bachd5f87e12014-12-12 15:59:17 +0100160macro(PRINT_CONFIG_SUMMARY)
161message(STATUS "----------------------------------------------------------")
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100162message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
163message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
James E. King III4c57be02019-01-27 11:12:43 -0500164message(STATUS)
165message(STATUS "Build configuration summary")
James E. King IIIb1d63e72019-01-22 14:16:39 -0500166message(STATUS " Build compiler: ${BUILD_COMPILER}")
James E. King IIIb1d63e72019-01-22 14:16:39 -0500167message(STATUS " Build libraries: ${BUILD_LIBRARIES}")
168message(STATUS " Build tests: ${BUILD_TESTING}")
Kevin Wojniak1ce73172019-11-03 00:26:55 -0700169MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_COMPILER=OFF and no valid THRIFT_COMPILER is given")
James E. King III4c57be02019-01-27 11:12:43 -0500170message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
171message(STATUS)
172message(STATUS "Language libraries:")
173message(STATUS)
James E. King IIIb1d63e72019-01-22 14:16:39 -0500174message(STATUS " Build as3 library: ${BUILD_AS3}")
175MESSAGE_DEP(WITH_AS3 "Disabled by WITH_AS3=OFF")
176MESSAGE_DEP(HAVE_COMPC "Adobe Flex compc was not found - did you set env var FLEX_HOME?")
James E. King III4c57be02019-01-27 11:12:43 -0500177message(STATUS)
Kevin Wojniakdbb95e42020-01-25 12:37:23 -0800178message(STATUS " Build with OpenSSL: ${WITH_OPENSSL}")
179if(WITH_OPENSSL)
180 message(STATUS " Version: ${OPENSSL_VERSION}")
181endif()
182message(STATUS)
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100183message(STATUS " Build C++ library: ${BUILD_CPP}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500184MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF")
James E. King III4c57be02019-01-27 11:12:43 -0500185if (BUILD_CPP)
186 message(STATUS " C++ Language Level: ${CXX_LANGUAGE_LEVEL}")
187 message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
188 message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
189 message(STATUS " Build with Qt5 support: ${WITH_QT5}")
190 message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
191endif ()
192message(STATUS)
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100193message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500194MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF")
Roger Meier3b99c972015-04-20 22:49:48 +0200195MESSAGE_DEP(GLIB_FOUND "GLib missing")
James E. King III4c57be02019-01-27 11:12:43 -0500196message(STATUS)
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100197message(STATUS " Build Java library: ${BUILD_JAVA}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500198MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900199if(ANDROID)
200 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
201else()
202 MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
Jiayu Liu5d220eb2022-04-19 04:18:58 +0200203 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
Nobuaki Sukegawaca939362015-11-14 00:23:40 +0900204endif()
Mario Emmenlauer61d50202019-10-23 17:32:34 +0200205message(STATUS " Build Javascript library: ${BUILD_JAVASCRIPT}")
206MESSAGE_DEP(WITH_JAVASCRIPT "Disabled by WITH_JAVASCRIPT=OFF")
207message(STATUS " Build NodeJS library: ${BUILD_NODEJS}")
208MESSAGE_DEP(WITH_NODEJS "Disabled by WITH_NODEJS=OFF")
James E. King III4c57be02019-01-27 11:12:43 -0500209message(STATUS)
Antonio Di Monaco796667b2016-01-04 23:05:19 +0100210message(STATUS " Build Python library: ${BUILD_PYTHON}")
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500211MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF")
Carel Combrinkcdd8e3b2025-11-10 15:16:18 +0200212MESSAGE_DEP(Python3_Interpreter_FOUND "Python interpreter missing")
Carel Combrink23e29d62025-11-10 14:00:18 +0200213MESSAGE_DEP(Python3_Development_FOUND "Python libraries missing")
Carel Combrinkcdd8e3b2025-11-10 15:16:18 +0200214if(BUILD_PYTHON)
215 message(STATUS " Version: ${Python3_VERSION}")
216endif()
Mario Emmenlauer654968a2021-08-02 21:25:22 +0200217if(MSVC)
218 message(STATUS " Using static runtime library: ${WITH_MT}")
219endif(MSVC)
James E. King III4c57be02019-01-27 11:12:43 -0500220message(STATUS)
James E. King III4c57be02019-01-27 11:12:43 -0500221message(STATUS)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100222message(STATUS "----------------------------------------------------------")
223endmacro(PRINT_CONFIG_SUMMARY)