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 | |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 20 | cmake_minimum_required(VERSION 3.4) |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 21 | |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 22 | if(POLICY CMP0048) |
| 23 | cmake_policy(SET CMP0048 NEW) # package version behavior added in cmake 3.0 |
| 24 | endif() |
| 25 | if(POLICY CMP0074) |
| 26 | cmake_policy(SET CMP0074 NEW) # find_package behavior added in cmake 3.12 |
| 27 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 28 | |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 29 | # PACKAGE_VERSION is used by cpack scripts currently |
| 30 | # Both thrift_VERSION and PACKAGE_VERSION should be the same for now |
Jens Geyer | 75cf93e | 2024-02-04 14:50:37 +0100 | [diff] [blame] | 31 | set(thrift_VERSION "0.21.0") |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 32 | set(PACKAGE_VERSION ${thrift_VERSION}) |
| 33 | |
| 34 | project("thrift" VERSION ${PACKAGE_VERSION}) |
| 35 | message(STATUS "Configuring ${CMAKE_PROJECT_NAME} ${thrift_VERSION}") |
| 36 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 37 | |
jfarrell | e03f7e8 | 2015-02-18 23:25:54 -0500 | [diff] [blame] | 38 | set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 39 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 40 | # Some default settings |
| 41 | include(DefineCMakeDefaults) |
| 42 | |
| 43 | # Build time options are defined here |
| 44 | include(DefineOptions) |
| 45 | include(DefineInstallationPaths) |
| 46 | |
| 47 | # Based on the options set some platform specifics |
| 48 | include(DefinePlatformSpecifc) |
| 49 | |
cyy | a6a3a78 | 2019-02-07 22:27:33 +0800 | [diff] [blame] | 50 | # Add CMake targets for static code analysis |
| 51 | include(StaticCodeAnalysis) |
| 52 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 53 | # Generate the config.h file |
| 54 | include(ConfigureChecks) |
| 55 | |
soroshsabz | 0c4e96f | 2019-03-15 15:05:18 +0330 | [diff] [blame] | 56 | # Generate the ThriftConfig.cmake module |
| 57 | include(GenerateConfigModule) |
| 58 | |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 59 | # Packaging |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 60 | include(CPackConfig) |
| 61 | |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 62 | # Dependencies |
| 63 | include(BoostMacros) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 64 | find_package(Threads) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 65 | include(CTest) |
James E. King III | c9ac8d2 | 2019-01-07 16:46:45 -0500 | [diff] [blame] | 66 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 67 | if(BUILD_TESTING) |
| 68 | message(STATUS "Building with unittests") |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 69 | |
| 70 | enable_testing() |
| 71 | # Define "make check" as alias for "make test" |
| 72 | add_custom_target(check COMMAND ctest) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 73 | else () |
| 74 | message(STATUS "Building without tests") |
| 75 | endif () |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 76 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 77 | if(BUILD_COMPILER) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 78 | if(NOT EXISTS ${THRIFT_COMPILER}) |
| 79 | set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>) |
| 80 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 81 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 82 | elseif(EXISTS ${THRIFT_COMPILER}) |
| 83 | add_executable(thrift-compiler IMPORTED) |
| 84 | set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER}) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 85 | endif() |
| 86 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 87 | if(BUILD_CPP) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 88 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp) |
ben-craig | 1f64ea9 | 2015-07-15 08:11:57 -0500 | [diff] [blame] | 89 | if(BUILD_TUTORIALS) |
| 90 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 91 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 92 | if(BUILD_TESTING) |
Marco Molteni | fdf0198 | 2015-04-15 21:22:41 +0200 | [diff] [blame] | 93 | if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL) |
Marco Molteni | 7f47792 | 2015-04-15 20:46:48 +0200 | [diff] [blame] | 94 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp) |
| 95 | else() |
Marco Molteni | fdf0198 | 2015-04-15 21:22:41 +0200 | [diff] [blame] | 96 | message(WARNING "libevent and/or ZLIB and/or OpenSSL not found or disabled; will not build some tests") |
Marco Molteni | 7f47792 | 2015-04-15 20:46:48 +0200 | [diff] [blame] | 97 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 98 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 99 | endif() |
| 100 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 101 | if(BUILD_C_GLIB) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 102 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib) |
cyy | a6a3a78 | 2019-02-07 22:27:33 +0800 | [diff] [blame] | 103 | if(BUILD_TESTING) |
| 104 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/c_glib) |
| 105 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 106 | endif() |
| 107 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 108 | if(BUILD_JAVA) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 109 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java) |
| 110 | endif() |
| 111 | |
Mario Emmenlauer | 93171d2 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 112 | if(BUILD_JAVASCRIPT) |
| 113 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/js) |
| 114 | endif() |
| 115 | |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 116 | if(BUILD_KOTLIN) |
| 117 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/kotlin) |
| 118 | endif() |
| 119 | |
Mario Emmenlauer | 93171d2 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 120 | if(BUILD_NODEJS) |
| 121 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/nodejs) |
| 122 | endif() |
| 123 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 124 | if(BUILD_PYTHON) |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 125 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py) |
Roger Meier | 211b82d | 2015-06-04 12:47:31 +0200 | [diff] [blame] | 126 | if(BUILD_TESTING) |
| 127 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py) |
| 128 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 129 | endif() |
| 130 | |
zeshuai007 | 348790d | 2020-03-23 16:48:35 +0800 | [diff] [blame] | 131 | # Create the uninstall target |
| 132 | add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/build/cmake/uninstall.cmake") |
| 133 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 134 | PRINT_CONFIG_SUMMARY() |