Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 21 | include(CMakeDependentOption) |
| 22 | |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 23 | set(THRIFT_COMPILER "" CACHE FILEPATH "External Thrift compiler to use during build") |
| 24 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 25 | # Additional components |
| 26 | option(BUILD_COMPILER "Build Thrift compiler" ON) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 27 | |
| 28 | if(BUILD_COMPILER OR EXISTS ${THRIFT_COMPILER}) |
| 29 | set(HAVE_COMPILER ON) |
| 30 | endif() |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 31 | CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 32 | CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF) |
Marco Molteni | 7f47792 | 2015-04-15 20:46:48 +0200 | [diff] [blame] | 33 | option(BUILD_LIBRARIES "Build Thrift libraries" ON) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 34 | |
| 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 III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 42 | if (NOT Boost_USE_STATIC_LIBS) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 43 | add_definitions(-DBOOST_ALL_DYN_LINK) |
| 44 | add_definitions(-DBOOST_TEST_DYN_LINK) |
| 45 | endif() |
| 46 | |
James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 47 | # as3 |
| 48 | option(WITH_AS3 "Build ActionScript 3 Thrift Library" ON) |
| 49 | if (WITH_AS3) |
| 50 | set(POSSIBLE_PATHS "${FLEX_HOME}/bin" "$ENV{FLEX_HOME}/bin") |
| 51 | find_program(HAVE_COMPC NAMES compc HINTS ${POSSIBLE_PATHS}) |
| 52 | endif () |
| 53 | CMAKE_DEPENDENT_OPTION(BUILD_AS3 "Build as3 library" ON |
| 54 | "BUILD_LIBRARIES;WITH_AS3;HAVE_COMPC" OFF) |
| 55 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 56 | # C++ |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 57 | option(WITH_CPP "Build C++ Thrift library" ON) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 58 | if(WITH_CPP) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 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 |
| 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 Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 73 | find_package(Qt5 QUIET COMPONENTS Core Network) |
| 74 | CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON |
| 75 | "Qt5_FOUND" OFF) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 76 | endif() |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 77 | CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 78 | "BUILD_LIBRARIES;WITH_CPP" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 79 | |
| 80 | # C GLib |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 81 | option(WITH_C_GLIB "Build C (GLib) Thrift library" ON) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 82 | if(WITH_C_GLIB) |
| 83 | find_package(GLIB QUIET COMPONENTS gobject) |
| 84 | endif() |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 85 | CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON |
| 86 | "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 87 | |
Kevin Wojniak | dbb95e4 | 2020-01-25 12:37:23 -0800 | [diff] [blame] | 88 | # OpenSSL |
| 89 | if(WITH_CPP OR WITH_C_GLIB) |
| 90 | find_package(OpenSSL QUIET) |
| 91 | CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON |
| 92 | "OPENSSL_FOUND" OFF) |
| 93 | endif() |
| 94 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 95 | # Java |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 96 | option(WITH_JAVA "Build Java Thrift library" ON) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 97 | if(ANDROID) |
| 98 | find_package(Gradle QUIET) |
| 99 | CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON |
| 100 | "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF) |
| 101 | else() |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 102 | find_package(Gradlew QUIET) |
Pascal Bach | 665844e | 2015-12-01 11:02:14 +0100 | [diff] [blame] | 103 | find_package(Java QUIET) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 104 | CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 105 | "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;GRADLEW_FOUND" OFF) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 106 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 107 | |
Mario Emmenlauer | 61d5020 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 108 | # Javascript |
| 109 | option(WITH_JAVASCRIPT "Build Javascript Thrift library" ON) |
| 110 | CMAKE_DEPENDENT_OPTION(BUILD_JAVASCRIPT "Build Javascript library" ON |
Mario Emmenlauer | 93171d2 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 111 | "BUILD_LIBRARIES;WITH_JAVASCRIPT;NOT WIN32; NOT CYGWIN" OFF) |
Mario Emmenlauer | 61d5020 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 112 | |
| 113 | # NodeJS |
| 114 | option(WITH_NODEJS "Build NodeJS Thrift library" ON) |
| 115 | CMAKE_DEPENDENT_OPTION(BUILD_NODEJS "Build NodeJS library" ON |
| 116 | "BUILD_LIBRARIES;WITH_NODEJS" OFF) |
| 117 | |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 118 | # Python |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 119 | option(WITH_PYTHON "Build Python Thrift library" ON) |
| 120 | find_package(PythonInterp QUIET) # for Python executable |
| 121 | find_package(PythonLibs QUIET) # for Python.h |
| 122 | CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 123 | "BUILD_LIBRARIES;WITH_PYTHON;PYTHONINTERP_FOUND;PYTHONLIBS_FOUND" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 124 | |
| 125 | # Common library options |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 126 | # https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html |
| 127 | # Default on Windows is static, shared mode library support needs work... |
Mario Emmenlauer | 1e243a7 | 2020-06-24 10:57:00 +0200 | [diff] [blame] | 128 | if(WIN32) |
| 129 | set(DEFAULT_BUILD_SHARED_LIBS ON) |
| 130 | else() |
| 131 | set(DEFAULT_BUILD_SHARED_LIBS OFF) |
| 132 | endif() |
| 133 | option(BUILD_SHARED_LIBS "Build shared libraries" ${DEFAULT_BUILD_SHARED_LIBS}) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 134 | |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 135 | if (WITH_SHARED_LIB) |
| 136 | message(WARNING "WITH_SHARED_LIB is deprecated; use -DBUILD_SHARED_LIBS=ON instead") |
| 137 | set(BUILD_SHARED_LIBS ON) |
| 138 | elseif (WITH_STATIC_LIB) |
| 139 | if (WITH_SHARED_LIB) |
| 140 | message(FATAL_ERROR "Cannot build shared and static together; set BUILD_SHARED_LIBS instead.") |
| 141 | endif () |
| 142 | message(WARNING "WITH_STATIC_LIB is deprecated; use -DBUILD_SHARED_LIBS=OFF instead") |
| 143 | set(BUILD_SHARED_LIBS OFF) |
| 144 | endif () |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 145 | |
| 146 | # Visual Studio only options |
| 147 | if(MSVC) |
Mario Emmenlauer | 654968a | 2021-08-02 21:25:22 +0200 | [diff] [blame] | 148 | option(WITH_MT "Build using the static runtime 'MT' instead of the shared DLL-specific runtime 'MD' (MSVC only)" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 149 | endif(MSVC) |
| 150 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 151 | macro(MESSAGE_DEP flag summary) |
| 152 | if(NOT ${flag}) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 153 | message(STATUS " - ${summary}") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 154 | endif() |
| 155 | endmacro(MESSAGE_DEP flag summary) |
| 156 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 157 | macro(PRINT_CONFIG_SUMMARY) |
| 158 | message(STATUS "----------------------------------------------------------") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 159 | message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") |
| 160 | message(STATUS "Thrift package version: ${PACKAGE_VERSION}") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 161 | message(STATUS) |
| 162 | message(STATUS "Build configuration summary") |
James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 163 | message(STATUS " Build compiler: ${BUILD_COMPILER}") |
James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 164 | message(STATUS " Build libraries: ${BUILD_LIBRARIES}") |
| 165 | message(STATUS " Build tests: ${BUILD_TESTING}") |
Kevin Wojniak | 1ce7317 | 2019-11-03 00:26:55 -0700 | [diff] [blame] | 166 | MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_COMPILER=OFF and no valid THRIFT_COMPILER is given") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 167 | message(STATUS " Build type: ${CMAKE_BUILD_TYPE}") |
| 168 | message(STATUS) |
| 169 | message(STATUS "Language libraries:") |
| 170 | message(STATUS) |
James E. King III | b1d63e7 | 2019-01-22 14:16:39 -0500 | [diff] [blame] | 171 | message(STATUS " Build as3 library: ${BUILD_AS3}") |
| 172 | MESSAGE_DEP(WITH_AS3 "Disabled by WITH_AS3=OFF") |
| 173 | MESSAGE_DEP(HAVE_COMPC "Adobe Flex compc was not found - did you set env var FLEX_HOME?") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 174 | message(STATUS) |
Kevin Wojniak | dbb95e4 | 2020-01-25 12:37:23 -0800 | [diff] [blame] | 175 | message(STATUS " Build with OpenSSL: ${WITH_OPENSSL}") |
| 176 | if(WITH_OPENSSL) |
| 177 | message(STATUS " Version: ${OPENSSL_VERSION}") |
| 178 | endif() |
| 179 | message(STATUS) |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 180 | message(STATUS " Build C++ library: ${BUILD_CPP}") |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 181 | MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 182 | if (BUILD_CPP) |
| 183 | message(STATUS " C++ Language Level: ${CXX_LANGUAGE_LEVEL}") |
| 184 | message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}") |
| 185 | message(STATUS " Build with libevent support: ${WITH_LIBEVENT}") |
| 186 | message(STATUS " Build with Qt5 support: ${WITH_QT5}") |
| 187 | message(STATUS " Build with ZLIB support: ${WITH_ZLIB}") |
| 188 | endif () |
| 189 | message(STATUS) |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 190 | message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}") |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 191 | MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 192 | MESSAGE_DEP(GLIB_FOUND "GLib missing") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 193 | message(STATUS) |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 194 | message(STATUS " Build Java library: ${BUILD_JAVA}") |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 195 | MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF") |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 196 | if(ANDROID) |
| 197 | MESSAGE_DEP(GRADLE_FOUND "Gradle missing") |
| 198 | else() |
| 199 | MESSAGE_DEP(JAVA_FOUND "Java Runtime missing") |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 200 | MESSAGE_DEP(GRADLEW_FOUND "Gradle Wrapper missing") |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 201 | endif() |
Mario Emmenlauer | 61d5020 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 202 | message(STATUS " Build Javascript library: ${BUILD_JAVASCRIPT}") |
| 203 | MESSAGE_DEP(WITH_JAVASCRIPT "Disabled by WITH_JAVASCRIPT=OFF") |
| 204 | message(STATUS " Build NodeJS library: ${BUILD_NODEJS}") |
| 205 | MESSAGE_DEP(WITH_NODEJS "Disabled by WITH_NODEJS=OFF") |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 206 | message(STATUS) |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 207 | message(STATUS " Build Python library: ${BUILD_PYTHON}") |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 208 | MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 209 | MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing") |
Mario Emmenlauer | 654968a | 2021-08-02 21:25:22 +0200 | [diff] [blame] | 210 | if(MSVC) |
| 211 | message(STATUS " Using static runtime library: ${WITH_MT}") |
| 212 | endif(MSVC) |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 213 | message(STATUS) |
James E. King III | 4c57be0 | 2019-01-27 11:12:43 -0500 | [diff] [blame] | 214 | message(STATUS) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 215 | message(STATUS "----------------------------------------------------------") |
| 216 | endmacro(PRINT_CONFIG_SUMMARY) |