diff --git a/CMakeLists.txt b/CMakeLists.txt index dd602fdacff..12cdb8363d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,10 +187,17 @@ else() endif() if(WITH_ZSTD) - find_package(zstd REQUIRED) + find_package(zstd CONFIG) + if(zstd_DIR) + # Extract include dirs, because some targets (testutillib) use zstd headers without linking to zstd. + get_target_property(ZSTD_INCLUDE_DIRS zstd::libzstd INTERFACE_INCLUDE_DIRECTORIES) + list(APPEND THIRDPARTY_LIBS zstd::libzstd) + else() + find_package(zstd REQUIRED) + list(APPEND THIRDPARTY_LIBS zstd::zstd) + endif() add_definitions(-DZSTD) include_directories(${ZSTD_INCLUDE_DIRS}) - list(APPEND THIRDPARTY_LIBS zstd::zstd) endif() endif() diff --git a/build_tools/format-diff.sh b/build_tools/format-diff.sh index aa6b634563d..fb9cb9b847b 100755 --- a/build_tools/format-diff.sh +++ b/build_tools/format-diff.sh @@ -119,7 +119,9 @@ fi set -e # Exclude third-party from formatting -EXCLUDE=':!third-party/' +# Exclude thirdparty.inc as it is a cmake file. +EXCLUDE="':!third-party/' ':!thirdparty.inc'" + uncommitted_code=`git diff HEAD` diff --git a/thirdparty.inc b/thirdparty.inc index 25ecdab88c2..d0b73111db0 100644 --- a/thirdparty.inc +++ b/thirdparty.inc @@ -215,10 +215,19 @@ if (WITH_ZSTD) set(ZSTD_LIB_RELEASE $ENV{ZSTD_LIB_RELEASE}) endif() + if(ZSTD_INCLUDE AND EXISTS "${ZSTD_INCLUDE}") + set(ZSTD_LIBS debug ${ZSTD_LIB_DEBUG} optimized ${ZSTD_LIB_RELEASE}) + else() + # No explicit paths provided - try to find config package. + find_package(zstd CONFIG REQUIRED) + message(STATUS "zstd: found config at '${zstd_DIR}'.") + set(ZSTD_LIBS zstd::libzstd_static) + # Extract include dirs, because some targets (testutillib) use zstd headers without linking to zstd. + get_target_property(ZSTD_INCLUDE zstd::libzstd_static INTERFACE_INCLUDE_DIRECTORIES) + endif() + # ZSTD_STATIC_LINKING_ONLY only allows us to create an allocation functions override # When jemalloc is in use - set(ZSTD_LIBS debug ${ZSTD_LIB_DEBUG} optimized ${ZSTD_LIB_RELEASE}) - add_definitions(-DZSTD -DZSTD_STATIC_LINKING_ONLY) include_directories(${ZSTD_INCLUDE}) set (THIRDPARTY_LIBS ${THIRDPARTY_LIBS} ${ZSTD_LIBS})