From 7620c28c145ddc1d5597306b2bf63db8b542c8b2 Mon Sep 17 00:00:00 2001 From: bharatnc Date: Thu, 17 Jun 2021 01:31:37 -0700 Subject: [PATCH] LZ4 - fix cmake to include lz4 --- CMakeLists.txt | 1 + cmake/find/lz4.cmake | 27 +++++++++++++++++++++++++++ contrib/lz4-cmake/CMakeLists.txt | 9 ++++++++- src/CMakeLists.txt | 5 +++++ src/IO/Lz4DeflatingWriteBuffer.h | 1 + src/IO/Lz4InflatingReadBuffer.h | 2 ++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 cmake/find/lz4.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d23e5f540d3..ba705d527f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -540,6 +540,7 @@ include (cmake/find/rocksdb.cmake) include (cmake/find/libpqxx.cmake) include (cmake/find/nuraft.cmake) include (cmake/find/yaml-cpp.cmake) +include (cmake/find/lz4.cmake) if(NOT USE_INTERNAL_PARQUET_LIBRARY) set (ENABLE_ORC OFF CACHE INTERNAL "") diff --git a/cmake/find/lz4.cmake b/cmake/find/lz4.cmake new file mode 100644 index 00000000000..33e91d11ede --- /dev/null +++ b/cmake/find/lz4.cmake @@ -0,0 +1,27 @@ +option (USE_LZ4 "Set to FALSE to use system lz4 library instead of bundled" ${NOT_UNBUNDLED}) + +if(NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/lz4/lib/lz4.h") + if(USE_LZ4) + message(WARNING "submodule contrib/lz4 is missing. to fix try run: \n git submodule update --init --recursive") + message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find internal lz4 library") + set(USE_LZ4 0) + endif() + set(MISSING_INTERNAL_LZ4_LIBRARY 1) +endif() + +if (NOT USE_LZ4) + find_library (LZ4_LIBRARY lz4) + find_path (LZ4_INCLUDE_DIR NAMES lz4.h PATHS ${LZ4_INCLUDE_PATHS}) + if (NOT LZ4_LIBRARY OR NOT LZ4_INCLUDE_DIR) + message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system lz4 library") + endif () +endif () + +if (LZ4_LIBRARY AND LZ4_INCLUDE_DIR) +elseif (NOT MISSING_INTERNAL_LZ4_LIBRARY) + set (USE_LZ4 1) + set (LZ4_LIBRARY lz4) + set (LZ4_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/lz4/lib) +endif () + +message (STATUS "Using lz4: ${LZ4_INCLUDE_DIR} : ${LZ4_LIBRARY}") diff --git a/contrib/lz4-cmake/CMakeLists.txt b/contrib/lz4-cmake/CMakeLists.txt index 77e00d4295b..5980d4f019a 100644 --- a/contrib/lz4-cmake/CMakeLists.txt +++ b/contrib/lz4-cmake/CMakeLists.txt @@ -27,7 +27,14 @@ if (NOT EXTERNAL_LZ4_LIBRARY_FOUND) "${LIBRARY_DIR}/lib/xxhash.c" ) - add_library (lz4 ${SRCS}) + set (HEADERS + "${LIBRARY_DIR}/lib/lz4.h" + "${LIBRARY_DIR}/lib/lz4hc.h" + "${LIBRARY_DIR}/lib/lz4frame.h" + "${LIBRARY_DIR}/lib/xxhash.h" + ) + + add_library (lz4 ${SRCS} ${HEADERS}) target_compile_definitions (lz4 PUBLIC LZ4_DISABLE_DEPRECATE_WARNINGS=1 USE_XXHASH=1) if (SANITIZE STREQUAL "undefined") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 272bea4f6d7..e3ccb448368 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -458,6 +458,11 @@ if (USE_DATASKETCHES) target_include_directories (clickhouse_aggregate_functions SYSTEM BEFORE PRIVATE ${DATASKETCHES_INCLUDE_DIR}) endif () +if (USE_LZ4) + target_link_libraries (clickhouse_common_io PRIVATE ${LZ4_LIBRARY}) + target_include_directories (clickhouse_common_io SYSTEM BEFORE PRIVATE ${LZ4_INCLUDE_DIR}) +endif() + dbms_target_link_libraries(PRIVATE _boost_context) include ("${ClickHouse_SOURCE_DIR}/cmake/add_check.cmake") diff --git a/src/IO/Lz4DeflatingWriteBuffer.h b/src/IO/Lz4DeflatingWriteBuffer.h index 7ae8b2addb4..ba0e2fb6e82 100644 --- a/src/IO/Lz4DeflatingWriteBuffer.h +++ b/src/IO/Lz4DeflatingWriteBuffer.h @@ -4,6 +4,7 @@ #include #include +#include namespace DB { diff --git a/src/IO/Lz4InflatingReadBuffer.h b/src/IO/Lz4InflatingReadBuffer.h index 9bc03126f9d..e87dcb740eb 100644 --- a/src/IO/Lz4InflatingReadBuffer.h +++ b/src/IO/Lz4InflatingReadBuffer.h @@ -4,6 +4,8 @@ #include #include +#include + namespace DB {