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 20cmake_minimum_required(VERSION 3.4) 21 22if(POLICY CMP0048) 23 cmake_policy(SET CMP0048 NEW) # package version behavior added in cmake 3.0 24endif() 25if(POLICY CMP0074) 26 cmake_policy(SET CMP0074 NEW) # find_package behavior added in cmake 3.12 27endif() 28 29# PACKAGE_VERSION is used by cpack scripts currently 30# Both thrift_VERSION and PACKAGE_VERSION should be the same for now 31set(thrift_VERSION "0.18.0") 32set(PACKAGE_VERSION ${thrift_VERSION}) 33 34project("thrift" VERSION ${PACKAGE_VERSION}) 35message(STATUS "Configuring ${CMAKE_PROJECT_NAME} ${thrift_VERSION}") 36 37 38set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake") 39 40# Some default settings 41include(DefineCMakeDefaults) 42 43# Build time options are defined here 44include(DefineOptions) 45include(DefineInstallationPaths) 46 47# Based on the options set some platform specifics 48include(DefinePlatformSpecifc) 49 50# Add CMake targets for static code analysis 51include(StaticCodeAnalysis) 52 53# Generate the config.h file 54include(ConfigureChecks) 55 56# Generate the ThriftConfig.cmake module 57include(GenerateConfigModule) 58 59# Packaging 60include(CPackConfig) 61 62# Dependencies 63include(BoostMacros) 64find_package(Threads) 65include(CTest) 66 67if(BUILD_TESTING) 68 message(STATUS "Building with unittests") 69 70 enable_testing() 71 # Define "make check" as alias for "make test" 72 add_custom_target(check COMMAND ctest) 73else () 74 message(STATUS "Building without tests") 75endif () 76 77if(BUILD_COMPILER) 78 if(NOT EXISTS ${THRIFT_COMPILER}) 79 set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>) 80 endif() 81 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp) 82elseif(EXISTS ${THRIFT_COMPILER}) 83 add_executable(thrift-compiler IMPORTED) 84 set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER}) 85endif() 86 87if(BUILD_CPP) 88 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp) 89 if(BUILD_TUTORIALS) 90 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp) 91 endif() 92 if(BUILD_TESTING) 93 if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL) 94 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp) 95 else() 96 message(WARNING "libevent and/or ZLIB and/or OpenSSL not found or disabled; will not build some tests") 97 endif() 98 endif() 99endif() 100 101if(BUILD_C_GLIB) 102 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib) 103 if(BUILD_TESTING) 104 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/c_glib) 105 endif() 106endif() 107 108if(BUILD_JAVA) 109 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java) 110endif() 111 112if(BUILD_JAVASCRIPT) 113 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/js) 114endif() 115 116if(BUILD_KOTLIN) 117 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/kotlin) 118endif() 119 120if(BUILD_NODEJS) 121 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/nodejs) 122endif() 123 124if(BUILD_PYTHON) 125 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py) 126 if(BUILD_TESTING) 127 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py) 128 endif() 129endif() 130 131# Create the uninstall target 132add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/build/cmake/uninstall.cmake") 133 134PRINT_CONFIG_SUMMARY() 135