blob: 4db182eaa6340c6be3c42a518bb71f3be08722f1 [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
Roger Meier8f271892015-04-14 22:05:50 +020020cmake_minimum_required(VERSION 2.8.12)
Pascal Bachd5f87e12014-12-12 15:59:17 +010021
Roger Meier211b82d2015-06-04 12:47:31 +020022project("Apache Thrift")
Pascal Bachd5f87e12014-12-12 15:59:17 +010023
jfarrelle03f7e82015-02-18 23:25:54 -050024set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
Pascal Bachd5f87e12014-12-12 15:59:17 +010025
26# TODO: add `git rev-parse --short HEAD`
27# Read the version information from the Autoconf file
28file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" )
29
30# The following variable is used in the version.h.in file
31string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC})
32message(STATUS "Parsed Thrift package version: ${PACKAGE_VERSION}")
33
34# These are internal to CMake
35string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION})
36string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION})
37string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION})
38string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION})
39message(STATUS "Parsed Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
40
41# Some default settings
42include(DefineCMakeDefaults)
43
44# Build time options are defined here
45include(DefineOptions)
46include(DefineInstallationPaths)
47
48# Based on the options set some platform specifics
49include(DefinePlatformSpecifc)
50
51# Generate the config.h file
52include(ConfigureChecks)
53
54# Package it
55include(CPackConfig)
56
57
58find_package(Threads)
59
60include(CTest)
61if(BUILD_TESTING)
62 message(STATUS "Building with unittests")
Roger Meier26593812015-04-12 16:10:35 +020063
64 enable_testing()
65 # Define "make check" as alias for "make test"
66 add_custom_target(check COMMAND ctest)
Pascal Bachd5f87e12014-12-12 15:59:17 +010067else ()
68 message(STATUS "Building without tests")
69endif ()
70if(BUILD_COMPILER)
71 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp)
72endif()
73
Roger Meier3b99c972015-04-20 22:49:48 +020074if(BUILD_CPP)
Pascal Bachd5f87e12014-12-12 15:59:17 +010075 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp)
Roger Meier26593812015-04-12 16:10:35 +020076 if(BUILD_TESTING)
Marco Moltenifdf01982015-04-15 21:22:41 +020077 if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL)
Marco Molteni7f477922015-04-15 20:46:48 +020078 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp)
79 else()
Marco Moltenifdf01982015-04-15 21:22:41 +020080 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 +020081 endif()
Roger Meier26593812015-04-12 16:10:35 +020082 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010083endif()
84
Roger Meier3b99c972015-04-20 22:49:48 +020085if(BUILD_C_GLIB)
Pascal Bachd5f87e12014-12-12 15:59:17 +010086 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib)
87endif()
88
Roger Meier3b99c972015-04-20 22:49:48 +020089if(BUILD_JAVA)
Pascal Bachd5f87e12014-12-12 15:59:17 +010090 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
91endif()
92
Roger Meier3b99c972015-04-20 22:49:48 +020093if(BUILD_PYTHON)
Roger Meier26593812015-04-12 16:10:35 +020094 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
Roger Meier211b82d2015-06-04 12:47:31 +020095 if(BUILD_TESTING)
96 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py)
97 endif()
Roger Meier26593812015-04-12 16:10:35 +020098endif()
99
Pascal Bachd5f87e12014-12-12 15:59:17 +0100100PRINT_CONFIG_SUMMARY()