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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
21 include(CMakeDependentOption)
23 set(THRIFT_COMPILER "" CACHE FILEPATH "External Thrift compiler to use during build")
25 # Additional components
26 option(BUILD_COMPILER "Build Thrift compiler" ON)
28 if(BUILD_COMPILER OR EXISTS ${THRIFT_COMPILER})
31 CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF)
32 CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF)
33 option(BUILD_LIBRARIES "Build Thrift libraries" ON)
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.
42 if (NOT Boost_USE_STATIC_LIBS)
43 add_definitions(-DBOOST_ALL_DYN_LINK)
44 add_definitions(-DBOOST_TEST_DYN_LINK)
48 option(WITH_AS3 "Build ActionScript 3 Thrift Library" ON)
50 set(POSSIBLE_PATHS "${FLEX_HOME}/bin" "$ENV{FLEX_HOME}/bin")
51 find_program(HAVE_COMPC NAMES compc HINTS ${POSSIBLE_PATHS})
53 CMAKE_DEPENDENT_OPTION(BUILD_AS3 "Build as3 library" ON
54 "BUILD_LIBRARIES;WITH_AS3;HAVE_COMPC" OFF)
57 option(WITH_CPP "Build C++ Thrift library" ON)
59 # 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
64 # FindZLIB.cmake does not normalize path so we need to do it ourselves.
65 file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
67 find_package(ZLIB QUIET)
68 CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
70 find_package(Libevent QUIET)
71 CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON
73 find_package(Qt5 QUIET COMPONENTS Core Network)
74 CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
76 find_package(OpenSSL QUIET)
77 CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
80 CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
81 "BUILD_LIBRARIES;WITH_CPP" OFF)
84 option(WITH_C_GLIB "Build C (GLib) Thrift library" ON)
86 find_package(GLIB QUIET COMPONENTS gobject)
88 CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
89 "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
92 option(WITH_JAVA "Build Java Thrift library" ON)
94 find_package(Gradle QUIET)
95 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
96 "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF)
98 find_package(Gradlew QUIET)
99 find_package(Java QUIET)
100 CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON
101 "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;GRADLEW_FOUND" OFF)
105 option(WITH_PYTHON "Build Python Thrift library" ON)
106 find_package(PythonInterp QUIET) # for Python executable
107 find_package(PythonLibs QUIET) # for Python.h
108 CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
109 "BUILD_LIBRARIES;WITH_PYTHON;PYTHONINTERP_FOUND;PYTHONLIBS_FOUND" OFF)
112 option(WITH_HASKELL "Build Haskell Thrift library" ON)
113 find_package(GHC QUIET)
114 find_package(Cabal QUIET)
115 CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON
116 "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
118 # Common library options
119 # https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
120 # Default on Windows is static, shared mode library support needs work...
121 CMAKE_DEPENDENT_OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF "WIN32" ON)
124 message(WARNING "WITH_SHARED_LIB is deprecated; use -DBUILD_SHARED_LIBS=ON instead")
125 set(BUILD_SHARED_LIBS ON)
126 elseif (WITH_STATIC_LIB)
128 message(FATAL_ERROR "Cannot build shared and static together; set BUILD_SHARED_LIBS instead.")
130 message(WARNING "WITH_STATIC_LIB is deprecated; use -DBUILD_SHARED_LIBS=OFF instead")
131 set(BUILD_SHARED_LIBS OFF)
134 # Visual Studio only options
136 option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF)
139 macro(MESSAGE_DEP flag summary)
141 message(STATUS " - ${summary}")
143 endmacro(MESSAGE_DEP flag summary)
145 macro(PRINT_CONFIG_SUMMARY)
146 message(STATUS "----------------------------------------------------------")
147 message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
148 message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
150 message(STATUS "Build configuration summary")
151 message(STATUS " Build compiler: ${BUILD_COMPILER}")
152 message(STATUS " Build libraries: ${BUILD_LIBRARIES}")
153 message(STATUS " Build tests: ${BUILD_TESTING}")
154 MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given")
155 message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
157 message(STATUS "Language libraries:")
159 message(STATUS " Build as3 library: ${BUILD_AS3}")
160 MESSAGE_DEP(WITH_AS3 "Disabled by WITH_AS3=OFF")
161 MESSAGE_DEP(HAVE_COMPC "Adobe Flex compc was not found - did you set env var FLEX_HOME?")
163 message(STATUS " Build C++ library: ${BUILD_CPP}")
164 MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF")
166 message(STATUS " C++ Language Level: ${CXX_LANGUAGE_LEVEL}")
167 message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
168 message(STATUS " Build with libevent support: ${WITH_LIBEVENT}")
169 message(STATUS " Build with Qt5 support: ${WITH_QT5}")
170 message(STATUS " Build with ZLIB support: ${WITH_ZLIB}")
173 message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}")
174 MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF")
175 MESSAGE_DEP(GLIB_FOUND "GLib missing")
177 message(STATUS " Build Java library: ${BUILD_JAVA}")
178 MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF")
180 MESSAGE_DEP(GRADLE_FOUND "Gradle missing")
182 MESSAGE_DEP(JAVA_FOUND "Java Runtime missing")
183 MESSAGE_DEP(GRADLEW_FOUND "Gradle Wrapper missing")
186 message(STATUS " Build Python library: ${BUILD_PYTHON}")
187 MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF")
188 MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
190 message(STATUS " Build Haskell library: ${BUILD_HASKELL}")
191 MESSAGE_DEP(WITH_HASKELL "Disabled by WITH_HASKELL=OFF")
192 MESSAGE_DEP(GHC_FOUND "GHC missing")
193 MESSAGE_DEP(CABAL_FOUND "Cabal missing")
195 message(STATUS "----------------------------------------------------------")
196 endmacro(PRINT_CONFIG_SUMMARY)