From 2f5e7ac51e13dd25b1ea4f40bcead3c90c03daa5 Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Wed, 20 Dec 2017 12:49:34 +0300 Subject: [PATCH] Carefully detect snappy version for cbc-version Some snappy builds might not include version information into snappy-stubs-public.h, display version from pkg-config in this case Change-Id: I6c07d7ba98c98af8d7ac0264a6b775edc65355c4 --- cmake/Modules/FindCouchbaseSnappy.cmake | 15 +++++++++++---- cmake/config-cmake.h.in | 1 + tools/cbc.cc | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmake/Modules/FindCouchbaseSnappy.cmake b/cmake/Modules/FindCouchbaseSnappy.cmake index d8cb3601..98c4a2cb 100644 --- a/cmake/Modules/FindCouchbaseSnappy.cmake +++ b/cmake/Modules/FindCouchbaseSnappy.cmake @@ -1,11 +1,18 @@ -FIND_PATH(SNAPPY_INCLUDES snappy-c.h +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(SNAPPY snappy) +IF(SNAPPY_FOUND) + SET(SNAPPY_INCLUDES ${SNAPPY_INCLUDE_DIRS}) + SET(LCB_SNAPPY_PKG_VERSION ${SNAPPY_VERSION}) +ELSE() + FIND_PATH(SNAPPY_INCLUDES snappy-c.h HINTS ENV SNAPPY_DIR ${SNAPPY_DIR} PATH_SUFFIXES include) -FIND_LIBRARY(SNAPPY_LIBRARIES NAMES snappy + FIND_LIBRARY(SNAPPY_LIBRARIES NAMES snappy HINTS ENV SNAPPY_DIR ${SNAPPY_DIR} PATH_SUFFIXES lib) -IF(SNAPPY_LIBRARIES AND SNAPPY_INCLUDES) + IF(SNAPPY_LIBRARIES AND SNAPPY_INCLUDES) SET(SNAPPY_FOUND TRUE) -ELSE() + ELSE() SET(SNAPPY_FOUND FALSE) + ENDIF() ENDIF() diff --git a/cmake/config-cmake.h.in b/cmake/config-cmake.h.in index 70db880f..1c3728ad 100644 --- a/cmake/config-cmake.h.in +++ b/cmake/config-cmake.h.in @@ -72,3 +72,4 @@ #define LCB_CLIENT_ID "libcouchbase/" LCB_VERSION_STRING " (" LCB_SYSTEM "; " LCB_SYSTEM_PROCESSOR "; " LCB_C_COMPILER ")" #cmakedefine LCB_STATIC_SNAPPY +#cmakedefine LCB_SNAPPY_PKG_VERSION "${LCB_SNAPPY_PKG_VERSION}" diff --git a/tools/cbc.cc b/tools/cbc.cc index bb7e11bc..a2f61402 100644 --- a/tools/cbc.cc +++ b/tools/cbc.cc @@ -853,13 +853,21 @@ VersionHandler::run() #ifdef LCB_NO_SNAPPY printf(" Snappy: SUPPORTED\n"); #else - printf(" Snappy: %d.%d.%d (" #ifdef LCB_STATIC_SNAPPY - "static" +#define LCB_SNAPPY_LINK "static" #else - "dynamic" +#define LCB_SNAPPY_LINK "dynamic" +#endif +#define EXPAND(VAR) VAR ## 1 +#define IS_EMPTY(VAR) EXPAND(VAR) + +#if defined(SNAPPY_MAJOR) && (IS_EMPTY(SNAPPY_MAJOR) != 1) + printf(" Snappy: %d.%d.%d (%s)\n", SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL, LCB_SNAPPY_LINK); +#elif defined(LCB_SNAPPY_PKG_VERSION) + printf(" Snappy: %s (%s)\n", LCB_SNAPPY_PKG_VERSION, LCB_SNAPPY_LINK); +#else + printf(" Snappy: unknown (%s)\n", LCB_SNAPPY_LINK); #endif - ")\n", SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL); #endif } else { printf(" Snappy: NOT SUPPORTED\n"); -- 2.14.3