Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build for Darwin #7149

Merged
merged 8 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/find/fastops.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT ARCH_ARM AND NOT OS_FREEBSD)
option (ENABLE_FASTOPS "Enable fast vectorized mathematical functions library by Mikhail Parakhin" ${NOT_UNBUNDLED})
endif ()

if (ENABLE_FASTOPS)
if (ENABLE_FASTOPS AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/fastops/fastops/fastops.h")
message(FATAL_ERROR "submodule contrib/fastops is missing. to fix try run: \n git submodule update --init --recursive")
set(USE_FASTOPS 0)
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/icu.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option(ENABLE_ICU "Enable ICU" ON)

if(ENABLE_ICU)
if(ENABLE_ICU AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (APPLE)
set(ICU_ROOT "/usr/local/opt/icu4c" CACHE STRING "")
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/parquet.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option (ENABLE_PARQUET "Enable parquet" ON)

if (ENABLE_PARQUET)
if (ENABLE_PARQUET AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")

if (NOT OS_FREEBSD AND NOT APPLE) # Freebsd: ../contrib/arrow/cpp/src/arrow/util/bit-util.h:27:10: fatal error: endian.h: No such file or directory
option(USE_INTERNAL_PARQUET_LIBRARY "Set to FALSE to use system parquet library instead of bundled" ${NOT_UNBUNDLED})
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option (ENABLE_PROTOBUF "Enable protobuf" ON)

if (ENABLE_PROTOBUF)
if (ENABLE_PROTOBUF AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")

option(USE_INTERNAL_PROTOBUF_LIBRARY "Set to FALSE to use system protobuf instead of bundled" ${NOT_UNBUNDLED})

Expand Down
2 changes: 1 addition & 1 deletion cmake/find/readline_edit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include (CMakePushCheckState)
cmake_push_check_state ()

option (ENABLE_READLINE "Enable readline" 1)
if (ENABLE_READLINE)
if (ENABLE_READLINE AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")

set (READLINE_PATHS "/usr/local/opt/readline/lib")
# First try find custom lib for macos users (default lib without history support)
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/snappy.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option(USE_SNAPPY "Enable support of snappy library" ON)

if (USE_SNAPPY)
if (USE_SNAPPY AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
option (USE_INTERNAL_SNAPPY_LIBRARY "Set to FALSE to use system snappy library instead of bundled" ${NOT_UNBUNDLED})

if(NOT USE_INTERNAL_SNAPPY_LIBRARY)
Expand Down
2 changes: 1 addition & 1 deletion cmake/find/ssl.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
option (ENABLE_SSL "Enable ssl" ON)

if (ENABLE_SSL)
if (ENABLE_SSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")

if(NOT ARCH_32)
option(USE_INTERNAL_SSL_LIBRARY "Set to FALSE to use system *ssl library instead of bundled" ${NOT_UNBUNDLED})
Expand Down
19 changes: 12 additions & 7 deletions cmake/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ if (CMAKE_CROSSCOMPILING)
set (HAS_POST_2038_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE)
set (HAS_POST_2038_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE)

# CMake < 3.13 doesn't respect same-name variables as values for options.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't know how to make such things with cmake you can ask colleagues. Will be fixed here bf2a265#diff-6f5216ab1e6a5d2983a9841326e86958R69

# FIXME: broken dependencies
set (USE_SNAPPY OFF)
set (ENABLE_SSL OFF)
set (ENABLE_PROTOBUF OFF)
set (ENABLE_PARQUET OFF)
set (ENABLE_READLINE OFF)
set (ENABLE_ICU OFF)
set (ENABLE_FASTOPS OFF)
# set (USE_SNAPPY OFF)
# set (ENABLE_SSL OFF)
# set (ENABLE_PROTOBUF OFF)
# set (ENABLE_PARQUET OFF)
# set (ENABLE_READLINE OFF)
# set (ENABLE_ICU OFF)
# set (ENABLE_FASTOPS OFF)

message (STATUS "Cross-compiling for Darwin")
else ()
message (FATAL_ERROR "Trying to cross-compile to unsupported target: ${CMAKE_SYSTEM_NAME}!")
endif ()

# Don't know why but CXX_STANDARD doesn't work for cross-compilation
Expand Down
2 changes: 1 addition & 1 deletion contrib/libcxx-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ target_include_directories(cxx SYSTEM BEFORE PUBLIC $<BUILD_INTERFACE:${LIBCXX_S
target_compile_definitions(cxx PRIVATE -D_LIBCPP_BUILDING_LIBRARY -DLIBCXX_BUILDING_LIBCXXABI)

target_compile_options(cxx PUBLIC -nostdinc++ -Wno-reserved-id-macro)
if (OS_DARWIN)
if (OS_DARWIN AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
target_compile_options(cxx PUBLIC -Wno-ctad-maybe-unsupported)
endif ()

Expand Down
15 changes: 9 additions & 6 deletions docker/packager/packager
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di
result = []
cmake_flags = ['$CMAKE_FLAGS', '-DADD_GDB_INDEX_FOR_GOLD=1']

cc = compiler
if compiler.endswith("-darwin"):
cc = compiler[:-len("-darwin")]
else:
cc = compiler
cxx = cc.replace('gcc', 'g++').replace('clang', 'clang++')
if package_type == "deb":
result.append("DEB_CC={}".format(cc))
Expand All @@ -119,11 +122,11 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di
cmake_flags.append('-DCMAKE_CXX_COMPILER=`which {}`'.format(cxx))

if "darwin" in compiler:
cmake_flags.append("-DCMAKE_AR:FILEPATH=/cctools/bin/x86_64-apple-darwin-ar") \
.append("-DCMAKE_RANLIB:FILEPATH=/cctools/bin/x86_64-apple-darwin-ranlib") \
.append("-DCMAKE_SYSTEM_NAME=Darwin") \
.append("-DSDK_PATH=/cctools/MacOSX10.14.sdk") \
.append("-DLINKER_NAME=/cctools/bin/x86_64-apple-darwin-ld")
cmake_flags.append("-DCMAKE_AR:FILEPATH=/cctools/bin/x86_64-apple-darwin-ar")
cmake_flags.append("-DCMAKE_RANLIB:FILEPATH=/cctools/bin/x86_64-apple-darwin-ranlib")
cmake_flags.append("-DCMAKE_SYSTEM_NAME=Darwin")
cmake_flags.append("-DSDK_PATH=/cctools/MacOSX10.14.sdk")
cmake_flags.append("-DLINKER_NAME=/cctools/bin/x86_64-apple-darwin-ld")

if sanitizer:
result.append("SANITIZER={}".format(sanitizer))
Expand Down
22 changes: 10 additions & 12 deletions docs/en/development/build_cross.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,37 @@ sudo apt-get install clang-8

# Install Cross-Compilation Toolset

Let's remember the path where we install `cctools` as ${CCTOOLS}

```bash
mkdir cctools
mkdir ${CCTOOLS}

git clone https://github.com/tpoechtrager/apple-libtapi.git
cd apple-libtapi
INSTALLPREFIX=../cctools ./build.sh
INSTALLPREFIX=${CCTOOLS} ./build.sh
./install.sh
cd ..

git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/cctools
./configure --prefix=../cctools --with-libtapi=../cctools --target=x86_64-apple-darwin
./configure --prefix=${CCTOOLS} --with-libtapi=${CCTOOLS} --target=x86_64-apple-darwin
make install
cd ..

cd cctools
cd ${CCTOOLS}
wget https://github.com/phracker/MacOSX-SDKs/releases/download/10.14-beta4/MacOSX10.14.sdk.tar.xz
tar xJf MacOSX10.14.sdk.tar.xz
```

Let's remember the path where we created `cctools` directory as ${CCTOOLS_PARENT}

# Build ClickHouse

```bash
cd ClickHouse
mkdir build-osx
CC=clang-8 CXX=clang++-8 cmake . -Bbuild-osx -DCMAKE_SYSTEM_NAME=Darwin \
-DCMAKE_AR:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ar \
-DCMAKE_RANLIB:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ranlib \
-DLINKER_NAME=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ld \
-DSDK_PATH=${CCTOOLS_PARENT}/cctools/MacOSX10.14.sdk \
-DUSE_SNAPPY=OFF -DENABLE_SSL=OFF -DENABLE_PROTOBUF=OFF -DENABLE_PARQUET=OFF -DENABLE_READLINE=OFF -DENABLE_ICU=OFF -DENABLE_FASTOPS=OFF
-DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar \
-DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib \
-DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld \
-DSDK_PATH=${CCTOOLS}/MacOSX10.14.sdk
ninja -C build-osx
```

Expand Down