blob: 9f57a66c4d53e7df06fce6acde8095463c3bbe1c [file] [log] [blame]
Pascal Bachd5f87e12014-12-12 15:59:17 +01001#
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, III43e959b2017-04-04 13:04:29 -040020cmake_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 Bachd5f87e12014-12-12 15:59:17 +010028
Roger Meier211b82d2015-06-04 12:47:31 +020029project("Apache Thrift")
Pascal Bachd5f87e12014-12-12 15:59:17 +010030
jfarrelle03f7e82015-02-18 23:25:54 -050031set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
Pascal Bachd5f87e12014-12-12 15:59:17 +010032
33# TODO: add `git rev-parse --short HEAD`
34# Read the version information from the Autoconf file
35file (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
38string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC})
39message(STATUS "Parsed Thrift package version: ${PACKAGE_VERSION}")
40
41# These are internal to CMake
42string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION})
43string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION})
44string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION})
45string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION})
46message(STATUS "Parsed Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
47
48# Some default settings
49include(DefineCMakeDefaults)
50
51# Build time options are defined here
52include(DefineOptions)
53include(DefineInstallationPaths)
54
55# Based on the options set some platform specifics
56include(DefinePlatformSpecifc)
57
58# Generate the config.h file
59include(ConfigureChecks)
60
61# Package it
62include(CPackConfig)
63
64
65find_package(Threads)
66
67include(CTest)
68if(BUILD_TESTING)
69 message(STATUS "Building with unittests")
Roger Meier26593812015-04-12 16:10:35 +020070
71 enable_testing()
72 # Define "make check" as alias for "make test"
73 add_custom_target(check COMMAND ctest)
Pascal Bachd5f87e12014-12-12 15:59:17 +010074else ()
75 message(STATUS "Building without tests")
76endif ()
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090077
Pascal Bachd5f87e12014-12-12 15:59:17 +010078if(BUILD_COMPILER)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090079 if(NOT EXISTS ${THRIFT_COMPILER})
80 set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>)
81 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010082 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090083elseif(EXISTS ${THRIFT_COMPILER})
84 add_executable(thrift-compiler IMPORTED)
85 set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER})
Pascal Bachd5f87e12014-12-12 15:59:17 +010086endif()
87
Roger Meier3b99c972015-04-20 22:49:48 +020088if(BUILD_CPP)
Pascal Bachd5f87e12014-12-12 15:59:17 +010089 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp)
ben-craig1f64ea92015-07-15 08:11:57 -050090 if(BUILD_TUTORIALS)
91 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090092 endif()
Roger Meier26593812015-04-12 16:10:35 +020093 if(BUILD_TESTING)
Marco Moltenifdf01982015-04-15 21:22:41 +020094 if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL)
Marco Molteni7f477922015-04-15 20:46:48 +020095 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp)
96 else()
Marco Moltenifdf01982015-04-15 21:22:41 +020097 message(WARNING "libevent and/or ZLIB and/or OpenSSL not found or disabled; will not build some tests")
Marco Molteni7f477922015-04-15 20:46:48 +020098 endif()
Roger Meier26593812015-04-12 16:10:35 +020099 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100100endif()
101
Roger Meier3b99c972015-04-20 22:49:48 +0200102if(BUILD_C_GLIB)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100103 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib)
104endif()
105
Roger Meier3b99c972015-04-20 22:49:48 +0200106if(BUILD_JAVA)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100107 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
108endif()
109
Roger Meier3b99c972015-04-20 22:49:48 +0200110if(BUILD_PYTHON)
Roger Meier26593812015-04-12 16:10:35 +0200111 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
Roger Meier211b82d2015-06-04 12:47:31 +0200112 if(BUILD_TESTING)
113 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py)
114 endif()
Roger Meier26593812015-04-12 16:10:35 +0200115endif()
116
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900117if(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()
122endif()
123
Pascal Bachd5f87e12014-12-12 15:59:17 +0100124PRINT_CONFIG_SUMMARY()