diff options
author | Thomas White <taw@physics.org> | 2021-10-13 15:46:31 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-10-13 15:52:37 +0200 |
commit | ecb963680530131a0d08b37b439ce6b24ba7d995 (patch) | |
tree | 66ae7af6a669a341ed72613f93ebd4772d3ebc9c | |
parent | 8f4b2d8249fad3f8d05099b76de698a9f7db64a4 (diff) |
Make zlib dependency optional
-rw-r--r-- | INSTALL.md | 2 | ||||
-rw-r--r-- | libcrystfel/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libcrystfel/libcrystfel-config.h.cmake.in | 1 | ||||
-rw-r--r-- | libcrystfel/libcrystfel-config.h.meson.in | 1 | ||||
-rw-r--r-- | libcrystfel/meson.build | 13 | ||||
-rw-r--r-- | libcrystfel/src/image-cbf.c | 17 | ||||
-rw-r--r-- | meson.build | 1 |
7 files changed, 29 insertions, 9 deletions
@@ -33,7 +33,6 @@ Here are the mandatory dependencies - you cannot install CrystFEL without these: * [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/) * [Bison](https://www.gnu.org/software/bison/) 2.6 or later * [Flex](https://www.gnu.org/software/flex/) -* [Zlib](https://www.zlib.net/) (1.2.3.5 or later preferred for better decompression speed) The following dependencies are "optional", in the sense that you can install CrystFEL without them. However, a CrystFEL installation without these will lack @@ -46,6 +45,7 @@ roughly in order of importance: * [gdk-pixbuf](https://docs.gtk.org/gdk-pixbuf/) 2.0 or later (required for GUI) * [libccp4](ftp://ftp.ccp4.ac.uk/opensource/) \[\*\] (required for MTZ import/export) * [XGandalf](https://stash.desy.de/users/gevorkov/repos/xgandalf) \[\*\] (for `xgandalf` indexing) +* [Zlib](https://www.zlib.net/) \[\*\] (required for reading gzipped CBF files. Version 1.2.3.5 or later preferred for better decompression speed) * [PinkIndexer](https://stash.desy.de/users/gevorkov/repos/pinkindexer) \[\*\] (for indexing electron or wide bandwidth diffraction patterns) * [FFTW](http://fftw.org/) 3.0 or later (required for `asdf` indexing) * [FDIP](https://stash.desy.de/users/gevorkov/repos/fastdiffractionimageprocessing/) \[\*\] (for `peakFinder9` peak search algorithm) 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 <zlib.h>', - 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 <zlib.h>', + 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 <assert.h> #include <math.h> #include <stdio.h> -#include <zlib.h> #include <unistd.h> +#ifdef HAVE_ZLIB +#include <zlib.h> +#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 } diff --git a/meson.build b/meson.build index 6e92d430..45fca0ec 100644 --- a/meson.build +++ b/meson.build @@ -19,7 +19,6 @@ conf_data = configuration_data() cc = meson.get_compiler('c') mdep = cc.find_library('m', required: true) gsldep = dependency('gsl', required: true) -zlibdep = dependency('zlib', required: true) pthreaddep = dependency('threads', required: true) # Try via pkg-config first: |