From bceea9b25450ec33ddde377a3d1edd4f35d3b5b7 Mon Sep 17 00:00:00 2001 From: David Keller Date: Tue, 5 Apr 2022 11:51:13 +0200 Subject: [PATCH] Add options to use system abseil, lz4 and cityhash This change solves #86, #99. Furthermore, it eases Conan packaging, as Conan already provides abseil, lz4 and cityhash. Signed-off-by: David Keller --- .github/workflows/linux.yml | 17 ++++++++--- .github/workflows/macos.yml | 25 +++++++++++++---- CMakeLists.txt | 28 ++++++++++++++++--- clickhouse/CMakeLists.txt | 12 ++++---- clickhouse/base/compressed.cpp | 4 +-- clickhouse/columns/lowcardinality.cpp | 2 +- clickhouse/types/types.cpp | 2 +- contrib/absl/CMakeLists.txt | 3 -- contrib/absl/absl/CMakeLists.txt | 5 ++++ contrib/absl/{ => absl}/base/attributes.h | 0 contrib/absl/{ => absl}/base/config.h | 0 contrib/absl/{ => absl}/base/internal/bits.h | 0 contrib/absl/{ => absl}/base/macros.h | 0 contrib/absl/{ => absl}/base/optimization.h | 0 contrib/absl/{ => absl}/base/options.h | 0 contrib/absl/{ => absl}/base/policy_checks.h | 0 contrib/absl/{ => absl}/base/port.h | 0 contrib/absl/{ => absl}/numeric/int128.cc | 0 contrib/absl/{ => absl}/numeric/int128.h | 0 .../numeric/int128_have_intrinsic.inc | 0 .../numeric/int128_no_intrinsic.inc | 0 contrib/cityhash/CMakeLists.txt | 5 ---- contrib/cityhash/{ => cityhash}/BUCK | 0 contrib/cityhash/cityhash/CMakeLists.txt | 7 +++++ contrib/cityhash/{ => cityhash}/COPYING | 0 contrib/cityhash/{ => cityhash}/city.cc | 0 contrib/cityhash/{ => cityhash}/city.h | 0 contrib/cityhash/{ => cityhash}/citycrc.h | 0 contrib/cityhash/{ => cityhash}/config.h | 0 contrib/lz4/CMakeLists.txt | 6 ---- contrib/lz4/{ => lz4}/BUCK | 0 contrib/lz4/lz4/CMakeLists.txt | 8 ++++++ contrib/lz4/{ => lz4}/LICENSE | 0 contrib/lz4/{ => lz4}/lz4.c | 0 contrib/lz4/{ => lz4}/lz4.h | 0 contrib/lz4/{ => lz4}/lz4hc.c | 0 contrib/lz4/{ => lz4}/lz4hc.h | 0 37 files changed, 86 insertions(+), 38 deletions(-) delete mode 100644 contrib/absl/CMakeLists.txt create mode 100644 contrib/absl/absl/CMakeLists.txt rename contrib/absl/{ => absl}/base/attributes.h (100%) rename contrib/absl/{ => absl}/base/config.h (100%) rename contrib/absl/{ => absl}/base/internal/bits.h (100%) rename contrib/absl/{ => absl}/base/macros.h (100%) rename contrib/absl/{ => absl}/base/optimization.h (100%) rename contrib/absl/{ => absl}/base/options.h (100%) rename contrib/absl/{ => absl}/base/policy_checks.h (100%) rename contrib/absl/{ => absl}/base/port.h (100%) rename contrib/absl/{ => absl}/numeric/int128.cc (100%) rename contrib/absl/{ => absl}/numeric/int128.h (100%) rename contrib/absl/{ => absl}/numeric/int128_have_intrinsic.inc (100%) rename contrib/absl/{ => absl}/numeric/int128_no_intrinsic.inc (100%) delete mode 100644 contrib/cityhash/CMakeLists.txt rename contrib/cityhash/{ => cityhash}/BUCK (100%) create mode 100644 contrib/cityhash/cityhash/CMakeLists.txt rename contrib/cityhash/{ => cityhash}/COPYING (100%) rename contrib/cityhash/{ => cityhash}/city.cc (100%) rename contrib/cityhash/{ => cityhash}/city.h (100%) rename contrib/cityhash/{ => cityhash}/citycrc.h (100%) rename contrib/cityhash/{ => cityhash}/config.h (100%) delete mode 100644 contrib/lz4/CMakeLists.txt rename contrib/lz4/{ => lz4}/BUCK (100%) create mode 100644 contrib/lz4/lz4/CMakeLists.txt rename contrib/lz4/{ => lz4}/LICENSE (100%) rename contrib/lz4/{ => lz4}/lz4.c (100%) rename contrib/lz4/{ => lz4}/lz4.h (100%) rename contrib/lz4/{ => lz4}/lz4hc.c (100%) rename contrib/lz4/{ => lz4}/lz4hc.h (100%) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index e64b8406..7e26d338 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -16,6 +16,7 @@ jobs: matrix: compiler: [clang-6, gcc-7, gcc-8, gcc-9] ssl: [ssl_ON, ssl_OFF] + dependencies: [dependencies_SYSTEM, dependencies_BUILT_IN] include: - compiler: clang-6 INSTALL: clang-6.0 @@ -39,16 +40,23 @@ jobs: - ssl: ssl_ON INSTALL_SSL: libssl-dev - EXTRA_CMAKE_FLAGS: -DWITH_OPENSSL=ON + OPENSSL_CMAKE_OPTION: -DWITH_OPENSSL=ON - ssl: ssl_OFF - EXTRA_CMAKE_FLAGS: -DWITH_OPENSSL=OFF + OPENSSL_CMAKE_OPTION: -DWITH_OPENSSL=OFF + + - dependencies: dependencies_SYSTEM + DEPENDENCIES_CMAKE_OPTIONS: -DWITH_SYSTEM_ABSEIL=ON -DWITH_SYSTEM_LZ4=ON -DWITH_SYSTEM_CITYHASH=ON + INSTALL_DEPENDENCIES: libabsl-dev liblz4-dev libcityhash-dev + + - dependencies: dependencies_BUILT_IN + DEPENDENCIES_CMAKE_OPTIONS: -DWITH_SYSTEM_ABSEIL=OFF -DWITH_SYSTEM_LZ4=OFF -DWITH_SYSTEM_CITYHASH=OFF steps: - uses: actions/checkout@v2 - name: Install dependencies - run: sudo apt-get install -y cmake ${{ matrix.INSTALL }} ${{ matrix.INSTALL_SSL }} + run: sudo apt-get install -y cmake ${{ matrix.INSTALL }} ${{ matrix.INSTALL_SSL }} ${{ matrix.INSTALL_DEPENDENCIES }} - name: Configure CMake run: | @@ -57,7 +65,8 @@ jobs: -DCMAKE_CXX_COMPILER=${{ matrix.CXX_COMPILER}} \ -B ${{github.workspace}}/build \ -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON \ - ${{ matrix.EXTRA_CMAKE_FLAGS }} + ${{ matrix.OPENSSL_CMAKE_OPTION}} \ + ${{ matrix.DEPENDENCIES_CMAKE_OPTIONS }} - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a2bb171f..5dfb3e77 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -19,23 +19,36 @@ jobs: fail-fast: false matrix: build: [nossl, ssl] + dependencies: [dependencies_SYSTEM, dependencies_BUILT_IN] include: - build: nossl - extra_cmake_flags: -DWITH_OPENSSL=OFF - extra_install: + openssl_cmake_option: -DWITH_OPENSSL=OFF - build: ssl - extra_cmake_flags: -DWITH_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ - extra_install: openssl + openssl_cmake_option: -DWITH_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ + openssl_install: openssl + + - dependencies: dependencies_SYSTEM + dependencies_cmake_options: -DWITH_SYSTEM_ABSEIL=ON -DWITH_SYSTEM_LZ4=ON -DWITH_SYSTEM_CITYHASH=ON + dependencies_install: abseil lz4 cityhash + + - dependencies: dependencies_BUILT_IN + dependencies_cmake_options: -DWITH_SYSTEM_ABSEIL=OFF -DWITH_SYSTEM_LZ4=OFF -DWITH_SYSTEM_CITYHASH=OFF + steps: - uses: actions/checkout@v2 - name: Install dependencies - run: brew install cmake ${{matrix.extra_install}} + run: brew install cmake ${{matrix.openssl_install}} ${{matrix.dependencies_install}} - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON ${{matrix.extra_cmake_flags}} + run: cmake \ + -B ${{github.workspace}}/build \ + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ + -DBUILD_TESTS=ON \ + ${{matrix.openssl_cmake_option}} \ + ${{matrix.dependencies_cmake_options}} - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target all diff --git a/CMakeLists.txt b/CMakeLists.txt index 31cd8a5a..fe721ae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ INCLUDE (cmake/openssl.cmake) OPTION (BUILD_BENCHMARK "Build benchmark" OFF) OPTION (BUILD_TESTS "Build tests" OFF) OPTION (WITH_OPENSSL "Use OpenSSL for TLS connections" OFF) +OPTION (USE_SYSTEM_ABSEIL "Use system ABSEIL" OFF) +OPTION (USE_SYSTEM_LZ4 "Use system LZ4" OFF) +OPTION (USE_SYSTEM_CITYHASH "Use system cityhash" OFF) PROJECT (CLICKHOUSE-CLIENT) @@ -27,13 +30,30 @@ PROJECT (CLICKHOUSE-CLIENT) ENDIF () INCLUDE_DIRECTORIES (.) - INCLUDE_DIRECTORIES (contrib) + + IF (USE_SYSTEM_ABSEIL) + FIND_PACKAGE(absl REQUIRED) + ELSE () + INCLUDE_DIRECTORIES (contrib/absl) + SUBDIRS (contrib/absl/absl) + ENDIF () + + IF (USE_SYSTEM_LZ4) + FIND_PACKAGE(lz4 REQUIRED) + ELSE () + INCLUDE_DIRECTORIES (contrib/lz4/lz4) + SUBDIRS (contrib/lz4/lz4) + ENDIF () + + IF (USE_SYSTEM_CITYHASH) + FIND_PACKAGE(cityhash REQUIRED) + ELSE () + INCLUDE_DIRECTORIES (contrib/cityhash/cityhash) + SUBDIRS (contrib/cityhash/cityhash) + ENDIF () SUBDIRS ( clickhouse - contrib/absl - contrib/cityhash - contrib/lz4 ) IF (BUILD_BENCHMARK) diff --git a/clickhouse/CMakeLists.txt b/clickhouse/CMakeLists.txt index e2afb3ae..f1c7154f 100644 --- a/clickhouse/CMakeLists.txt +++ b/clickhouse/CMakeLists.txt @@ -38,16 +38,16 @@ ENDIF () ADD_LIBRARY (clickhouse-cpp-lib SHARED ${clickhouse-cpp-lib-src}) SET_TARGET_PROPERTIES(clickhouse-cpp-lib PROPERTIES LINKER_LANGUAGE CXX) TARGET_LINK_LIBRARIES (clickhouse-cpp-lib - absl-lib - cityhash-lib - lz4-lib + absl::absl + cityhash::cityhash + lz4::lz4 ) ADD_LIBRARY (clickhouse-cpp-lib-static STATIC ${clickhouse-cpp-lib-src}) TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static - absl-lib - cityhash-lib - lz4-lib + absl::absl + cityhash::cityhash + lz4::lz4 ) IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/clickhouse/base/compressed.cpp b/clickhouse/base/compressed.cpp index baf0ffed..0a701b0d 100644 --- a/clickhouse/base/compressed.cpp +++ b/clickhouse/base/compressed.cpp @@ -3,8 +3,8 @@ #include "output.h" #include "../exceptions.h" -#include -#include +#include +#include #include #include diff --git a/clickhouse/columns/lowcardinality.cpp b/clickhouse/columns/lowcardinality.cpp index 694e3eda..1b5bc937 100644 --- a/clickhouse/columns/lowcardinality.cpp +++ b/clickhouse/columns/lowcardinality.cpp @@ -4,7 +4,7 @@ #include "nullable.h" #include "../base/wire_format.h" -#include +#include #include #include diff --git a/clickhouse/types/types.cpp b/clickhouse/types/types.cpp index 8dc6688b..9649bd1f 100644 --- a/clickhouse/types/types.cpp +++ b/clickhouse/types/types.cpp @@ -2,7 +2,7 @@ #include "../exceptions.h" -#include +#include #include diff --git a/contrib/absl/CMakeLists.txt b/contrib/absl/CMakeLists.txt deleted file mode 100644 index 87c8dff1..00000000 --- a/contrib/absl/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -ADD_LIBRARY (absl-lib STATIC - numeric/int128.cc -) diff --git a/contrib/absl/absl/CMakeLists.txt b/contrib/absl/absl/CMakeLists.txt new file mode 100644 index 00000000..eaec8673 --- /dev/null +++ b/contrib/absl/absl/CMakeLists.txt @@ -0,0 +1,5 @@ +ADD_LIBRARY (absl STATIC + numeric/int128.cc +) + +ADD_LIBRARY (absl::absl ALIAS absl) diff --git a/contrib/absl/base/attributes.h b/contrib/absl/absl/base/attributes.h similarity index 100% rename from contrib/absl/base/attributes.h rename to contrib/absl/absl/base/attributes.h diff --git a/contrib/absl/base/config.h b/contrib/absl/absl/base/config.h similarity index 100% rename from contrib/absl/base/config.h rename to contrib/absl/absl/base/config.h diff --git a/contrib/absl/base/internal/bits.h b/contrib/absl/absl/base/internal/bits.h similarity index 100% rename from contrib/absl/base/internal/bits.h rename to contrib/absl/absl/base/internal/bits.h diff --git a/contrib/absl/base/macros.h b/contrib/absl/absl/base/macros.h similarity index 100% rename from contrib/absl/base/macros.h rename to contrib/absl/absl/base/macros.h diff --git a/contrib/absl/base/optimization.h b/contrib/absl/absl/base/optimization.h similarity index 100% rename from contrib/absl/base/optimization.h rename to contrib/absl/absl/base/optimization.h diff --git a/contrib/absl/base/options.h b/contrib/absl/absl/base/options.h similarity index 100% rename from contrib/absl/base/options.h rename to contrib/absl/absl/base/options.h diff --git a/contrib/absl/base/policy_checks.h b/contrib/absl/absl/base/policy_checks.h similarity index 100% rename from contrib/absl/base/policy_checks.h rename to contrib/absl/absl/base/policy_checks.h diff --git a/contrib/absl/base/port.h b/contrib/absl/absl/base/port.h similarity index 100% rename from contrib/absl/base/port.h rename to contrib/absl/absl/base/port.h diff --git a/contrib/absl/numeric/int128.cc b/contrib/absl/absl/numeric/int128.cc similarity index 100% rename from contrib/absl/numeric/int128.cc rename to contrib/absl/absl/numeric/int128.cc diff --git a/contrib/absl/numeric/int128.h b/contrib/absl/absl/numeric/int128.h similarity index 100% rename from contrib/absl/numeric/int128.h rename to contrib/absl/absl/numeric/int128.h diff --git a/contrib/absl/numeric/int128_have_intrinsic.inc b/contrib/absl/absl/numeric/int128_have_intrinsic.inc similarity index 100% rename from contrib/absl/numeric/int128_have_intrinsic.inc rename to contrib/absl/absl/numeric/int128_have_intrinsic.inc diff --git a/contrib/absl/numeric/int128_no_intrinsic.inc b/contrib/absl/absl/numeric/int128_no_intrinsic.inc similarity index 100% rename from contrib/absl/numeric/int128_no_intrinsic.inc rename to contrib/absl/absl/numeric/int128_no_intrinsic.inc diff --git a/contrib/cityhash/CMakeLists.txt b/contrib/cityhash/CMakeLists.txt deleted file mode 100644 index e31bc245..00000000 --- a/contrib/cityhash/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -ADD_LIBRARY (cityhash-lib STATIC - city.cc -) - -set_property(TARGET cityhash-lib PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/contrib/cityhash/BUCK b/contrib/cityhash/cityhash/BUCK similarity index 100% rename from contrib/cityhash/BUCK rename to contrib/cityhash/cityhash/BUCK diff --git a/contrib/cityhash/cityhash/CMakeLists.txt b/contrib/cityhash/cityhash/CMakeLists.txt new file mode 100644 index 00000000..d1311562 --- /dev/null +++ b/contrib/cityhash/cityhash/CMakeLists.txt @@ -0,0 +1,7 @@ +ADD_LIBRARY (cityhash STATIC + city.cc +) + +set_property(TARGET cityhash PROPERTY POSITION_INDEPENDENT_CODE ON) + +ADD_LIBRARY (cityhash::cityhash ALIAS cityhash) diff --git a/contrib/cityhash/COPYING b/contrib/cityhash/cityhash/COPYING similarity index 100% rename from contrib/cityhash/COPYING rename to contrib/cityhash/cityhash/COPYING diff --git a/contrib/cityhash/city.cc b/contrib/cityhash/cityhash/city.cc similarity index 100% rename from contrib/cityhash/city.cc rename to contrib/cityhash/cityhash/city.cc diff --git a/contrib/cityhash/city.h b/contrib/cityhash/cityhash/city.h similarity index 100% rename from contrib/cityhash/city.h rename to contrib/cityhash/cityhash/city.h diff --git a/contrib/cityhash/citycrc.h b/contrib/cityhash/cityhash/citycrc.h similarity index 100% rename from contrib/cityhash/citycrc.h rename to contrib/cityhash/cityhash/citycrc.h diff --git a/contrib/cityhash/config.h b/contrib/cityhash/cityhash/config.h similarity index 100% rename from contrib/cityhash/config.h rename to contrib/cityhash/cityhash/config.h diff --git a/contrib/lz4/CMakeLists.txt b/contrib/lz4/CMakeLists.txt deleted file mode 100644 index 7b471da3..00000000 --- a/contrib/lz4/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -ADD_LIBRARY (lz4-lib STATIC - lz4.c - lz4hc.c -) - -set_property(TARGET lz4-lib PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/contrib/lz4/BUCK b/contrib/lz4/lz4/BUCK similarity index 100% rename from contrib/lz4/BUCK rename to contrib/lz4/lz4/BUCK diff --git a/contrib/lz4/lz4/CMakeLists.txt b/contrib/lz4/lz4/CMakeLists.txt new file mode 100644 index 00000000..1ec7fb07 --- /dev/null +++ b/contrib/lz4/lz4/CMakeLists.txt @@ -0,0 +1,8 @@ +ADD_LIBRARY (lz4 STATIC + lz4.c + lz4hc.c +) + +set_property(TARGET lz4 PROPERTY POSITION_INDEPENDENT_CODE ON) + +ADD_LIBRARY(lz4::lz4 ALIAS lz4) diff --git a/contrib/lz4/LICENSE b/contrib/lz4/lz4/LICENSE similarity index 100% rename from contrib/lz4/LICENSE rename to contrib/lz4/lz4/LICENSE diff --git a/contrib/lz4/lz4.c b/contrib/lz4/lz4/lz4.c similarity index 100% rename from contrib/lz4/lz4.c rename to contrib/lz4/lz4/lz4.c diff --git a/contrib/lz4/lz4.h b/contrib/lz4/lz4/lz4.h similarity index 100% rename from contrib/lz4/lz4.h rename to contrib/lz4/lz4/lz4.h diff --git a/contrib/lz4/lz4hc.c b/contrib/lz4/lz4/lz4hc.c similarity index 100% rename from contrib/lz4/lz4hc.c rename to contrib/lz4/lz4/lz4hc.c diff --git a/contrib/lz4/lz4hc.h b/contrib/lz4/lz4/lz4hc.h similarity index 100% rename from contrib/lz4/lz4hc.h rename to contrib/lz4/lz4/lz4hc.h