Skip to content

Commit 819efc8

Browse files
authored
Merge pull request #281 from Jihadist/opt_deps
Add options to use system abseil, lz4 and cityhash
2 parents df4ae9f + a2c17ec commit 819efc8

40 files changed

+192
-68
lines changed

.github/workflows/linux.yml

+50-20
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,67 @@ env:
1414

1515
jobs:
1616
build:
17-
runs-on: ubuntu-20.04
1817
strategy:
18+
fail-fast: false
1919
matrix:
20-
compiler: [clang-6, gcc-7, gcc-8, gcc-9]
20+
os: [ubuntu-20.04]
21+
compiler: [clang-6, clang-10-libc++, gcc-7, gcc-8, gcc-9]
2122
ssl: [ssl_ON, ssl_OFF]
23+
dependencies: [dependencies_BUILT_IN]
24+
2225
include:
2326
- compiler: clang-6
24-
INSTALL: clang-6.0
27+
COMPILER_INSTALL: clang-6.0 libc++-dev
2528
C_COMPILER: clang-6.0
2629
CXX_COMPILER: clang++-6.0
2730

31+
- compiler: clang-10-libc++
32+
COMPILER_INSTALL: clang-10 libc++-dev
33+
C_COMPILER: clang-10
34+
CXX_COMPILER: clang++-10
35+
2836
- compiler: gcc-7
29-
INSTALL: gcc-7 g++-7
37+
COMPILER_INSTALL: gcc-7 g++-7
3038
C_COMPILER: gcc-7
3139
CXX_COMPILER: g++-7
3240

3341
- compiler: gcc-8
34-
INSTALL: gcc-8 g++-8
42+
COMPILER_INSTALL: gcc-8 g++-8
3543
C_COMPILER: gcc-8
3644
CXX_COMPILER: g++-8
3745

3846
- compiler: gcc-9
39-
INSTALL: gcc-9 g++-9
47+
COMPILER_INSTALL: gcc-9 g++-9
4048
C_COMPILER: gcc-9
4149
CXX_COMPILER: g++-9
4250

4351
- ssl: ssl_ON
44-
INSTALL_SSL: libssl-dev
45-
EXTRA_CMAKE_FLAGS: -DWITH_OPENSSL=ON
52+
SSL_CMAKE_OPTION: -D WITH_OPENSSL=ON
4653

47-
- ssl: ssl_OFF
48-
EXTRA_CMAKE_FLAGS: -DWITH_OPENSSL=OFF
54+
- dependencies: dependencies_SYSTEM
55+
compiler: compiler_SYSTEM
56+
os: ubuntu-22.04
57+
COMPILER_INSTALL: gcc g++
58+
C_COMPILER: gcc
59+
CXX_COMPILER: g++
60+
DEPENDENCIES_INSTALL: libabsl-dev liblz4-dev
61+
DEPENDENCIES_CMAKE_OPTIONS: >-
62+
-D WITH_SYSTEM_LZ4=ON
63+
-D WITH_SYSTEM_ABSEIL=ON
64+
65+
runs-on: ${{matrix.os}}
4966

5067
steps:
5168
- uses: actions/checkout@v2
5269

5370
- name: Install dependencies
54-
run: sudo apt-get install -y docker cmake ${{ matrix.INSTALL }} ${{ matrix.INSTALL_SSL }}
71+
run: |
72+
sudo apt-get update && \
73+
sudo apt-get install -y \
74+
docker \
75+
cmake \
76+
${{matrix.COMPILER_INSTALL}} \
77+
${{matrix.DEPENDENCIES_INSTALL}}
5578
5679
- name: Install dependencies - Docker
5780
run: |
@@ -62,17 +85,24 @@ jobs:
6285
sudo apt update -q
6386
sudo apt install docker-ce docker-ce-cli containerd.io
6487
65-
- name: Configure CMake
88+
- name: Configure project
89+
run: |
90+
cmake \
91+
-D CMAKE_C_COMPILER=${{matrix.C_COMPILER}} \
92+
-D CMAKE_CXX_COMPILER=${{matrix.CXX_COMPILER}} \
93+
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
94+
-D BUILD_TESTS=ON \
95+
${{matrix.SSL_CMAKE_OPTION}} \
96+
${{matrix.DEPENDENCIES_CMAKE_OPTIONS}} \
97+
-S ${{github.workspace}} \
98+
-B ${{github.workspace}}/build
99+
100+
- name: Build project
66101
run: |
67102
cmake \
68-
-DCMAKE_C_COMPILER=${{ matrix.C_COMPILER}} \
69-
-DCMAKE_CXX_COMPILER=${{ matrix.CXX_COMPILER}} \
70-
-B ${{github.workspace}}/build \
71-
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON \
72-
${{ matrix.EXTRA_CMAKE_FLAGS }}
73-
74-
- name: Build
75-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all
103+
--build ${{github.workspace}}/build \
104+
--config ${{env.BUILD_TYPE}} \
105+
--target all
76106
77107
- name: Test - Start ClickHouse server in background
78108
run: |

.github/workflows/macos.yml

+17-7
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,34 @@ jobs:
2323
build: [nossl, ssl]
2424
include:
2525
- build: nossl
26-
extra_cmake_flags: -DWITH_OPENSSL=OFF
27-
extra_install:
2826

2927
- build: ssl
30-
extra_cmake_flags: -DWITH_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/
31-
extra_install: openssl
28+
SSL_CMAKE_OPTION: >-
29+
-D WITH_OPENSSL=ON
30+
-D OPENSSL_ROOT_DIR=/usr/local/opt/openssl/
31+
SSL_INSTALL: openssl
3232

3333
steps:
3434
- uses: actions/checkout@v2
3535

3636
- name: Install dependencies
37-
run: brew install cmake ${{matrix.extra_install}}
37+
run: brew install cmake ${{matrix.SSL_INSTALL}}
3838

3939
- name: Configure CMake
40-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON ${{matrix.extra_cmake_flags}}
40+
run: |
41+
cmake \
42+
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
43+
-D BUILD_TESTS=ON \
44+
${{matrix.SSL_CMAKE_OPTION}} \
45+
-S ${{github.workspace}} \
46+
-B ${{github.workspace}}/build
4147
4248
- name: Build
43-
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all
49+
run: |
50+
cmake \
51+
--build ${{github.workspace}}/build \
52+
--config ${{env.BUILD_TYPE}} \
53+
--target all
4454
4555
- name: Start tls offoader proxy
4656
# that mimics non-secure clickhouse running on localhost

CMakeLists.txt

+52-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
CMAKE_MINIMUM_REQUIRED (VERSION 3.0.2)
22

3-
INCLUDE (cmake/cpp17.cmake)
4-
INCLUDE (cmake/subdirs.cmake)
5-
INCLUDE (cmake/openssl.cmake)
3+
LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4+
5+
INCLUDE (cpp17)
6+
INCLUDE (subdirs)
7+
INCLUDE (openssl)
68

79
OPTION (BUILD_BENCHMARK "Build benchmark" OFF)
810
OPTION (BUILD_TESTS "Build tests" OFF)
911
OPTION (BUILD_SHARED_LIBS "Build shared libs" OFF)
1012
OPTION (WITH_OPENSSL "Use OpenSSL for TLS connections" OFF)
13+
OPTION (WITH_SYSTEM_ABSEIL "Use system ABSEIL" OFF)
14+
OPTION (WITH_SYSTEM_LZ4 "Use system LZ4" OFF)
15+
OPTION (WITH_SYSTEM_CITYHASH "Use system cityhash" OFF)
1116

1217
PROJECT (CLICKHOUSE-CLIENT)
1318

@@ -34,11 +39,52 @@ PROJECT (CLICKHOUSE-CLIENT)
3439
ENDIF()
3540
ENDIF()
3641

42+
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
43+
INCLUDE (CheckCXXSourceCompiles)
44+
45+
CHECK_CXX_SOURCE_COMPILES("#include <bits/c++config.h>\nint main() { return __GLIBCXX__ != 0; }"
46+
CLANG_WITH_LIB_STDCXX)
47+
ENDIF ()
48+
49+
IF (CLANG_WITH_LIB_STDCXX)
50+
# there is a problem with __builtin_mul_overflow call at link time
51+
# the error looks like: ... undefined reference to `__muloti4' ...
52+
# caused by clang bug https://bugs.llvm.org/show_bug.cgi?id=16404
53+
# explicit linking to compiler-rt allows to workaround the problem
54+
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt")
55+
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt")
56+
57+
# some workaround for linking issues on linux:
58+
# /usr/bin/ld: CMakeFiles/simple-test.dir/main.cpp.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
59+
# /usr/bin/ld: /lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
60+
# FIXME: that workaround breaks clang build on mingw
61+
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lgcc_s")
62+
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcc_s")
63+
ENDIF ()
64+
65+
IF (WITH_SYSTEM_ABSEIL)
66+
FIND_PACKAGE(absl REQUIRED)
67+
ELSE ()
68+
INCLUDE_DIRECTORIES (contrib/absl)
69+
SUBDIRS (contrib/absl/absl)
70+
ENDIF ()
71+
72+
IF (WITH_SYSTEM_LZ4)
73+
FIND_PACKAGE(lz4 REQUIRED)
74+
ELSE ()
75+
INCLUDE_DIRECTORIES (contrib/lz4/lz4)
76+
SUBDIRS (contrib/lz4/lz4)
77+
ENDIF ()
78+
79+
IF (WITH_SYSTEM_CITYHASH)
80+
FIND_PACKAGE(cityhash REQUIRED)
81+
ELSE ()
82+
INCLUDE_DIRECTORIES (contrib/cityhash/cityhash)
83+
SUBDIRS (contrib/cityhash/cityhash)
84+
ENDIF ()
85+
3786
SUBDIRS (
3887
clickhouse
39-
contrib/absl
40-
contrib/cityhash
41-
contrib/lz4
4288
)
4389

4490
IF (BUILD_BENCHMARK)

clickhouse/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ ENDIF ()
4141
ADD_LIBRARY (clickhouse-cpp-lib ${clickhouse-cpp-lib-src})
4242
SET_TARGET_PROPERTIES (clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX)
4343
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib
44-
absl-lib
45-
cityhash-lib
46-
lz4-lib
44+
absl::int128
45+
cityhash::cityhash
46+
lz4::lz4
4747
)
4848
TARGET_INCLUDE_DIRECTORIES (clickhouse-cpp-lib
4949
PUBLIC ${PROJECT_SOURCE_DIR}

clickhouse/base/compressed.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include "output.h"
44
#include "../exceptions.h"
55

6-
#include <cityhash/city.h>
7-
#include <lz4/lz4.h>
6+
#include <city.h>
7+
#include <lz4.h>
88
#include <stdexcept>
99
#include <system_error>
1010

clickhouse/columns/lowcardinality.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "nullable.h"
55
#include "../base/wire_format.h"
66

7-
#include <cityhash/city.h>
7+
#include <city.h>
88

99
#include <functional>
1010
#include <string_view>

clickhouse/types/types.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../exceptions.h"
44

5-
#include <cityhash/city.h>
5+
#include <city.h>
66

77
#include <stdexcept>
88

cmake/Findlz4.cmake

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
find_path(lz4_INCLUDE_DIR
2+
NAMES lz4.h
3+
DOC "lz4 include directory")
4+
mark_as_advanced(lz4_INCLUDE_DIR)
5+
find_library(lz4_LIBRARY
6+
NAMES lz4 liblz4
7+
DOC "lz4 library")
8+
mark_as_advanced(lz4_LIBRARY)
9+
10+
if (lz4_INCLUDE_DIR)
11+
file(STRINGS "${lz4_INCLUDE_DIR}/lz4.h" _lz4_version_lines
12+
REGEX "#define[ \t]+LZ4_VERSION_(MAJOR|MINOR|RELEASE)")
13+
string(REGEX REPLACE ".*LZ4_VERSION_MAJOR *\([0-9]*\).*" "\\1" _lz4_version_major "${_lz4_version_lines}")
14+
string(REGEX REPLACE ".*LZ4_VERSION_MINOR *\([0-9]*\).*" "\\1" _lz4_version_minor "${_lz4_version_lines}")
15+
string(REGEX REPLACE ".*LZ4_VERSION_RELEASE *\([0-9]*\).*" "\\1" _lz4_version_release "${_lz4_version_lines}")
16+
set(lz4_VERSION "${_lz4_version_major}.${_lz4_version_minor}.${_lz4_version_release}")
17+
unset(_lz4_version_major)
18+
unset(_lz4_version_minor)
19+
unset(_lz4_version_release)
20+
unset(_lz4_version_lines)
21+
endif ()
22+
23+
include(FindPackageHandleStandardArgs)
24+
find_package_handle_standard_args(lz4
25+
REQUIRED_VARS lz4_LIBRARY lz4_INCLUDE_DIR
26+
VERSION_VAR lz4_VERSION)
27+
28+
if (lz4_FOUND)
29+
set(lz4_INCLUDE_DIRS "${lz4_INCLUDE_DIR}")
30+
set(lz4_LIBRARIES "${lz4_LIBRARY}")
31+
32+
if (NOT TARGET lz4::lz4)
33+
add_library(lz4::lz4 UNKNOWN IMPORTED)
34+
set_target_properties(lz4::lz4 PROPERTIES
35+
IMPORTED_LOCATION "${lz4_LIBRARY}"
36+
INTERFACE_INCLUDE_DIRECTORIES "${lz4_INCLUDE_DIR}")
37+
endif ()
38+
endif ()

contrib/absl/CMakeLists.txt

-6
This file was deleted.

contrib/absl/absl/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ADD_LIBRARY (absl_int128 STATIC
2+
numeric/int128.cc
3+
)
4+
5+
TARGET_INCLUDE_DIRECTORIES (absl_int128
6+
PUBLIC ${PROJECT_SOURCE_DIR}/contrib/absl
7+
)
8+
9+
ADD_LIBRARY (absl::int128 ALIAS absl_int128)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

contrib/cityhash/CMakeLists.txt

-5
This file was deleted.
File renamed without changes.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ADD_LIBRARY (cityhash STATIC
2+
city.cc
3+
)
4+
5+
set_property(TARGET cityhash PROPERTY POSITION_INDEPENDENT_CODE ON)
6+
7+
ADD_LIBRARY (cityhash::cityhash ALIAS cityhash)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

contrib/lz4/CMakeLists.txt

-6
This file was deleted.
File renamed without changes.

contrib/lz4/lz4/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ADD_LIBRARY (lz4 STATIC
2+
lz4.c
3+
lz4hc.c
4+
)
5+
6+
set_property(TARGET lz4 PROPERTY POSITION_INDEPENDENT_CODE ON)
7+
8+
ADD_LIBRARY(lz4::lz4 ALIAS lz4)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/simple/CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,3 @@ ADD_EXECUTABLE (simple-test
66
TARGET_LINK_LIBRARIES (simple-test
77
clickhouse-cpp-lib
88
)
9-
10-
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
11-
# there is a problem with __builtin_mul_overflow call at link time
12-
# the error looks like: ... undefined reference to `__muloti4' ...
13-
# caused by clang bug https://bugs.llvm.org/show_bug.cgi?id=16404
14-
# explicit linking to compiler-rt allows to workaround the problem
15-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt")
16-
ENDIF ()

ut/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-ut
3939
clickhouse-cpp-lib
4040
gtest-lib
4141
)
42-
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
43-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --rtlib=compiler-rt")
44-
ENDIF ()
42+
43+
IF (MSVC)
44+
TARGET_COMPILE_OPTIONS(clickhouse-cpp-ut PRIVATE /bigobj)
45+
ENDIF()

0 commit comments

Comments
 (0)