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 | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 20 | cmake_minimum_required(VERSION 3.1) |
| 21 | |
| 22 | # CMake 3.1 supports C++ standards selection with CMAKE_CXX_STANDARD |
| 23 | # If you need CMake 3.1+ for Ubuntu 14.04, try |
| 24 | # https://launchpad.net/~george-edison55/+archive/ubuntu/cmake-3.x |
| 25 | # If you need CMake 3.1+ for debian "jessie", get it from jessie-backports |
| 26 | # Otherwise |
| 27 | # http://cmake.org |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 28 | |
Roger Meier | 211b82d | 2015-06-04 12:47:31 +0200 | [diff] [blame] | 29 | project("Apache Thrift") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 30 | |
jfarrell | e03f7e8 | 2015-02-18 23:25:54 -0500 | [diff] [blame] | 31 | 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] | 32 | |
| 33 | # TODO: add `git rev-parse --short HEAD` |
| 34 | # Read the version information from the Autoconf file |
| 35 | file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" ) |
| 36 | |
| 37 | # The following variable is used in the version.h.in file |
| 38 | string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC}) |
| 39 | message(STATUS "Parsed Thrift package version: ${PACKAGE_VERSION}") |
| 40 | |
| 41 | # These are internal to CMake |
| 42 | string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION}) |
| 43 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION}) |
| 44 | string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION}) |
| 45 | string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION}) |
| 46 | message(STATUS "Parsed Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") |
| 47 | |
| 48 | # Some default settings |
| 49 | include(DefineCMakeDefaults) |
| 50 | |
| 51 | # Build time options are defined here |
| 52 | include(DefineOptions) |
| 53 | include(DefineInstallationPaths) |
| 54 | |
| 55 | # Based on the options set some platform specifics |
| 56 | include(DefinePlatformSpecifc) |
| 57 | |
| 58 | # Generate the config.h file |
| 59 | include(ConfigureChecks) |
| 60 | |
| 61 | # Package it |
| 62 | include(CPackConfig) |
| 63 | |
| 64 | |
| 65 | find_package(Threads) |
| 66 | |
| 67 | include(CTest) |
| 68 | if(BUILD_TESTING) |
| 69 | message(STATUS "Building with unittests") |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 70 | |
| 71 | enable_testing() |
| 72 | # Define "make check" as alias for "make test" |
| 73 | add_custom_target(check COMMAND ctest) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 74 | else () |
| 75 | message(STATUS "Building without tests") |
| 76 | endif () |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 77 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 78 | if(BUILD_COMPILER) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 79 | if(NOT EXISTS ${THRIFT_COMPILER}) |
| 80 | set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>) |
| 81 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 82 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 83 | elseif(EXISTS ${THRIFT_COMPILER}) |
| 84 | add_executable(thrift-compiler IMPORTED) |
| 85 | set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER}) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 86 | endif() |
| 87 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 88 | if(BUILD_CPP) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 89 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp) |
ben-craig | 1f64ea9 | 2015-07-15 08:11:57 -0500 | [diff] [blame] | 90 | if(BUILD_TUTORIALS) |
| 91 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp) |
Nobuaki Sukegawa | ca93936 | 2015-11-14 00:23:40 +0900 | [diff] [blame] | 92 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 93 | if(BUILD_TESTING) |
Marco Molteni | fdf0198 | 2015-04-15 21:22:41 +0200 | [diff] [blame] | 94 | if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL) |
Marco Molteni | 7f47792 | 2015-04-15 20:46:48 +0200 | [diff] [blame] | 95 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp) |
| 96 | else() |
Marco Molteni | fdf0198 | 2015-04-15 21:22:41 +0200 | [diff] [blame] | 97 | 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] | 98 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 99 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 100 | endif() |
| 101 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 102 | if(BUILD_C_GLIB) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 103 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib) |
| 104 | endif() |
| 105 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 106 | if(BUILD_JAVA) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 107 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java) |
| 108 | endif() |
| 109 | |
Roger Meier | 3b99c97 | 2015-04-20 22:49:48 +0200 | [diff] [blame] | 110 | if(BUILD_PYTHON) |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 111 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py) |
Roger Meier | 211b82d | 2015-06-04 12:47:31 +0200 | [diff] [blame] | 112 | if(BUILD_TESTING) |
| 113 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py) |
| 114 | endif() |
Roger Meier | 2659381 | 2015-04-12 16:10:35 +0200 | [diff] [blame] | 115 | endif() |
| 116 | |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 117 | if(BUILD_HASKELL) |
| 118 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/hs) |
| 119 | if(BUILD_TESTING) |
| 120 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/hs) |
| 121 | endif() |
| 122 | endif() |
| 123 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 124 | PRINT_CONFIG_SUMMARY() |