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() |
| 31 | CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF) |
| 32 | CMAKE_DEPENDENT_OPTION(BUILD_EXAMPLES "Build examples" ON "HAVE_COMPILER" OFF) |
| 33 | CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF) |
Marco Molteni | 7f47792 | 2015-04-15 20:46:48 +0200 | [diff] [blame] | 34 | option(BUILD_LIBRARIES "Build Thrift libraries" ON) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 35 | |
| 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 | |
| 43 | # C++ |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 44 | option(WITH_CPP "Build C++ Thrift library" ON) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 45 | if(WITH_CPP) |
| 46 | find_package(Boost 1.53 QUIET) |
| 47 | # NOTE: Currently the following options are C++ specific, |
| 48 | # but in future other libraries might reuse them. |
| 49 | # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently |
| 50 | # has no effect. |
| 51 | if(ZLIB_LIBRARY) |
| 52 | # FindZLIB.cmake does not normalize path so we need to do it ourselves. |
| 53 | file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY) |
| 54 | endif() |
| 55 | find_package(ZLIB QUIET) |
| 56 | CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON |
| 57 | "ZLIB_FOUND" OFF) |
| 58 | find_package(Libevent QUIET) |
| 59 | CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON |
| 60 | "Libevent_FOUND" OFF) |
| 61 | find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork) |
| 62 | CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON |
| 63 | "QT4_FOUND" OFF) |
| 64 | find_package(Qt5 QUIET COMPONENTS Core Network) |
| 65 | CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON |
| 66 | "Qt5_FOUND" OFF) |
| 67 | if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3) |
| 68 | # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5 |
| 69 | set(WITH_QT4 OFF) |
| 70 | endif() |
| 71 | find_package(OpenSSL QUIET) |
| 72 | CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON |
| 73 | "OPENSSL_FOUND" OFF) |
| 74 | option(WITH_STDTHREADS "Build with C++ std::thread support" OFF) |
| 75 | CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF |
| 76 | "NOT WITH_STDTHREADS;Boost_FOUND" OFF) |
| 77 | endif() |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 78 | CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON |
| 79 | "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 80 | |
| 81 | # C GLib |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 82 | option(WITH_C_GLIB "Build C (GLib) Thrift library" ON) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 83 | if(WITH_C_GLIB) |
| 84 | find_package(GLIB QUIET COMPONENTS gobject) |
| 85 | endif() |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 86 | CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON |
| 87 | "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF) |
Nobuaki Sukegawa | 33744b0 | 2016-01-03 14:24:39 +0900 | [diff] [blame] | 88 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 89 | # Java |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 90 | option(WITH_JAVA "Build Java Thrift library" ON) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 91 | if(ANDROID) |
| 92 | find_package(Gradle QUIET) |
| 93 | CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON |
| 94 | "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF) |
| 95 | else() |
Pascal Bach | 665844e | 2015-12-01 11:02:14 +0100 | [diff] [blame] | 96 | find_package(Java QUIET) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 97 | find_package(Ant QUIET) |
| 98 | CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON |
| 99 | "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;ANT_FOUND" OFF) |
| 100 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 101 | |
| 102 | # Python |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 103 | option(WITH_PYTHON "Build Python Thrift library" ON) |
| 104 | find_package(PythonInterp QUIET) # for Python executable |
| 105 | find_package(PythonLibs QUIET) # for Python.h |
Nobuaki Sukegawa | 25536ad | 2016-02-04 15:08:55 +0900 | [diff] [blame] | 106 | find_package(Pip QUIET) |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 107 | CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON |
Nobuaki Sukegawa | 25536ad | 2016-02-04 15:08:55 +0900 | [diff] [blame] | 108 | "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND;PIP_FOUND" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 109 | |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 110 | # Haskell |
| 111 | option(WITH_HASKELL "Build Haskell Thrift library" ON) |
| 112 | find_package(GHC QUIET) |
| 113 | find_package(Cabal QUIET) |
| 114 | CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON |
| 115 | "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF) |
| 116 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 117 | # Common library options |
| 118 | option(WITH_SHARED_LIB "Build shared libraries" ON) |
| 119 | option(WITH_STATIC_LIB "Build static libraries" ON) |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 120 | if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB) |
| 121 | message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!") |
| 122 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 123 | |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 124 | option(WITH_DYN_LINK_TEST "Build with Boost dynamic link test library" OFF) |
| 125 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 126 | #NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt |
| 127 | |
| 128 | # Visual Studio only options |
| 129 | if(MSVC) |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 130 | option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 131 | endif(MSVC) |
| 132 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 133 | macro(MESSAGE_DEP flag summary) |
| 134 | if(NOT ${flag}) |
| 135 | message(STATUS " - ${summary}") |
| 136 | endif() |
| 137 | endmacro(MESSAGE_DEP flag summary) |
| 138 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 139 | macro(PRINT_CONFIG_SUMMARY) |
| 140 | message(STATUS "----------------------------------------------------------") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 141 | message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") |
| 142 | message(STATUS "Thrift package version: ${PACKAGE_VERSION}") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 143 | message(STATUS "Build configuration Summary") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 144 | message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}") |
| 145 | message(STATUS " Build with unit tests: ${BUILD_TESTING}") |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 146 | MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 147 | message(STATUS " Build examples: ${BUILD_EXAMPLES}") |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 148 | MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 149 | message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 150 | message(STATUS " Language libraries:") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 151 | message(STATUS " Build C++ library: ${BUILD_CPP}") |
Nobuaki Sukegawa | c40018b | 2016-02-22 21:29:13 +0900 | [diff] [blame^] | 152 | MESSAGE_DEP(WITH_CPP "Disabled by via WITH_CPP=OFF") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 153 | MESSAGE_DEP(Boost_FOUND "Boost headers missing") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 154 | message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 155 | MESSAGE_DEP(WITH_C_GLIB "Disabled by via WITH_C_GLIB=OFF") |
| 156 | MESSAGE_DEP(GLIB_FOUND "GLib missing") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 157 | message(STATUS " Build Java library: ${BUILD_JAVA}") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 158 | MESSAGE_DEP(WITH_JAVA "Disabled by via WITH_JAVA=OFF") |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 159 | if(ANDROID) |
| 160 | MESSAGE_DEP(GRADLE_FOUND "Gradle missing") |
| 161 | else() |
| 162 | MESSAGE_DEP(JAVA_FOUND "Java Runtime missing") |
| 163 | MESSAGE_DEP(ANT_FOUND "Ant missing") |
| 164 | endif() |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 165 | message(STATUS " Build Python library: ${BUILD_PYTHON}") |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 166 | MESSAGE_DEP(WITH_PYTHON "Disabled by via WITH_PYTHON=OFF") |
| 167 | MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 168 | message(STATUS " Build Haskell library: ${BUILD_HASKELL}") |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 169 | MESSAGE_DEP(WITH_HASKELL "Disabled by via WITH_HASKELL=OFF") |
| 170 | MESSAGE_DEP(GHC_FOUND "GHC missing") |
| 171 | MESSAGE_DEP(CABAL_FOUND "Cabal missing") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 172 | message(STATUS " Library features:") |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 173 | message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}") |
| 174 | message(STATUS " Build static libraries: ${WITH_STATIC_LIB}") |
| 175 | message(STATUS " Build with ZLIB support: ${WITH_ZLIB}") |
| 176 | message(STATUS " Build with libevent support: ${WITH_LIBEVENT}") |
| 177 | message(STATUS " Build with Qt4 support: ${WITH_QT4}") |
| 178 | message(STATUS " Build with Qt5 support: ${WITH_QT5}") |
| 179 | message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}") |
| 180 | message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}") |
| 181 | message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}") |
| 182 | message(STATUS " Build with Boost dynamic link test library: ${WITH_DYN_LINK_TEST}") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 183 | message(STATUS "----------------------------------------------------------") |
| 184 | endmacro(PRINT_CONFIG_SUMMARY) |