blob: 93ed8d2ac58e9b884601c2d4cd894af27152495d [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 ()
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090070
Pascal Bachd5f87e12014-12-12 15:59:17 +010071if(BUILD_COMPILER)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090072 if(NOT EXISTS ${THRIFT_COMPILER})
73 set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>)
74 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010075 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090076elseif(EXISTS ${THRIFT_COMPILER})
77 add_executable(thrift-compiler IMPORTED)
78 set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER})
Pascal Bachd5f87e12014-12-12 15:59:17 +010079endif()
80
Roger Meier3b99c972015-04-20 22:49:48 +020081if(BUILD_CPP)
Pascal Bachd5f87e12014-12-12 15:59:17 +010082 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp)
ben-craig1f64ea92015-07-15 08:11:57 -050083 if(BUILD_TUTORIALS)
84 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp)
Nobuaki Sukegawaca939362015-11-14 00:23:40 +090085 endif()
Roger Meier26593812015-04-12 16:10:35 +020086 if(BUILD_TESTING)
Marco Moltenifdf01982015-04-15 21:22:41 +020087 if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL)
Marco Molteni7f477922015-04-15 20:46:48 +020088 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp)
89 else()
Marco Moltenifdf01982015-04-15 21:22:41 +020090 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 +020091 endif()
Roger Meier26593812015-04-12 16:10:35 +020092 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010093endif()
94
Roger Meier3b99c972015-04-20 22:49:48 +020095if(BUILD_C_GLIB)
Pascal Bachd5f87e12014-12-12 15:59:17 +010096 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib)
97endif()
98
Roger Meier3b99c972015-04-20 22:49:48 +020099if(BUILD_JAVA)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100100 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
101endif()
102
Roger Meier3b99c972015-04-20 22:49:48 +0200103if(BUILD_PYTHON)
Roger Meier26593812015-04-12 16:10:35 +0200104 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
Roger Meier211b82d2015-06-04 12:47:31 +0200105 if(BUILD_TESTING)
106 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py)
107 endif()
Roger Meier26593812015-04-12 16:10:35 +0200108endif()
109
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +0900110if(BUILD_HASKELL)
111 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/hs)
112 if(BUILD_TESTING)
113 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/hs)
114 endif()
115endif()
116
Pascal Bachd5f87e12014-12-12 15:59:17 +0100117PRINT_CONFIG_SUMMARY()