From ecb963680530131a0d08b37b439ce6b24ba7d995 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 13 Oct 2021 15:46:31 +0200 Subject: Make zlib dependency optional --- libcrystfel/CMakeLists.txt | 3 ++- libcrystfel/libcrystfel-config.h.cmake.in | 1 + libcrystfel/libcrystfel-config.h.meson.in | 1 + libcrystfel/meson.build | 13 ++++++++----- libcrystfel/src/image-cbf.c | 17 ++++++++++++++++- 5 files changed, 28 insertions(+), 7 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/CMakeLists.txt b/libcrystfel/CMakeLists.txt index aea75b27..69668a8c 100644 --- a/libcrystfel/CMakeLists.txt +++ b/libcrystfel/CMakeLists.txt @@ -3,7 +3,7 @@ project(libcrystfel VERSION ${CRYSTFEL_SHORT_VERSION} LANGUAGES C) pkg_check_modules(XGANDALF xgandalf) pkg_check_modules(PINKINDEXER pinkIndexer) pkg_check_modules(FDIP fdip) -find_package(ZLIB REQUIRED) +find_package(ZLIB) find_package(FLEX REQUIRED) find_package(BISON REQUIRED) pkg_check_modules(MSGPACK msgpack) @@ -18,6 +18,7 @@ set(HAVE_PINKINDEXER ${PINKINDEXER_FOUND}) set(HAVE_FDIP ${FDIP_FOUND}) set(HAVE_MSGPACK ${MSGPACK_FOUND}) set(HAVE_LIBCCP4 ${LIBCCP4_FOUND}) +set(HAVE_ZLIB ${ZLIB_FOUND}) # Recent enough version of zlib? set(CMAKE_REQUIRED_LIBRARIES "-lz") diff --git a/libcrystfel/libcrystfel-config.h.cmake.in b/libcrystfel/libcrystfel-config.h.cmake.in index a7aaaf8f..69fd7397 100644 --- a/libcrystfel/libcrystfel-config.h.cmake.in +++ b/libcrystfel/libcrystfel-config.h.cmake.in @@ -5,6 +5,7 @@ #cmakedefine HAVE_XGANDALF #cmakedefine HAVE_PINKINDEXER #cmakedefine HAVE_FDIP +#cmakedefine HAVE_ZLIB #cmakedefine HAVE_GZBUFFER #cmakedefine HAVE_GDKPIXBUF #cmakedefine HAVE_LIBCCP4 diff --git a/libcrystfel/libcrystfel-config.h.meson.in b/libcrystfel/libcrystfel-config.h.meson.in index ede17ab8..01f6940e 100644 --- a/libcrystfel/libcrystfel-config.h.meson.in +++ b/libcrystfel/libcrystfel-config.h.meson.in @@ -4,6 +4,7 @@ #mesondefine HAVE_XGANDALF #mesondefine HAVE_PINKINDEXER #mesondefine HAVE_FDIP +#mesondefine HAVE_ZLIB #mesondefine HAVE_GZBUFFER #mesondefine HAVE_LIBCCP4 #mesondefine HAVE_MSGPACK diff --git a/libcrystfel/meson.build b/libcrystfel/meson.build index dc0fe2bf..b8dc4b6c 100644 --- a/libcrystfel/meson.build +++ b/libcrystfel/meson.build @@ -1,10 +1,13 @@ # libcrystfel -zlibdep = dependency('zlib', required: true) -if cc.has_function('gzbuffer', - prefix: '#include ', - dependencies: zlibdep) - conf_data.set10('HAVE_GZBUFFER', 1) +zlibdep = dependency('zlib', required: false) +if zlibdep.found() + conf_data.set10('HAVE_ZLIB', 1) + if cc.has_function('gzbuffer', + prefix: '#include ', + dependencies: zlibdep) + conf_data.set10('HAVE_GZBUFFER', 1) + endif endif fftwdep = dependency('fftw3', required: false) diff --git a/libcrystfel/src/image-cbf.c b/libcrystfel/src/image-cbf.c index de9fc75a..51003934 100644 --- a/libcrystfel/src/image-cbf.c +++ b/libcrystfel/src/image-cbf.c @@ -32,9 +32,12 @@ #include #include #include -#include #include +#ifdef HAVE_ZLIB +#include +#endif + #include "image.h" #include "utils.h" #include "detgeom.h" @@ -284,6 +287,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) } else { + #ifdef HAVE_ZLIB gzFile gzfh; int len_read; size_t len; @@ -293,8 +297,10 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) gzfh = gzopen(filename, "rb"); if ( gzfh == NULL ) return NULL; + #ifdef HAVE_GZBUFFER /* Set larger buffer size for hopefully faster uncompression */ gzbuffer(gzfh, 128*1024); + #endif buf = malloc(bufsz); if ( buf == NULL ) return NULL; @@ -322,6 +328,10 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) gzclose(gzfh); + #else + return NULL; + #endif + } /* This is really horrible, but there are at least three different types @@ -528,6 +538,7 @@ signed int is_cbf_file(const char *filename) signed int is_cbfgz_file(const char *filename) { + #ifdef HAVE_ZLIB gzFile gzfh; char line[1024]; @@ -541,6 +552,10 @@ signed int is_cbfgz_file(const char *filename) } return 1; + + #else /* No zlib */ + return 0; + #endif } -- cgit v1.2.3