From ad8ad3f45992d162e68537fb2ff0ae9fd0e001dc Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 15 Oct 2017 11:08:06 -0400 Subject: [PATCH 1/4] Checkout CMake build from hunter-0.10.0-p4 --- CMakeLists.txt | 121 +++++ build/cmake/CPackConfig.cmake | 68 +++ build/cmake/Config.cmake.in | 17 + build/cmake/ConfigureChecks.cmake | 76 +++ build/cmake/DefineCMakeDefaults.cmake | 70 +++ build/cmake/DefineInstallationPaths.cmake | 26 ++ build/cmake/DefineOptions.cmake | 199 ++++++++ build/cmake/DefinePlatformSpecifc.cmake | 106 +++++ build/cmake/FindAnt.cmake | 30 ++ build/cmake/FindCabal.cmake | 30 ++ build/cmake/FindGHC.cmake | 36 ++ build/cmake/FindGLIB.cmake | 122 +++++ build/cmake/FindGradle.cmake | 30 ++ build/cmake/FindLibevent.cmake | 41 ++ build/cmake/HunterGate.cmake | 540 ++++++++++++++++++++++ build/cmake/README.md | 60 +++ build/cmake/ThriftMacros.cmake | 96 ++++ build/cmake/android-toolchain.cmake | 26 ++ build/cmake/config.h.in | 157 +++++++ build/cmake/mingw32-toolchain.cmake | 24 + compiler/cpp/CMakeLists.txt | 2 + lib/cpp/CMakeLists.txt | 298 ++++++++++++ lib/py/CMakeLists.txt | 31 ++ 23 files changed, 2206 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 build/cmake/CPackConfig.cmake create mode 100644 build/cmake/Config.cmake.in create mode 100644 build/cmake/ConfigureChecks.cmake create mode 100644 build/cmake/DefineCMakeDefaults.cmake create mode 100644 build/cmake/DefineInstallationPaths.cmake create mode 100644 build/cmake/DefineOptions.cmake create mode 100644 build/cmake/DefinePlatformSpecifc.cmake create mode 100644 build/cmake/FindAnt.cmake create mode 100644 build/cmake/FindCabal.cmake create mode 100644 build/cmake/FindGHC.cmake create mode 100644 build/cmake/FindGLIB.cmake create mode 100644 build/cmake/FindGradle.cmake create mode 100644 build/cmake/FindLibevent.cmake create mode 100644 build/cmake/HunterGate.cmake create mode 100644 build/cmake/README.md create mode 100644 build/cmake/ThriftMacros.cmake create mode 100644 build/cmake/android-toolchain.cmake create mode 100644 build/cmake/config.h.in create mode 100644 build/cmake/mingw32-toolchain.cmake create mode 100755 lib/cpp/CMakeLists.txt create mode 100644 lib/py/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..9989c19b5b2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,121 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +cmake_minimum_required(VERSION 3.1) + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake") + +include(HunterGate) +HunterGate(URL "https://github.com/ruslo/hunter/archive/v0.19.112.tar.gz" + SHA1 "74cd301e87d79c09133b4ee252f202cd489203d8") + +# TODO: add `git rev-parse --short HEAD` +# Read the version information from the Autoconf file +file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" ) + +# The following variable is used in the version.h.in file +string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC}) +message(STATUS "Parsed Thrift package version: ${PACKAGE_VERSION}") + +# These are internal to CMake +string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION}) +string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION}) +string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION}) +string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION}) +message(STATUS "Parsed Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") + +project(thrift VERSION ${thrift_VERSION}) + +# Some default settings +include(DefineCMakeDefaults) + +# Build time options are defined here +include(DefineOptions) +include(DefineInstallationPaths) + +# Based on the options set some platform specifics +include(DefinePlatformSpecifc) + +# Generate the config.h file +include(ConfigureChecks) + +# Package it +include(CPackConfig) + + +find_package(Threads) + +include(CTest) +if(BUILD_TESTING) + message(STATUS "Building with unittests") + + enable_testing() + # Define "make check" as alias for "make test" + add_custom_target(check COMMAND ctest) +else () + message(STATUS "Building without tests") +endif () + +if(BUILD_COMPILER) + if(NOT EXISTS ${THRIFT_COMPILER}) + set(THRIFT_COMPILER $) + endif() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp) +elseif(EXISTS ${THRIFT_COMPILER}) + add_executable(thrift-compiler IMPORTED) + set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER}) +endif() + +if(BUILD_CPP) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp) + if(BUILD_TUTORIALS) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp) + endif() + if(BUILD_TESTING) + if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp) + else() + message(WARNING "libevent and/or ZLIB and/or OpenSSL not found or disabled; will not build some tests") + endif() + endif() +endif() + +if(BUILD_C_GLIB) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib) +endif() + +if(BUILD_JAVA) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java) +endif() + +if(BUILD_PYTHON) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py) + if(BUILD_TESTING) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py) + endif() +endif() + +if(BUILD_HASKELL) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/hs) + if(BUILD_TESTING) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/hs) + endif() +endif() + +PRINT_CONFIG_SUMMARY() diff --git a/build/cmake/CPackConfig.cmake b/build/cmake/CPackConfig.cmake new file mode 100644 index 00000000000..fdc1b4e76e8 --- /dev/null +++ b/build/cmake/CPackConfig.cmake @@ -0,0 +1,68 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +#TODO: Should we bundle system libraries for DLLs? +#include(InstallRequiredSystemLibraries) + +# For help take a look at: +# http://www.cmake.org/Wiki/CMake:CPackConfiguration + +### general settings +set(CPACK_PACKAGE_NAME "thrift") +set(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Apache Thrift") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VENDOR "Apache Software Foundation") +set(CPACK_PACKAGE_CONTACT "dev@thrift.apache.org") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") +set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") + +### versions +set(CPACK_PACKAGE_VERSION_MAJOR ${thrift_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${thrift_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${thrift_VERSION_PATCH}) + +### source generator +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") + +### zip generator +set(CPACK_GENERATOR "ZIP") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "thrift") + + +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(CPACK_GENERATOR "NSIS") + set(CPACK_NSIS_HELP_LINK "http://thrift.apache.org") + set(CPACK_NSIS_MENU_LINKS + "http://thrift.apache.org" "Apache Thrift - Web Site" + "https://issues.apache.org/jira/browse/THRIFT" "Apache Thrift - Issues") + set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT}) + set(CPACK_NSIS_MODIFY_PATH "ON") + set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") +else() + set(CPACK_GENERATOR "DEB" ) + set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT}) +endif() + + +include(CPack) diff --git a/build/cmake/Config.cmake.in b/build/cmake/Config.cmake.in new file mode 100644 index 00000000000..3f4c5945c89 --- /dev/null +++ b/build/cmake/Config.cmake.in @@ -0,0 +1,17 @@ +@PACKAGE_INIT@ + +set(package_deps @package_deps@) +foreach(dep IN LISTS package_deps) + if(dep STREQUAL "OpenSSL") + find_package(OpenSSL REQUIRED) + else() + find_package(${dep} CONFIG REQUIRED) + endif() +endforeach() + +set(boost_components @boost_components@) +find_package(Boost CONFIG REQUIRED ${boost_components}) + +check_required_components("@PROJECT_NAME@") + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") diff --git a/build/cmake/ConfigureChecks.cmake b/build/cmake/ConfigureChecks.cmake new file mode 100644 index 00000000000..f65054401e0 --- /dev/null +++ b/build/cmake/ConfigureChecks.cmake @@ -0,0 +1,76 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +include(CheckSymbolExists) +include(CheckIncludeFile) +include(CheckIncludeFiles) +include(CheckFunctionExists) + +# If AI_ADDRCONFIG is not defined we define it as 0 +check_symbol_exists(AI_ADDRCONFIG "sys/types.h;sys/socket.h;netdb.h" HAVE_AI_ADDRCONFIG) +if(NOT HAVE_AI_ADDRCONFIG) +set(AI_ADDRCONFIG 1) +endif(NOT HAVE_AI_ADDRCONFIG) + +check_include_file(arpa/inet.h HAVE_ARPA_INET_H) +check_include_file(fcntl.h HAVE_FCNTL_H) +check_include_file(getopt.h HAVE_GETOPT_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(netdb.h HAVE_NETDB_H) +check_include_file(netinet/in.h HAVE_NETINET_IN_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(pthread.h HAVE_PTHREAD_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(sys/param.h HAVE_SYS_PARAM_H) +check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) +check_include_file(sys/socket.h HAVE_SYS_SOCKET_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/un.h HAVE_SYS_UN_H) +check_include_file(sys/poll.h HAVE_SYS_POLL_H) +check_include_file(sys/select.h HAVE_SYS_SELECT_H) +check_include_file(sched.h HAVE_SCHED_H) +check_include_file(strings.h HAVE_STRINGS_H) + +check_function_exists(gethostbyname HAVE_GETHOSTBYNAME) +check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R) +check_function_exists(strerror_r HAVE_STRERROR_R) +check_function_exists(sched_get_priority_max HAVE_SCHED_GET_PRIORITY_MAX) +check_function_exists(sched_get_priority_min HAVE_SCHED_GET_PRIORITY_MIN) + +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles( + " + #include + int main(){char b;char *a = strerror_r(0, &b, 0); return(0);} + " + STRERROR_R_CHAR_P) + + +set(PACKAGE ${PACKAGE_NAME}) +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(VERSION ${thrift_VERSION}) + +# generate a config.h file +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/thrift/config.h") +# HACK: Some files include thrift/config.h and some config.h so we include both. This should be cleaned up. +include_directories("${CMAKE_CURRENT_BINARY_DIR}/thrift" "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/build/cmake/DefineCMakeDefaults.cmake b/build/cmake/DefineCMakeDefaults.cmake new file mode 100644 index 00000000000..8125de9d847 --- /dev/null +++ b/build/cmake/DefineCMakeDefaults.cmake @@ -0,0 +1,70 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# Always include srcdir and builddir in include path +# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in +# about every subdir +# since cmake 2.4.0 +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Put the include dirs which are in the source or build tree +# before all other include dirs, so the headers in the sources +# are preferred over the already installed ones +# since cmake 2.4.1 +set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) + +# Use colored output +# since cmake 2.4.0 +set(CMAKE_COLOR_MAKEFILE ON) + +# Define the generic version of the libraries here +set(GENERIC_LIB_VERSION "0.10.0") +set(GENERIC_LIB_SOVERSION "0") + +# Set the default build type to release with debug info +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo + CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + ) +endif (NOT CMAKE_BUILD_TYPE) + +# Create the compile command database for clang by default +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Put the libraries and binaries that get built into directories at the +# top of the build tree rather than in hard-to-find leaf +# directories. This simplifies manual testing and the use of the build +# tree rather than installed thrift libraries. +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +# +# "rpath" support. +# See http://www.itk.org/Wiki/index.php?title=CMake_RPATH_handling +# +# On MacOSX, for shared libraries, enable rpath support. +set(CMAKE_MACOSX_RPATH TRUE) +# +# On any OS, for executables, allow linking with shared libraries in non-system +# locations and running the executables without LD_PRELOAD or similar. +# This requires the library to be built with rpath support. +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) diff --git a/build/cmake/DefineInstallationPaths.cmake b/build/cmake/DefineInstallationPaths.cmake new file mode 100644 index 00000000000..122f0f6a937 --- /dev/null +++ b/build/cmake/DefineInstallationPaths.cmake @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# Define the default install paths +set(BIN_INSTALL_DIR "bin" CACHE PATH "The binary install dir (default: bin)") +set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The library install dir (default: lib${LIB_SUFFIX})") +set(INCLUDE_INSTALL_DIR "include" CACHE PATH "The library install dir (default: include)") +set(CMAKE_INSTALL_DIR "cmake" CACHE PATH "The subdirectory to install cmake config files (default: cmake)") +set(DOC_INSTALL_DIR "share/doc" CACHE PATH "The subdirectory to install documentation files (default: share/doc)") diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake new file mode 100644 index 00000000000..d53b9c10a4f --- /dev/null +++ b/build/cmake/DefineOptions.cmake @@ -0,0 +1,199 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +include(CMakeDependentOption) + +set(THRIFT_COMPILER "" CACHE FILEPATH "External Thrift compiler to use during build") + +# Additional components +option(BUILD_COMPILER "Build Thrift compiler" ON) + +if(BUILD_COMPILER OR EXISTS ${THRIFT_COMPILER}) + set(HAVE_COMPILER ON) +endif() +CMAKE_DEPENDENT_OPTION(BUILD_TESTING "Build with unit tests" ON "HAVE_COMPILER" OFF) +CMAKE_DEPENDENT_OPTION(BUILD_EXAMPLES "Build examples" ON "HAVE_COMPILER" OFF) +CMAKE_DEPENDENT_OPTION(BUILD_TUTORIALS "Build Thrift tutorials" ON "HAVE_COMPILER" OFF) +option(BUILD_LIBRARIES "Build Thrift libraries" ON) + +# Libraries to build + +# Each language library can be enabled or disabled using the WITH_ flag. +# By default CMake checks if the required dependencies for a language are present +# and enables the library if all are found. This means the default is to build as +# much as possible but leaving out libraries if their dependencies are not met. + +CMAKE_DEPENDENT_OPTION(WITH_BOOST_STATIC "Build with Boost static link library" OFF "NOT MSVC" ON) +set(Boost_USE_STATIC_LIBS ${WITH_BOOST_STATIC}) +if (NOT WITH_BOOST_STATIC) + add_definitions(-DBOOST_ALL_DYN_LINK) + add_definitions(-DBOOST_TEST_DYN_LINK) +endif() + +# C++ +option(WITH_CPP "Build C++ Thrift library" ON) +if(WITH_CPP) + # NOTE: Currently the following options are C++ specific, + # but in future other libraries might reuse them. + # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently + # has no effect. + option(WITH_ZLIB "Build with ZLIB support" ON) + option(WITH_LIBEVENT "Build with libevent support" ON) + option(WITH_QT4 "Build with Qt4 support" ON) + option(WITH_QT5 "Build with Qt5 support" ON) + if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3) + # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5 + set(WITH_QT4 OFF) + endif() + option(WITH_OPENSSL "Build with OpenSSL support" ON) + option(WITH_STDTHREADS "Build with C++ std::thread support" OFF) + CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF + "NOT WITH_STDTHREADS" OFF) +endif() +CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON + "BUILD_LIBRARIES;WITH_CPP" OFF) +CMAKE_DEPENDENT_OPTION(WITH_PLUGIN "Build compiler plugin support" ON + "BUILD_COMPILER;BUILD_CPP" OFF) + +# C GLib +option(WITH_C_GLIB "Build C (GLib) Thrift library" ON) +if(WITH_C_GLIB) + find_package(GLIB QUIET COMPONENTS gobject) +endif() +CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON + "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF) + +if(BUILD_CPP) + set(boost_components) + if(WITH_BOOSTTHREADS OR BUILD_TESTING) + list(APPEND boost_components system thread) + endif() + if(BUILD_TESTING) + list(APPEND boost_components unit_test_framework filesystem chrono program_options) + endif() + if(boost_components) + hunter_add_package(Boost COMPONENTS ${boost_components}) + find_package(Boost CONFIG REQUIRED ${boost_components}) + else() + hunter_add_package(Boost) + find_package(Boost CONFIG REQUIRED) + endif() +elseif(BUILD_C_GLIB AND BUILD_TESTING) + find_package(Boost 1.53 REQUIRED) +endif() + +# Java +option(WITH_JAVA "Build Java Thrift library" ON) +if(ANDROID) + find_package(Gradle QUIET) + CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON + "BUILD_LIBRARIES;WITH_JAVA;GRADLE_FOUND" OFF) +else() + find_package(Java QUIET) + find_package(Ant QUIET) + CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java library" ON + "BUILD_LIBRARIES;WITH_JAVA;JAVA_FOUND;ANT_FOUND" OFF) +endif() + +# Python +option(WITH_PYTHON "Build Python Thrift library" ON) +find_package(PythonInterp QUIET) # for Python executable +find_package(PythonLibs QUIET) # for Python.h +CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON + "BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF) + +# Haskell +option(WITH_HASKELL "Build Haskell Thrift library" ON) +find_package(GHC QUIET) +find_package(Cabal QUIET) +CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON + "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF) + +# Common library options +option(WITH_SHARED_LIB "Build shared libraries" ON) +option(WITH_STATIC_LIB "Build static libraries" ON) +if (NOT WITH_SHARED_LIB AND NOT WITH_STATIC_LIB) + message(FATAL_ERROR "Cannot build with both shared and static outputs disabled!") +endif() + +#NOTE: C++ compiler options are defined in the lib/cpp/CMakeLists.txt + +# Visual Studio only options +if(MSVC) +option(WITH_MT "Build using MT instead of MD (MSVC only)" OFF) +endif(MSVC) + +macro(MESSAGE_DEP flag summary) +if(NOT ${flag}) + message(STATUS " - ${summary}") +endif() +endmacro(MESSAGE_DEP flag summary) + +macro(PRINT_CONFIG_SUMMARY) +message(STATUS "----------------------------------------------------------") +message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") +message(STATUS "Thrift package version: ${PACKAGE_VERSION}") +message(STATUS "Build configuration Summary") +message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}") +message(STATUS " Build compiler plugin support: ${WITH_PLUGIN}") +MESSAGE_DEP(PLUGIN_COMPILER_NOT_TOO_OLD "Disabled due to older compiler") +message(STATUS " Build with unit tests: ${BUILD_TESTING}") +MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given") +message(STATUS " Build examples: ${BUILD_EXAMPLES}") +MESSAGE_DEP(HAVE_COMPILER "Disabled because BUILD_THRIFT=OFF and no valid THRIFT_COMPILER is given") +message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}") +message(STATUS " Language libraries:") +message(STATUS " Build C++ library: ${BUILD_CPP}") +MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF") +MESSAGE_DEP(Boost_FOUND "Boost headers missing") +message(STATUS " Build C (GLib) library: ${BUILD_C_GLIB}") +MESSAGE_DEP(WITH_C_GLIB "Disabled by WITH_C_GLIB=OFF") +MESSAGE_DEP(GLIB_FOUND "GLib missing") +message(STATUS " Build Java library: ${BUILD_JAVA}") +MESSAGE_DEP(WITH_JAVA "Disabled by WITH_JAVA=OFF") +if(ANDROID) + MESSAGE_DEP(GRADLE_FOUND "Gradle missing") +else() + MESSAGE_DEP(JAVA_FOUND "Java Runtime missing") + MESSAGE_DEP(ANT_FOUND "Ant missing") +endif() +message(STATUS " Build Python library: ${BUILD_PYTHON}") +MESSAGE_DEP(WITH_PYTHON "Disabled by WITH_PYTHON=OFF") +MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing") +message(STATUS " Build Haskell library: ${BUILD_HASKELL}") +MESSAGE_DEP(WITH_HASKELL "Disabled by WITH_HASKELL=OFF") +MESSAGE_DEP(GHC_FOUND "GHC missing") +MESSAGE_DEP(CABAL_FOUND "Cabal missing") +message(STATUS " Library features:") +message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}") +message(STATUS " Build static libraries: ${WITH_STATIC_LIB}") +message(STATUS " Build with ZLIB support: ${WITH_ZLIB}") +message(STATUS " Build with libevent support: ${WITH_LIBEVENT}") +message(STATUS " Build with Qt4 support: ${WITH_QT4}") +message(STATUS " Build with Qt5 support: ${WITH_QT5}") +message(STATUS " Build with OpenSSL support: ${WITH_OPENSSL}") +message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}") +message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}") +message(STATUS " Build with Boost static link library: ${WITH_BOOST_STATIC}") +if(MSVC) + message(STATUS " - Enabled for Visual C++") +endif() +message(STATUS "----------------------------------------------------------") +endmacro(PRINT_CONFIG_SUMMARY) diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake new file mode 100644 index 00000000000..e57ecc2f9b9 --- /dev/null +++ b/build/cmake/DefinePlatformSpecifc.cmake @@ -0,0 +1,106 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# Visual Studio specific options +if(MSVC) + #For visual studio the library naming is as following: + # Dynamic libraries: + # - thrift.dll for release library + # - thriftd.dll for debug library + # + # Static libraries: + # - thriftmd.lib for /MD release build + # - thriftmt.lib for /MT release build + # + # - thriftmdd.lib for /MD debug build + # - thriftmtd.lib for /MT debug build + # + # the same holds for other libraries like libthriftz etc. + + # For Debug build types, append a "d" to the library names. + set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE) + set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set release library postfix" FORCE) + set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "Set release library postfix" FORCE) + + # Build using /MT option instead of /MD if the WITH_MT options is set + if(WITH_MT) + set(CompilerFlags + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO + ) + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE) + else(WITH_MT) + set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE) + endif(WITH_MT) + + # Disable Windows.h definition of macros for min and max + add_definitions("-DNOMINMAX") + + # Disable boost auto linking pragmas - cmake includes the right files + add_definitions("-DBOOST_ALL_NO_LIB") + + # Windows build does not know how to make a shared library yet + # as there are no __declspec(dllexport) or exports files in the project. + if (WITH_SHARED_LIB) + message (FATAL_ERROR "Windows build does not support shared library output yet, please set -DWITH_SHARED_LIB=off") + endif() + +elseif(UNIX) + find_program( MEMORYCHECK_COMMAND valgrind ) + set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" ) + set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" ) +endif() + +# WITH_*THREADS selects which threading library to use +if(WITH_BOOSTTHREADS) + add_definitions("-DUSE_BOOST_THREAD=1") +elseif(WITH_STDTHREADS) + add_definitions("-DUSE_STD_THREAD=1") +endif() + +# GCC and Clang. +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # FIXME -pedantic can not be used at the moment because of: https://issues.apache.org/jira/browse/THRIFT-2784 + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra -pedantic") + # FIXME enabling c++11 breaks some Linux builds on Travis by triggering a g++ bug, see + # https://travis-ci.org/apache/thrift/jobs/58017022 + # on the other hand, both MacOSX and FreeBSD need c++11 + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra") + endif() +endif() + +# If gcc older than 4.8 is detected, disable new compiler plug-in support (see THRIFT-3937) +set(PLUGIN_COMPILER_NOT_TOO_OLD ON) # simplifies messaging in DefineOptions summary +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8" AND WITH_PLUGIN) + message(STATUS "Disabling compiler plug-in support to work with older gcc compiler") + set(WITH_PLUGIN OFF) + set(PLUGIN_COMPILER_NOT_TOO_OLD OFF) +endif() + diff --git a/build/cmake/FindAnt.cmake b/build/cmake/FindAnt.cmake new file mode 100644 index 00000000000..8b0371d91b4 --- /dev/null +++ b/build/cmake/FindAnt.cmake @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# ANT_FOUND - system has Ant +# Ant_EXECUTABLE - the Ant executable +# +# It will search the environment variable ANT_HOME if it is set + +include(FindPackageHandleStandardArgs) + +find_program(Ant_EXECUTABLE NAMES ant PATHS $ENV{ANT_HOME}/bin) +find_package_handle_standard_args(Ant DEFAULT_MSG Ant_EXECUTABLE) +mark_as_advanced(Ant_EXECUTABLE) diff --git a/build/cmake/FindCabal.cmake b/build/cmake/FindCabal.cmake new file mode 100644 index 00000000000..fed337bd495 --- /dev/null +++ b/build/cmake/FindCabal.cmake @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# Cabal_FOUND - system has Cabal +# Cabal - the Cabal executable +# +# It will search the environment variable CABAL_HOME if it is set + +include(FindPackageHandleStandardArgs) + +find_program(CABAL NAMES cabal PATHS $ENV{HOME}/.cabal/bin $ENV{CABAL_HOME}/bin) +find_package_handle_standard_args(CABAL DEFAULT_MSG CABAL) +mark_as_advanced(CABAL) diff --git a/build/cmake/FindGHC.cmake b/build/cmake/FindGHC.cmake new file mode 100644 index 00000000000..48738472cc5 --- /dev/null +++ b/build/cmake/FindGHC.cmake @@ -0,0 +1,36 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# GHC_FOUND - system has GHC +# GHC - the GHC executable +# RUN_HASKELL_FOUND - system has runhaskell +# RUN_HASKELL - the runhaskell executable +# +# It will search the environment variable GHC_HOME if it is set + +include(FindPackageHandleStandardArgs) + +find_program(GHC NAMES ghc PATHS $ENV{GHC_HOME}/bin) +find_package_handle_standard_args(GHC DEFAULT_MSG GHC) +mark_as_advanced(GHC) + +find_program(RUN_HASKELL NAMES runhaskell PATHS $ENV{GHC_HOME}/bin) +find_package_handle_standard_args(RUN_HASKELL DEFAULT_MSG RUN_HASKELL) +mark_as_advanced(RUN_HASKELL) diff --git a/build/cmake/FindGLIB.cmake b/build/cmake/FindGLIB.cmake new file mode 100644 index 00000000000..acbe433e395 --- /dev/null +++ b/build/cmake/FindGLIB.cmake @@ -0,0 +1,122 @@ +# - Try to find Glib and its components (gio, gobject etc) +# Once done, this will define +# +# GLIB_FOUND - system has Glib +# GLIB_INCLUDE_DIRS - the Glib include directories +# GLIB_LIBRARIES - link these to use Glib +# +# Optionally, the COMPONENTS keyword can be passed to find_package() +# and Glib components can be looked for. Currently, the following +# components can be used, and they define the following variables if +# found: +# +# gio: GLIB_GIO_LIBRARIES +# gobject: GLIB_GOBJECT_LIBRARIES +# gmodule: GLIB_GMODULE_LIBRARIES +# gthread: GLIB_GTHREAD_LIBRARIES +# +# Note that the respective _INCLUDE_DIR variables are not set, since +# all headers are in the same directory as GLIB_INCLUDE_DIRS. +# +# Copyright (C) 2012 Raphael Kubo da Costa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +find_package(PkgConfig) +pkg_check_modules(PC_GLIB QUIET glib-2.0) + +find_library(GLIB_LIBRARIES + NAMES glib-2.0 + HINTS ${PC_GLIB_LIBDIR} + ${PC_GLIB_LIBRARY_DIRS} +) + +# Files in glib's main include path may include glibconfig.h, which, +# for some odd reason, is normally in $LIBDIR/glib-2.0/include. +get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH) +find_path(GLIBCONFIG_INCLUDE_DIR + NAMES glibconfig.h + HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR} + ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/include +) + +find_path(GLIB_INCLUDE_DIR + NAMES glib.h + HINTS ${PC_GLIB_INCLUDEDIR} + ${PC_GLIB_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0 +) + +set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR}) + +if(GLIBCONFIG_INCLUDE_DIR) + # Version detection + file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS) + string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}") + set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}") +endif() + +# Additional Glib components. We only look for libraries, as not all of them +# have corresponding headers and all headers are installed alongside the main +# glib ones. +foreach (_component ${GLIB_FIND_COMPONENTS}) + if (${_component} STREQUAL "gio") + find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES) + elseif (${_component} STREQUAL "gobject") + find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES) + elseif (${_component} STREQUAL "gmodule") + find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES) + elseif (${_component} STREQUAL "gthread") + find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES) + elseif (${_component} STREQUAL "gio-unix") + # gio-unix is compiled as part of the gio library, but the include paths + # are separate from the shared glib ones. Since this is currently only used + # by WebKitGTK+ we don't go to extraordinary measures beyond pkg-config. + pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0) + endif () +endforeach () + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} + VERSION_VAR GLIB_VERSION) + +mark_as_advanced( + GLIBCONFIG_INCLUDE_DIR + GLIB_GIO_LIBRARIES + GLIB_GIO_UNIX_LIBRARIES + GLIB_GMODULE_LIBRARIES + GLIB_GOBJECT_LIBRARIES + GLIB_GTHREAD_LIBRARIES + GLIB_INCLUDE_DIR + GLIB_INCLUDE_DIRS + GLIB_LIBRARIES +) diff --git a/build/cmake/FindGradle.cmake b/build/cmake/FindGradle.cmake new file mode 100644 index 00000000000..8845d697e61 --- /dev/null +++ b/build/cmake/FindGradle.cmake @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +# GRADLE_FOUND - system has Gradle +# GRADLE_EXECUTABLE - the Gradle executable +# +# It will search the environment variable ANT_HOME if it is set + +include(FindPackageHandleStandardArgs) + +find_program(GRADLE_EXECUTABLE NAMES gradle PATHS $ENV{GRADLE_HOME}/bin NO_CMAKE_FIND_ROOT_PATH) +find_package_handle_standard_args(Gradle DEFAULT_MSG GRADLE_EXECUTABLE) +mark_as_advanced(GRADLE_EXECUTABLE) diff --git a/build/cmake/FindLibevent.cmake b/build/cmake/FindLibevent.cmake new file mode 100644 index 00000000000..2bcd7099a7f --- /dev/null +++ b/build/cmake/FindLibevent.cmake @@ -0,0 +1,41 @@ +# find LibEvent +# an event notification library (http://libevent.org/) +# +# Usage: +# LIBEVENT_INCLUDE_DIRS, where to find LibEvent headers +# LIBEVENT_LIBRARIES, LibEvent libraries +# Libevent_FOUND, If false, do not try to use libevent + +set(LIBEVENT_ROOT CACHE PATH "Root directory of libevent installation") +set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}" ${LIBEVENT_ROOT}) +foreach(prefix ${LibEvent_EXTRA_PREFIXES}) + list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include") + list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib") +endforeach() + +find_path(LIBEVENT_INCLUDE_DIRS event.h PATHS ${LibEvent_INCLUDE_PATHS}) +# "lib" prefix is needed on Windows +find_library(LIBEVENT_LIBRARIES NAMES event libevent PATHS ${LibEvent_LIBRARIES_PATHS}) + +if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS) + set(Libevent_FOUND TRUE) + set(LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARIES}) +else () + set(Libevent_FOUND FALSE) +endif () + +if (Libevent_FOUND) + if (NOT Libevent_FIND_QUIETLY) + message(STATUS "Found libevent: ${LIBEVENT_LIBRARIES}") + endif () +else () + if (LibEvent_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find libevent.") + endif () + message(STATUS "libevent NOT found.") +endif () + +mark_as_advanced( + LIBEVENT_LIBRARIES + LIBEVENT_INCLUDE_DIRS + ) diff --git a/build/cmake/HunterGate.cmake b/build/cmake/HunterGate.cmake new file mode 100644 index 00000000000..3a8043d2b10 --- /dev/null +++ b/build/cmake/HunterGate.cmake @@ -0,0 +1,540 @@ +# Copyright (c) 2013-2017, Ruslan Baratov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This is a gate file to Hunter package manager. +# Include this file using `include` command and add package you need, example: +# +# cmake_minimum_required(VERSION 3.0) +# +# include("cmake/HunterGate.cmake") +# HunterGate( +# URL "https://github.com/path/to/hunter/archive.tar.gz" +# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" +# ) +# +# project(MyProject) +# +# hunter_add_package(Foo) +# hunter_add_package(Boo COMPONENTS Bar Baz) +# +# Projects: +# * https://github.com/hunter-packages/gate/ +# * https://github.com/ruslo/hunter + +option(HUNTER_ENABLED "Enable Hunter package manager support" ON) +if(HUNTER_ENABLED) + if(CMAKE_VERSION VERSION_LESS "3.0") + message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management." + " Update CMake or set HUNTER_ENABLED to OFF.") + endif() +endif() + +include(CMakeParseArguments) # cmake_parse_arguments + +option(HUNTER_STATUS_PRINT "Print working status" ON) +option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) + +set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki") + +function(hunter_gate_status_print) + foreach(print_message ${ARGV}) + if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) + message(STATUS "[hunter] ${print_message}") + endif() + endforeach() +endfunction() + +function(hunter_gate_status_debug) + foreach(print_message ${ARGV}) + if(HUNTER_STATUS_DEBUG) + string(TIMESTAMP timestamp) + message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") + endif() + endforeach() +endfunction() + +function(hunter_gate_wiki wiki_page) + message("------------------------------ WIKI -------------------------------") + message(" ${HUNTER_WIKI}/${wiki_page}") + message("-------------------------------------------------------------------") + message("") + message(FATAL_ERROR "") +endfunction() + +function(hunter_gate_internal_error) + message("") + foreach(print_message ${ARGV}) + message("[hunter ** INTERNAL **] ${print_message}") + endforeach() + message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_wiki("error.internal") +endfunction() + +function(hunter_gate_fatal_error) + cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}") + string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki) + if(have_no_wiki) + hunter_gate_internal_error("Expected wiki") + endif() + message("") + foreach(x ${hunter_UNPARSED_ARGUMENTS}) + message("[hunter ** FATAL ERROR **] ${x}") + endforeach() + message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_wiki("${hunter_WIKI}") +endfunction() + +function(hunter_gate_user_error) + hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data") +endfunction() + +function(hunter_gate_self root version sha1 result) + string(COMPARE EQUAL "${root}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("root is empty") + endif() + + string(COMPARE EQUAL "${version}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("version is empty") + endif() + + string(COMPARE EQUAL "${sha1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("sha1 is empty") + endif() + + string(SUBSTRING "${sha1}" 0 7 archive_id) + + if(EXISTS "${root}/cmake/Hunter") + set(hunter_self "${root}") + else() + set( + hunter_self + "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" + ) + endif() + + set("${result}" "${hunter_self}" PARENT_SCOPE) +endfunction() + +# Set HUNTER_GATE_ROOT cmake variable to suitable value. +function(hunter_gate_detect_root) + # Check CMake variable + string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) + if(not_empty) + set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") + return() + endif() + + # Check environment variable + string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) + if(not_empty) + set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") + return() + endif() + + # Check HOME environment variable + string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") + return() + endif() + + # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) + if(WIN32) + string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using SYSTEMDRIVE environment variable" + ) + return() + endif() + + string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using USERPROFILE environment variable" + ) + return() + endif() + endif() + + hunter_gate_fatal_error( + "Can't detect HUNTER_ROOT" + WIKI "error.detect.hunter.root" + ) +endfunction() + +macro(hunter_gate_lock dir) + if(NOT HUNTER_SKIP_LOCK) + if("${CMAKE_VERSION}" VERSION_LESS "3.2") + hunter_gate_fatal_error( + "Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK" + WIKI "error.can.not.lock" + ) + endif() + hunter_gate_status_debug("Locking directory: ${dir}") + file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) + hunter_gate_status_debug("Lock done") + endif() +endmacro() + +function(hunter_gate_download dir) + string( + COMPARE + NOTEQUAL + "$ENV{HUNTER_DISABLE_AUTOINSTALL}" + "" + disable_autoinstall + ) + if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) + hunter_gate_fatal_error( + "Hunter not found in '${dir}'" + "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" + "Settings:" + " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" + " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" + WIKI "error.run.install" + ) + endif() + string(COMPARE EQUAL "${dir}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("Empty 'dir' argument") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_URL empty") + endif() + + set(done_location "${dir}/DONE") + set(sha1_location "${dir}/SHA1") + + set(build_dir "${dir}/Build") + set(cmakelists "${dir}/CMakeLists.txt") + + hunter_gate_lock("${dir}") + if(EXISTS "${done_location}") + # while waiting for lock other instance can do all the job + hunter_gate_status_debug("File '${done_location}' found, skip install") + return() + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(MAKE_DIRECTORY "${build_dir}") # check directory permissions + + # Disabling languages speeds up a little bit, reduces noise in the output + # and avoids path too long windows error + file( + WRITE + "${cmakelists}" + "cmake_minimum_required(VERSION 3.0)\n" + "project(HunterDownload LANGUAGES NONE)\n" + "include(ExternalProject)\n" + "ExternalProject_Add(\n" + " Hunter\n" + " URL\n" + " \"${HUNTER_GATE_URL}\"\n" + " URL_HASH\n" + " SHA1=${HUNTER_GATE_SHA1}\n" + " DOWNLOAD_DIR\n" + " \"${dir}\"\n" + " SOURCE_DIR\n" + " \"${dir}/Unpacked\"\n" + " CONFIGURE_COMMAND\n" + " \"\"\n" + " BUILD_COMMAND\n" + " \"\"\n" + " INSTALL_COMMAND\n" + " \"\"\n" + ")\n" + ) + + if(HUNTER_STATUS_DEBUG) + set(logging_params "") + else() + set(logging_params OUTPUT_QUIET) + endif() + + hunter_gate_status_debug("Run generate") + + # Need to add toolchain file too. + # Otherwise on Visual Studio + MDD this will fail with error: + # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" + if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") + get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") + else() + # 'toolchain_arg' can't be empty + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") + endif() + + string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) + if(no_make) + set(make_arg "") + else() + # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM + set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") + endif() + + execute_process( + COMMAND + "${CMAKE_COMMAND}" + "-H${dir}" + "-B${build_dir}" + "-G${CMAKE_GENERATOR}" + "${toolchain_arg}" + ${make_arg} + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error("Configure project failed") + endif() + + hunter_gate_status_print( + "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" + " ${HUNTER_GATE_URL}" + " -> ${dir}" + ) + execute_process( + COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error("Build project failed") + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") + file(WRITE "${done_location}" "DONE") + + hunter_gate_status_debug("Finished") +endfunction() + +# Must be a macro so master file 'cmake/Hunter' can +# apply all variables easily just by 'include' command +# (otherwise PARENT_SCOPE magic needed) +macro(HunterGate) + if(HUNTER_GATE_DONE) + # variable HUNTER_GATE_DONE set explicitly for external project + # (see `hunter_download`) + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() + + # First HunterGate command will init Hunter, others will be ignored + get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) + + if(NOT HUNTER_ENABLED) + # Empty function to avoid error "unknown function" + function(hunter_add_package) + endfunction() + + set( + _hunter_gate_disabled_mode_dir + "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" + ) + if(EXISTS "${_hunter_gate_disabled_mode_dir}") + hunter_gate_status_debug( + "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" + ) + list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") + endif() + elseif(_hunter_gate_done) + hunter_gate_status_debug("Secondary HunterGate (use old settings)") + hunter_gate_self( + "${HUNTER_CACHED_ROOT}" + "${HUNTER_VERSION}" + "${HUNTER_SHA1}" + _hunter_self + ) + include("${_hunter_self}/cmake/Hunter") + else() + set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}") + + string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) + if(_have_project_name) + hunter_gate_fatal_error( + "Please set HunterGate *before* 'project' command. " + "Detected project: ${PROJECT_NAME}" + WIKI "error.huntergate.before.project" + ) + endif() + + cmake_parse_arguments( + HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} + ) + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) + string( + COMPARE + NOTEQUAL + "${HUNTER_GATE_UNPARSED_ARGUMENTS}" + "" + _have_unparsed + ) + string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) + string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) + + if(_have_unparsed) + hunter_gate_user_error( + "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" + ) + endif() + if(_empty_sha1) + hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") + endif() + if(_empty_url) + hunter_gate_user_error("URL suboption of HunterGate is mandatory") + endif() + if(_have_global) + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") + endif() + endif() + if(HUNTER_GATE_LOCAL) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") + endif() + endif() + if(_have_filepath) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") + endif() + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") + endif() + endif() + + hunter_gate_detect_root() # set HUNTER_GATE_ROOT + + # Beautify path, fix probable problems with windows path slashes + get_filename_component( + HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE + ) + hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") + if(NOT HUNTER_ALLOW_SPACES_IN_PATH) + string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) + if(NOT _contain_spaces EQUAL -1) + hunter_gate_fatal_error( + "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." + "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" + "(Use at your own risk!)" + WIKI "error.spaces.in.hunter.root" + ) + endif() + endif() + + string( + REGEX + MATCH + "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" + HUNTER_GATE_VERSION + "${HUNTER_GATE_URL}" + ) + string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) + if(_is_empty) + set(HUNTER_GATE_VERSION "unknown") + endif() + + hunter_gate_self( + "${HUNTER_GATE_ROOT}" + "${HUNTER_GATE_VERSION}" + "${HUNTER_GATE_SHA1}" + _hunter_self + ) + + set(_master_location "${_hunter_self}/cmake/Hunter") + if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") + # Hunter downloaded manually (e.g. by 'git clone') + set(_unused "xxxxxxxxxx") + set(HUNTER_GATE_SHA1 "${_unused}") + set(HUNTER_GATE_VERSION "${_unused}") + else() + get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) + set(_done_location "${_archive_id_location}/DONE") + set(_sha1_location "${_archive_id_location}/SHA1") + + # Check Hunter already downloaded by HunterGate + if(NOT EXISTS "${_done_location}") + hunter_gate_download("${_archive_id_location}") + endif() + + if(NOT EXISTS "${_done_location}") + hunter_gate_internal_error("hunter_gate_download failed") + endif() + + if(NOT EXISTS "${_sha1_location}") + hunter_gate_internal_error("${_sha1_location} not found") + endif() + file(READ "${_sha1_location}" _sha1_value) + string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal) + if(NOT _is_equal) + hunter_gate_internal_error( + "Short SHA1 collision:" + " ${_sha1_value} (from ${_sha1_location})" + " ${HUNTER_GATE_SHA1} (HunterGate)" + ) + endif() + if(NOT EXISTS "${_master_location}") + hunter_gate_user_error( + "Master file not found:" + " ${_master_location}" + "try to update Hunter/HunterGate" + ) + endif() + endif() + include("${_master_location}") + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() +endmacro() diff --git a/build/cmake/README.md b/build/cmake/README.md new file mode 100644 index 00000000000..ebc4f7da133 --- /dev/null +++ b/build/cmake/README.md @@ -0,0 +1,60 @@ +# Apache Thrift - CMake build + +## Goal +Extend Apache Thrift's *make cross* approach to the build system. + +Due to growing the field of operating system support, a proper executable +and library detection mechanism running on as much platforms as possible +becomes required. The other aspect to simplify the release process and +package generation process. + +As nice side benefit of CMake is the generation of development environment +specific soultion files. => No solution files within source tree. + + +## Usage +just do this: + + mkdir cmake-build && cd cmake-build + cmake .. + +if you use a specific toolchain pass it to cmake, the same for options: + + cmake -DCMAKE_TOOLCHAIN_FILE=../build/cmake/mingw32-toolchain.cmake .. + cmake -DCMAKE_C_COMPILER=clang-3.5 -DCMAKE_CXX_COMPILER=clang++-3.5 .. + cmake -DTHRIFT_COMPILER_HS=OFF .. + cmake -DWITH_ZLIB=ON .. + +or on Windows + + cmake -G "Visual Studio 12 2013 Win64" \ + -DBOOST_ROOT=C:/3rdparty/boost_1_58_0 \ + -DZLIB_ROOT=C:/3rdparty/zlib128-dll \ + -DWITH_SHARED_LIB=off -DWITH_BOOSTTHREADS=ON .. + +and open the development environment you like with the solution or do this: + + make + make check + make cross + make dist + +to generate an installer and distribution package do this: + + cpack + +## TODO +* git hash or tag based versioning depending on source state +* build tutorial +* build test +* with/without language lib// +* enable/disable +* make cross +* make dist (create an alias to make package_source) +* make doc +* cpack (C++ and make dist only ?) + * thrift-compiler + * libthrift + * tutorial + * test +* merge into /README.md diff --git a/build/cmake/ThriftMacros.cmake b/build/cmake/ThriftMacros.cmake new file mode 100644 index 00000000000..48b0d45c34c --- /dev/null +++ b/build/cmake/ThriftMacros.cmake @@ -0,0 +1,96 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + + +set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE) + + +macro(ADD_LIBRARY_THRIFT name) + +if(WITH_SHARED_LIB) + add_library(${name} SHARED ${ARGN}) + set_target_properties(${name} PROPERTIES + OUTPUT_NAME ${name} + VERSION ${thrift_VERSION} + SOVERSION ${thrift_VERSION}) + list(APPEND thrift_lib_targets ${name}) +endif() + +if(WITH_STATIC_LIB) + add_library(${name}_static STATIC ${ARGN}) + set_target_properties(${name}_static PROPERTIES + OUTPUT_NAME ${name}${STATIC_POSTFIX} + VERSION ${thrift_VERSION} + SOVERSION ${thrift_VERSION}) + list(APPEND thrift_lib_targets ${name}_static) +endif() + +endmacro(ADD_LIBRARY_THRIFT) + + +macro(TARGET_INCLUDE_DIRECTORIES_THRIFT name) + +if(WITH_SHARED_LIB) + target_include_directories(${name} PUBLIC ${ARGN}) +endif() + +if(WITH_STATIC_LIB) + target_include_directories(${name}_static PUBLIC ${ARGN}) +endif() + +endmacro(TARGET_INCLUDE_DIRECTORIES_THRIFT) + + +macro(TARGET_LINK_LIBRARIES_THRIFT name) + +if(WITH_SHARED_LIB) + target_link_libraries(${name} ${ARGN}) +endif() + +if(WITH_STATIC_LIB) + target_link_libraries(${name}_static ${ARGN}) +endif() + +endmacro(TARGET_LINK_LIBRARIES_THRIFT) + + +macro(LINK_AGAINST_THRIFT_LIBRARY target libname) + +if (WITH_SHARED_LIB) + target_link_libraries(${target} ${libname}) +elseif (WITH_STATIC_LIB) + target_link_libraries(${target} ${libname}_static) +else() + message(FATAL "Not linking with shared or static libraries?") +endif() + +endmacro(LINK_AGAINST_THRIFT_LIBRARY) + + +macro(TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY target libname) + +if(WITH_SHARED_LIB) + target_link_libraries(${target} ${ARGN} ${libname}) +endif() + +if(WITH_STATIC_LIB) + target_link_libraries(${target}_static ${ARGN} ${libname}_static) +endif() + +endmacro(TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY) diff --git a/build/cmake/android-toolchain.cmake b/build/cmake/android-toolchain.cmake new file mode 100644 index 00000000000..15f3d002a00 --- /dev/null +++ b/build/cmake/android-toolchain.cmake @@ -0,0 +1,26 @@ +set(ANDROID_NDK "/opt/android-ndk" CACHE) +set(ANDROID_PLATFORM "android-15" CACHE) +set(ANDROID_ARCH "arch-arm" CACHE) +set(ANDROID_TOOL_ARCH "android-arm" CACHE) +set(ANDROID_CPU "armeabi-v7a" CACHE) +set(ANDROID_GCC_VERSION 4.9 CACHE) +set(HOST_ARCH linux-x86_64 CACHE) + +set(CMAKE_SYSTEM_NAME Android) +set(ANDROID_SYSROOT "${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/${ANDROID_ARCH}") +set(ANDROID_TRIPLET arm-linux-androideabi) +set(ANDROID_STL "${ANDROID_NDK}/sources/cxx-stl/gnu-libstd++/${ANDROID_GCC_VERSION}") + +set(_COMPILER_ROOT ${ANDROID_NDK}/prebuilt/${ANDROID_TRIPLET}-${ANDROID_GCC_VERSION}/prebuilt/${HOST_ARCH}) +set(CMAKE_C_COMPILER ${_COMPILER_ROOT}/bin/${ANDROID_TRIPLET}-gcc) +set(CMAKE_CXCX_COMPILER ${_COMPILER_ROOT}/bin/${ANDROID_TRIPLET}-g++) + +include_directories( + ${ANDROID_STL}/include + ${ANDROID_STL}/libs/${ANDROID_CPU}/include) + +set(CMAKE_FIND_ROOT_PATH ${ANDROID_SYSROOT}) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in new file mode 100644 index 00000000000..181ea180e97 --- /dev/null +++ b/build/cmake/config.h.in @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* config.h generated by CMake from config.h.in */ + +#ifndef CONFIG_H +#define CONFIG_H + + +/* Name of package */ +#cmakedefine PACKAGE "${PACKAGE}" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "${PACKAGE_BUGREPORT}" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "${PACKAGE_NAME}" + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME "${PACKAGE_TARNAME}" + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "${PACKAGE_URL}" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "${PACKAGE_VERSION}" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "${PACKAGE_STRING}" + +/* Version number of package */ +#define VERSION "${VERSION}" + +/************************** DEFINES *************************/ + +/* Define if the AI_ADDRCONFIG symbol is unavailable */ +#cmakedefine AI_ADDRCONFIG 0 + +/* Possible value for SIGNED_RIGHT_SHIFT_IS */ +/* TODO: This is just set to 1 for the moment + port the macro aclocal/ax_signed_right_shift.m4 to CMake to make this work */ +#define ARITHMETIC_RIGHT_SHIFT 1 + +/* Indicates the effect of the right shift operator on negative signed + integers */ +/* TODO: This is just set to 1 for the moment */ +#define SIGNED_RIGHT_SHIFT_IS 1 + +/* Use *.h extension for parser header file */ +/* TODO: This might now be necessary anymore as it is set only for automake < 1.11 + see: aclocal/ac_prog_bison.m4 */ +#cmakedefine BISON_USE_PARSER_H_EXTENSION 1 + +/* replaces POSIX pthread by boost::thread */ +#cmakedefine USE_BOOST_THREAD 1 + +/* replaces POSIX pthread by std::thread */ +#cmakedefine USE_STD_THREAD 1 + +/* Define to 1 if strerror_r returns char *. */ +#cmakedefine STRERROR_R_CHAR_P 1 + + +/************************** HEADER FILES *************************/ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PTHREAD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SCHED_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/*************************** FUNCTIONS ***************************/ + +/* Define to 1 if you have the `gethostbyname' function. */ +#cmakedefine HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the `gethostbyname_r' function. */ +#cmakedefine HAVE_GETHOSTBYNAME_R 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#cmakedefine HAVE_STRERROR_R 1 + +/* Define to 1 if you have the `sched_get_priority_max' function. */ +#cmakedefine HAVE_SCHED_GET_PRIORITY_MAX 1 + +/* Define to 1 if you have the `sched_get_priority_min' function. */ +#cmakedefine HAVE_SCHED_GET_PRIORITY_MIN 1 + + +/* Define to 1 if strerror_r returns char *. */ +#cmakedefine STRERROR_R_CHAR_P 1 + +#endif \ No newline at end of file diff --git a/build/cmake/mingw32-toolchain.cmake b/build/cmake/mingw32-toolchain.cmake new file mode 100644 index 00000000000..864c0ebe4d4 --- /dev/null +++ b/build/cmake/mingw32-toolchain.cmake @@ -0,0 +1,24 @@ +# CMake mingw32 cross compile toolchain file + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc) +SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++) +SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres) + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(BUILD_SHARED_LIBS OFF) +SET(CMAKE_EXE_LINKER_FLAGS "-static") +set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-static-libgcc") +set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-static-libstdc++") diff --git a/compiler/cpp/CMakeLists.txt b/compiler/cpp/CMakeLists.txt index 606bfcd5bc5..4d5373e54e3 100644 --- a/compiler/cpp/CMakeLists.txt +++ b/compiler/cpp/CMakeLists.txt @@ -45,7 +45,9 @@ else() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) endif() +hunter_add_package(flex) find_package(FLEX REQUIRED) +hunter_add_package(bison) find_package(BISON REQUIRED) # Create flex and bison files and build the lib parse static library diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt new file mode 100755 index 00000000000..c29ebaf4396 --- /dev/null +++ b/lib/cpp/CMakeLists.txt @@ -0,0 +1,298 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +include_directories(src) + +# SYSLIBS contains libraries that need to be linked to all lib targets +set(SYSLIBS "") +set(package_deps Boost) +set(boost_components) + +# Create the thrift C++ library +set( thriftcpp_SOURCES + src/thrift/TApplicationException.cpp + src/thrift/TOutput.cpp + src/thrift/async/TAsyncChannel.cpp + src/thrift/async/TConcurrentClientSyncInfo.h + src/thrift/async/TConcurrentClientSyncInfo.cpp + src/thrift/concurrency/ThreadManager.cpp + src/thrift/concurrency/TimerManager.cpp + src/thrift/concurrency/Util.cpp + src/thrift/processor/PeekProcessor.cpp + src/thrift/protocol/TBase64Utils.cpp + src/thrift/protocol/TDebugProtocol.cpp + src/thrift/protocol/TJSONProtocol.cpp + src/thrift/protocol/TMultiplexedProtocol.cpp + src/thrift/protocol/TProtocol.cpp + src/thrift/transport/TTransportException.cpp + src/thrift/transport/TFDTransport.cpp + src/thrift/transport/TSimpleFileTransport.cpp + src/thrift/transport/THttpTransport.cpp + src/thrift/transport/THttpClient.cpp + src/thrift/transport/THttpServer.cpp + src/thrift/transport/TSocket.cpp + src/thrift/transport/TSocketPool.cpp + src/thrift/transport/TServerSocket.cpp + src/thrift/transport/TTransportUtils.cpp + src/thrift/transport/TBufferTransports.cpp + src/thrift/server/TConnectedClient.cpp + src/thrift/server/TServerFramework.cpp + src/thrift/server/TSimpleServer.cpp + src/thrift/server/TThreadPoolServer.cpp + src/thrift/server/TThreadedServer.cpp +) + +# This files don't work on Windows CE as there is no pipe support +# TODO: These files won't work with UNICODE support on windows. If fixed this can be re-added. +if (NOT WINCE) + list(APPEND thriftcpp_SOURCES + src/thrift/transport/TPipe.cpp + src/thrift/transport/TPipeServer.cpp + src/thrift/transport/TFileTransport.cpp + ) +endif() + + +if (WIN32) + list(APPEND thriftcpp_SOURCES + src/thrift/windows/TWinsockSingleton.cpp + src/thrift/windows/SocketPair.cpp + src/thrift/windows/GetTimeOfDay.cpp + src/thrift/windows/WinFcntl.cpp + ) + if(NOT WINCE) + # This file uses pipes so it currently won't work on Windows CE + list(APPEND thriftcpp_SOURCES + src/thrift/windows/OverlappedSubmissionThread.cpp + ) + endif() +else() + # These files evaluate to nothing on Windows, so omit them from the + # Windows build + list(APPEND thriftcpp_SOURCES + src/thrift/VirtualProfiling.cpp + src/thrift/server/TServer.cpp + ) +endif() + +if(WITH_OPENSSL) + hunter_add_package(OpenSSL) + find_package(OpenSSL REQUIRED) + list( APPEND thriftcpp_SOURCES + src/thrift/transport/TSSLSocket.cpp + src/thrift/transport/TSSLServerSocket.cpp + ) + list(APPEND SYSLIBS OpenSSL::SSL OpenSSL::Crypto) + list(APPEND package_deps OpenSSL) +endif() + +# WITH_*THREADS selects which threading library to use +if(WITH_BOOSTTHREADS) + set( thriftcpp_threads_SOURCES + src/thrift/concurrency/BoostThreadFactory.cpp + src/thrift/concurrency/BoostMonitor.cpp + src/thrift/concurrency/BoostMutex.cpp + ) + list(APPEND SYSLIBS "${Boost_LIBRARIES}") + list(APPEND boost_components thread) +elseif(UNIX AND NOT WITH_STDTHREADS) + if(ANDROID) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + else() + list(APPEND SYSLIBS pthread) + endif() + set( thriftcpp_threads_SOURCES + src/thrift/concurrency/PosixThreadFactory.cpp + src/thrift/concurrency/Mutex.cpp + src/thrift/concurrency/Monitor.cpp + ) +else() + if(UNIX) + if(ANDROID) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + else() + list(APPEND SYSLIBS pthread) + endif() + endif() + set( thriftcpp_threads_SOURCES + src/thrift/concurrency/StdThreadFactory.cpp + src/thrift/concurrency/StdMutex.cpp + src/thrift/concurrency/StdMonitor.cpp + ) +endif() + +# Thrift non blocking server +set( thriftcppnb_SOURCES + src/thrift/server/TNonblockingServer.cpp + src/thrift/async/TAsyncProtocolProcessor.cpp + src/thrift/async/TEvhttpServer.cpp + src/thrift/async/TEvhttpClientChannel.cpp +) + +# Thrift zlib server +set( thriftcppz_SOURCES + src/thrift/transport/TZlibTransport.cpp + src/thrift/protocol/THeaderProtocol.cpp + src/thrift/transport/THeaderTransport.cpp + src/thrift/protocol/THeaderProtocol.cpp + src/thrift/transport/THeaderTransport.cpp +) + +# Thrift Qt4 server +set( thriftcppqt_SOURCES + src/thrift/qt/TQIODeviceTransport.cpp + src/thrift/qt/TQTcpServer.cpp +) + +# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT +include(ThriftMacros) + +ADD_LIBRARY_THRIFT(thrift ${thriftcpp_SOURCES} ${thriftcpp_threads_SOURCES}) +if(WIN32) + TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS} ws2_32) +else() + TARGET_LINK_LIBRARIES_THRIFT(thrift ${SYSLIBS}) +endif() + +if(WITH_LIBEVENT) + hunter_add_package(Libevent) + find_package(Libevent CONFIG REQUIRED) # Libevent comes with CMake support form upstream + include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS}) + + ADD_LIBRARY_THRIFT(thriftnb ${thriftcppnb_SOURCES}) + TARGET_LINK_LIBRARIES_THRIFT(thriftnb ${SYSLIBS} Libevent::event_core Libevent::event_extra) + TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftnb thrift) + list(APPEND package_deps Libevent) +endif() + +if(WITH_ZLIB) + hunter_add_package(ZLIB) + find_package(ZLIB CONFIG REQUIRED) + include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS}) + + ADD_LIBRARY_THRIFT(thriftz ${thriftcppz_SOURCES}) + TARGET_LINK_LIBRARIES_THRIFT(thriftz ${SYSLIBS} ZLIB::zlib) + TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftz thrift) + list(APPEND package_deps ZLIB) +endif() + +if(WITH_QT4) + set(CMAKE_AUTOMOC ON) + find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork) + ADD_LIBRARY_THRIFT(thriftqt ${thriftcppqt_SOURCES}) + TARGET_LINK_LIBRARIES_THRIFT(thriftqt ${SYSLIBS} Qt4::QtCore Qt4::QtNetwork) + TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftqt thrift) +endif() + +if(WITH_QT5) + # Qt5 has its own directory to avoid conflict with Qt4 caused by CMAKE_AUTOMOC + add_subdirectory(src/thrift/qt) +endif() + +if(MSVC) + add_definitions("-DUNICODE -D_UNICODE") +endif() + +add_definitions("-D__STDC_LIMIT_MACROS") + +# Installation (https://github.com/forexample/package-example) + +# Layout. This works for all platforms: +# * /lib/cmake/ +# * /lib/ +# * /include/ +set(config_install_dir "lib/cmake/${PROJECT_NAME}") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Configuration +set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(namespace "${PROJECT_NAME}::") + +# Include module with fuction 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Configure 'ConfigVersion.cmake' +# Use: +# * PROJECT_VERSION +write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion +) + +# Configure 'Config.cmake' +# Use variables: +# * TARGETS_EXPORT_NAME +# * PROJECT_NAME +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/build/cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) + +# Targets: +# * /lib/libthrift.a +# * /lib/libthriftz.a +# * /lib/libthriftnb.a +# * header location after install: /include/thrift/thrift-config.h +# * headers can be included by C++ code `#include ` +install( + TARGETS ${thrift_lib_targets} + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${INCLUDE_INSTALL_DIR}" +) + +# Headers: +# * src/thrift/thrift-config.h -> /include/thrift/thrift-config.h +install( + DIRECTORY "src/thrift" + DESTINATION "${INCLUDE_INSTALL_DIR}" + FILES_MATCHING PATTERN "*.h" PATTERN "*.tcc" +) + +# Copy config.h file +install( + DIRECTORY "${CMAKE_BINARY_DIR}/thrift" + DESTINATION "${INCLUDE_INSTALL_DIR}" + FILES_MATCHING PATTERN "*.h" +) + +# Config +# * /lib/cmake/thrift/thriftConfig.cmake +# * /lib/cmake/thrift/thriftConfigVersion.cmake +install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" +) + +# Config +# * /lib/cmake/thrift/thriftTargets.cmake +install( + EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" +) + +if(BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/lib/py/CMakeLists.txt b/lib/py/CMakeLists.txt new file mode 100644 index 00000000000..7bb91fe6712 --- /dev/null +++ b/lib/py/CMakeLists.txt @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +include_directories(${PYTHON_INCLUDE_DIRS}) + +add_custom_target(python_build ALL + COMMAND ${PYTHON_EXECUTABLE} setup.py build + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Building Python library" +) + +if(BUILD_TESTING) + add_test(PythonTestSSLSocket ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_sslsocket.py) + add_test(PythonThriftJson ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/thrift_json.py) +endif() From b0503d3087edca7919932cae228d762c8555d88d Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 15 Oct 2017 11:12:35 -0400 Subject: [PATCH 2/4] Fix sources to account for deleted C++ files --- lib/cpp/CMakeLists.txt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index c29ebaf4396..a864fc31545 100755 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -26,36 +26,39 @@ set(boost_components) # Create the thrift C++ library set( thriftcpp_SOURCES + src/thrift/Thrift.cpp src/thrift/TApplicationException.cpp - src/thrift/TOutput.cpp - src/thrift/async/TAsyncChannel.cpp - src/thrift/async/TConcurrentClientSyncInfo.h - src/thrift/async/TConcurrentClientSyncInfo.cpp + src/thrift/VirtualProfiling.cpp src/thrift/concurrency/ThreadManager.cpp src/thrift/concurrency/TimerManager.cpp src/thrift/concurrency/Util.cpp - src/thrift/processor/PeekProcessor.cpp - src/thrift/protocol/TBase64Utils.cpp src/thrift/protocol/TDebugProtocol.cpp + src/thrift/protocol/TDenseProtocol.cpp src/thrift/protocol/TJSONProtocol.cpp + src/thrift/protocol/TBase64Utils.cpp src/thrift/protocol/TMultiplexedProtocol.cpp - src/thrift/protocol/TProtocol.cpp src/thrift/transport/TTransportException.cpp src/thrift/transport/TFDTransport.cpp + src/thrift/transport/TFileTransport.cpp src/thrift/transport/TSimpleFileTransport.cpp src/thrift/transport/THttpTransport.cpp src/thrift/transport/THttpClient.cpp src/thrift/transport/THttpServer.cpp src/thrift/transport/TSocket.cpp + src/thrift/transport/TPipe.cpp + src/thrift/transport/TPipeServer.cpp + src/thrift/transport/TSSLSocket.cpp src/thrift/transport/TSocketPool.cpp src/thrift/transport/TServerSocket.cpp + src/thrift/transport/TSSLServerSocket.cpp src/thrift/transport/TTransportUtils.cpp src/thrift/transport/TBufferTransports.cpp - src/thrift/server/TConnectedClient.cpp - src/thrift/server/TServerFramework.cpp + src/thrift/server/TServer.cpp src/thrift/server/TSimpleServer.cpp src/thrift/server/TThreadPoolServer.cpp src/thrift/server/TThreadedServer.cpp + src/thrift/async/TAsyncChannel.cpp + src/thrift/processor/PeekProcessor.cpp ) # This files don't work on Windows CE as there is no pipe support @@ -148,10 +151,6 @@ set( thriftcppnb_SOURCES # Thrift zlib server set( thriftcppz_SOURCES src/thrift/transport/TZlibTransport.cpp - src/thrift/protocol/THeaderProtocol.cpp - src/thrift/transport/THeaderTransport.cpp - src/thrift/protocol/THeaderProtocol.cpp - src/thrift/transport/THeaderTransport.cpp ) # Thrift Qt4 server From 833df2be32d2797a70deb35a708fd29999fbecf5 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 15 Oct 2017 11:13:49 -0400 Subject: [PATCH 3/4] Backport fix for SSLv3 (https://github.com/apache/thrift/pull/944) --- lib/cpp/src/thrift/transport/TSSLSocket.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp index fd285dbd9ed..e9b3bb0b1a7 100644 --- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp @@ -140,13 +140,11 @@ SSLContext::SSLContext(const SSLProtocol& protocol) { if(protocol == SSLTLS) { ctx_ = SSL_CTX_new(SSLv23_method()); - } - else if(protocol == SSLv3) - { +#ifndef OPENSSL_NO_SSL3 + } else if (protocol == SSLv3) { ctx_ = SSL_CTX_new(SSLv3_method()); - } - else if(protocol == TLSv1_0) - { +#endif + } else if (protocol == TLSv1_0) { ctx_ = SSL_CTX_new(TLSv1_method()); } else if(protocol == TLSv1_1) From d64f2178009dc574acf59dec63a377104390a234 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Mon, 16 Oct 2017 05:50:33 -0400 Subject: [PATCH 4/4] Backport fix for newer OpenSSL libraries (https://github.com/apache/thrift/pull/1102) --- lib/cpp/src/thrift/transport/TSSLSocket.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp index e9b3bb0b1a7..075e64be396 100644 --- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp +++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp @@ -96,7 +96,11 @@ void initializeOpenSSL() { SSL_library_init(); SSL_load_error_strings(); // static locking +#ifdef CRYPTO_num_locks + mutexes = boost::shared_array(new Mutex[CRYPTO_num_locks()]); +#else mutexes = boost::shared_array(new Mutex[::CRYPTO_num_locks()]); +#endif if (mutexes == NULL) { throw TTransportException(TTransportException::INTERNAL_ERROR, "initializeOpenSSL() failed, "