Merge pull request #159 from yandex/chebotarev-osx

[WIP] OS X 10.12 build
This commit is contained in:
alexey-milovidov 2016-11-03 21:14:30 +04:00 committed by GitHub
commit 3d05948c45
15 changed files with 142 additions and 17 deletions

View File

@ -132,6 +132,7 @@ include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/MongoDB/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Zip/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libcommon/include/)
include_directories (${ClickHouse_BINARY_DIR}/libs/libcommon/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libpocoext/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libmysqlxx/include/)
@ -154,6 +155,23 @@ include_directories (/usr/local/include/)
link_directories (/usr/local/lib)
# External libraries
# 1. openssl
include_directories ("/usr/local/opt/openssl/include")
set (OPENSSL_HINTS "/usr/local/opt/openssl/lib")
find_library (LIBSSL libssl.a HINTS ${OPENSSL_HINTS})
find_library (LIBCRYPTO libcrypto.a HINTS ${OPENSSL_HINTS})
set (OPENSSL_LIBS ${LIBSSL} ${LIBCRYPTO})
# 2. icu4c
include_directories ("/usr/local/opt/icu4c/include")
set (ICU_HINTS "/usr/local/opt/icu4c/lib")
find_library (ICUI18N libicui18n.a HINTS ${ICU_HINTS})
find_library (ICUUC libicuuc.a HINTS ${ICU_HINTS})
find_library (ICUDATA libicudata.a HINTS ${ICU_HINTS})
set (ICU_LIBS ${ICUI18N} ${ICUUC} ${ICUDATA})
# Directory for Yandex specific files
SET(CLICKHOUSE_PRIVATE_DIR ${ClickHouse_SOURCE_DIR}/private/)

View File

@ -46,9 +46,14 @@ add_library (re2_st ${re2_headers})
set_target_properties(re2_st PROPERTIES COMPILE_DEFINITIONS "NO_THREADS;re2=re2_st")
ADD_CUSTOM_COMMAND(
TARGET re2_st
POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create_st_headers.sh ARGS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Creating headers for re2_st library.")
message ("Creating headers for re2_st library.")
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/re2_st)
foreach (FILENAME filtered_re2.h re2.h set.h stringpiece.h variadic_function.h)
file (READ ${CMAKE_CURRENT_SOURCE_DIR}/re2/${FILENAME} CONTENT)
string(REGEX REPLACE "using re2::RE2;" "" CONTENT "${CONTENT}")
string(REGEX REPLACE "namespace re2" "namespace re2_st" CONTENT "${CONTENT}")
string(REGEX REPLACE "re2::" "re2_st::" CONTENT "${CONTENT}")
string(REGEX REPLACE "\"re2/" "\"re2_st/" CONTENT "${CONTENT}")
string(REGEX REPLACE "(.\\*?_H)" "\\1_ST" CONTENT "${CONTENT}")
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/re2_st/${FILENAME} "${CONTENT}")
endforeach ()

View File

@ -19,7 +19,7 @@ endif()
if (DISABLE_MONGODB)
add_definitions(-D DISABLE_MONGODB)
else()
set (LINK_MONGOCLIENT libmongoclient.a libssl.a libcrypto.a libboost_thread.a)
set (LINK_MONGOCLIENT libmongoclient.a ${OPENSSL_LIBS} libboost_thread.a)
endif()
if (DISABLE_LIBTCMALLOC)

View File

@ -1,6 +1,11 @@
#pragma once
#pragma GCC diagnostic push
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <unicode/ucol.h>
#pragma GCC diagnostic pop
#include <DB/Common/Exception.h>
#include <DB/IO/WriteHelpers.h>

View File

@ -1,4 +1,6 @@
#ifndef __APPLE__
#include <sched.h>
#endif
#include <iostream>
#include <iomanip>

66
doc/build_osx.md Normal file
View File

@ -0,0 +1,66 @@
# How to build ClickHouse
Build should work on Mac OS X 10.12. If you're using earlier version, you can try to build ClickHouse using Gentoo Prefix and clang sl in this instruction.
With appropriate changes, build should work on any other OS X distribution.
## Install Xcode
Use App Store.
## Install Homebrew
```
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
## Install cmake, gcc
```
brew install cmake gcc
```
## Install GCC-compatible version of boost
```
brew install boost --cc=gcc-6
```
## Install required libraries from packages
```
brew install icu4c mysql openssl unixodbc
```
# Checkout ClickHouse sources
```
git clone git@github.com:yandex/ClickHouse.git
# or: git clone https://github.com/yandex/ClickHouse.git
cd ClickHouse
```
Note that master branch is not stable.
For stable version, switch to some release branch.
## Use GCC 6 for builds
```
export CC=gcc-6
export CXX=g++-6
```
## Disable MongoDB binding
```
export DISABLE_MONGODB=1
```
# Build ClickHouse
```
mkdir build
cd build
cmake ..
make -j $THREADS
cd ..
```

View File

@ -12,6 +12,12 @@ set_source_files_properties(
include_directories (${CMAKE_CURRENT_BINARY_DIR}/src/)
if (APPLE)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT "${CMAKE_SYSTEM_VERSION}" VERSION_LESS "16.1.0")
set (APPLE_SIERRA_OR_NEWER 1)
else ()
set (APPLE_SIERRA_OR_NEWER 0)
endif ()
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/common/apple_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/common/apple_version.h)
add_library (apple_rt
src/apple_rt.cpp
include/common/apple_rt.h
@ -78,7 +84,7 @@ target_link_libraries (
${MALLOC_LIBRARIES}
pthread
libglib-2.0.a
libicui18n.a libicuuc.a libicudata.a
${ICU_LIBS}
${RT_LIBRARIES})
IF(TESTS)

View File

@ -6,6 +6,9 @@
* To use, include this file with -include compiler parameter.
*/
#include <common/apple_version.h>
#if APPLE_SIERRA_OR_NEWER == 0
/**
* MacOS X doesn't support different clock sources
*
@ -20,3 +23,6 @@
typedef int clockid_t;
int clock_gettime(int clk_id, struct timespec* t);
#else
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
#endif

View File

@ -0,0 +1,3 @@
#pragma once
#define APPLE_SIERRA_OR_NEWER ${APPLE_SIERRA_OR_NEWER}

View File

@ -1,7 +1,12 @@
#include <common/DateLUT.h>
#pragma GCC diagnostic push
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <unicode/timezone.h>
#include <unicode/unistr.h>
#pragma GCC diagnostic pop
DateLUT::DateLUT()
{

View File

@ -5,6 +5,10 @@
* To use, include this file with -include compiler parameter.
*/
#include <common/apple_rt.h>
#if APPLE_SIERRA_OR_NEWER == 0
#include <time.h>
#include <stdlib.h>
#include <mach/mach_init.h>
@ -12,7 +16,6 @@
#include <mach/mach_port.h>
#include <sys/time.h>
#include <common/apple_rt.h>
int clock_gettime_thread(timespec *spec) {
thread_port_t thread = mach_thread_self();
@ -43,3 +46,5 @@ int clock_gettime(int clk_id, struct timespec* t) {
return 0;
}
#endif

View File

@ -14,10 +14,10 @@ else()
SET(RT_LIBRARIES "rt")
endif()
target_link_libraries (date_lut_init common libicui18n.a libicuuc.a libicudata.a dl)
target_link_libraries (date_lut2 common libicui18n.a libicuuc.a libicudata.a dl)
target_link_libraries (date_lut3 common libicui18n.a libicuuc.a libicudata.a dl)
target_link_libraries (date_lut4 common libicui18n.a libicuuc.a libicudata.a dl)
target_link_libraries (date_lut_init common ${ICU_LIBS} dl)
target_link_libraries (date_lut2 common ${ICU_LIBS} dl)
target_link_libraries (date_lut3 common ${ICU_LIBS} dl)
target_link_libraries (date_lut4 common ${ICU_LIBS} dl)
target_link_libraries (multi_version dbms libboost_system.a ${RT_LIBRARIES})
target_link_libraries (json_test dbms libboost_system.a ${RT_LIBRARIES})
target_link_libraries (strong_typedef common)

View File

@ -26,7 +26,7 @@ add_library (mysqlxx
add_dependencies (mysqlxx common)
target_link_libraries (mysqlxx common libmysqlclient.a libssl.a libcrypto.a libz.a dl)
target_link_libraries (mysqlxx common libmysqlclient.a ${OPENSSL_LIBS} libz.a dl)
ADD_CUSTOM_COMMAND(

View File

@ -29,9 +29,13 @@ if (${num_extra_args} GREATER 0)
endif()
set(tmp_file_name ${filename}.init)
set (SED_INPLACE_SUFFIX "")
if (APPLE)
set (SED_INPLACE_SUFFIX "''")
endif ()
add_custom_target(${daemonname}-init.target ALL
COMMAND sed -e 's,[@]DAEMON[@],${daemonname},g' < ${PROJECT_SOURCE_DIR}/tools/init.d/template > ${CMAKE_CURRENT_BINARY_DIR}/${tmp_file_name}
COMMAND sed -i 's,[@]CRONFILE[@],${filename},g' ${CMAKE_CURRENT_BINARY_DIR}/${tmp_file_name}
COMMAND sed -i ${SED_INPLACE_SUFFIX} 's,[@]CRONFILE[@],${filename},g' ${CMAKE_CURRENT_BINARY_DIR}/${tmp_file_name}
COMMAND chmod a+x ${CMAKE_CURRENT_BINARY_DIR}/${tmp_file_name}
COMMENT "Building ${daemonname}"
)

View File

@ -46,8 +46,8 @@ struct AlignedBuffer
{
size_t page = sysconf(_SC_PAGESIZE);
size = size_;
posix_memalign(reinterpret_cast<void **>(&data), page, (size + page - 1) / page * page);
if (!data)
int rc = posix_memalign(reinterpret_cast<void **>(&data), page, (size + page - 1) / page * page);
if (data == nullptr || rc != 0)
throwFromErrno("memalign failed");
}