Skip to content

Commit b619873

Browse files
committed
PHPC-2236: Allow compression libraries to be configured at build time
This introduces several configure options: --with-mongodb-snappy=[auto/yes/no] --with-mongodb-zlib=[auto/yes/system/bundled/no] --with-mongodb-zstd=[auto/yes/no] The "auto", "yes", and "no" options behave like existing options: "auto" attempts to use a library but allows it to not be found; "yes" requires a library and errors if it's not found; "no" disables a library. The "system" and "bundled" options for zlib function like "yes", but for using the system library or bundled zlib sources in libmongoc, respectively. Since bundled sources are always available, configuring zlib with "auto", "yes", or "bundled" should never fail.
1 parent 4c5084c commit b619873

File tree

1 file changed

+89
-50
lines changed

1 file changed

+89
-50
lines changed

scripts/autotools/libmongoc/CheckCompression.m4

Lines changed: 89 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,111 @@
1+
PHP_ARG_WITH([mongodb-snappy],
2+
[whether to enable Snappy for compression],
3+
[AS_HELP_STRING([--with-mongodb-snappy=@<:@auto/yes/no@:>@],
4+
[MongoDB: Enable Snappy for compression [default=auto]])],
5+
[auto],
6+
[no])
7+
8+
PHP_ARG_WITH([mongodb-zlib],
9+
[whether to enable zlib for compression],
10+
[AS_HELP_STRING([--with-mongodb-zlib=@<:@auto/yes/system/bundled/no@:>@],
11+
[MongoDB: Enable zlib for compression [default=auto]])],
12+
[auto],
13+
[no])
14+
15+
PHP_ARG_WITH([mongodb-zstd],
16+
[whether to enable zstd for compression],
17+
[AS_HELP_STRING([--with-mongodb-zstd=@<:@auto/yes/no@:>@],
18+
[MongoDB: Enable zstd for compression [default=auto]])],
19+
[auto],
20+
[no])
21+
122
found_snappy="no"
223
found_zlib="no"
324
bundled_zlib="no"
425
found_zstd="no"
526

6-
PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
7-
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_SNAPPY_CFLAGS"
8-
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
9-
found_snappy="yes"
10-
],[
11-
PHP_CHECK_LIBRARY([snappy],
12-
[snappy_uncompress],
13-
[have_snappy_lib="yes"],
14-
[have_snappy_lib="no"])
15-
16-
AC_CHECK_HEADER([snappy-c.h],
17-
[have_snappy_headers=yes],
18-
[have_snappy_headers=no])
19-
20-
if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
21-
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
27+
AS_IF([test "$PHP_MONGODB_SNAPPY" = "auto" -o "$PHP_MONGODB_SNAPPY" = "yes"],[
28+
PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
29+
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_SNAPPY_CFLAGS"
30+
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
2231
found_snappy="yes"
32+
],[
33+
PHP_CHECK_LIBRARY([snappy],
34+
[snappy_uncompress],
35+
[have_snappy_lib="yes"],
36+
[have_snappy_lib="no"])
37+
38+
AC_CHECK_HEADER([snappy-c.h],
39+
[have_snappy_headers=yes],
40+
[have_snappy_headers=no])
41+
42+
if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
43+
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
44+
found_snappy="yes"
45+
fi
46+
])
47+
48+
if test "$PHP_MONGODB_SNAPPY" = "yes" -a "$found_snappy" = "no"; then
49+
AC_MSG_ERROR([Snappy libraries and development headers could not be found])
2350
fi
2451
])
2552

26-
PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
27-
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZLIB_CFLAGS"
28-
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
29-
found_zlib="yes"
30-
],[
31-
PHP_CHECK_LIBRARY([zlib],
32-
[compress2],
33-
[have_zlib_lib="yes"],
34-
[have_zlib_lib="no"])
35-
36-
AC_CHECK_HEADER([zlib.h],
37-
[have_zlib_headers=yes],
38-
[have_zlib_headers=no])
39-
40-
if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
41-
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
53+
AS_IF([test "$PHP_MONGODB_ZLIB" = "auto" -o "$PHP_MONGODB_ZLIB" = "yes" -o "$PHP_MONGODB_ZLIB" = "system"],[
54+
PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
55+
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZLIB_CFLAGS"
56+
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
4257
found_zlib="yes"
58+
],[
59+
PHP_CHECK_LIBRARY([zlib],
60+
[compress2],
61+
[have_zlib_lib="yes"],
62+
[have_zlib_lib="no"])
63+
64+
AC_CHECK_HEADER([zlib.h],
65+
[have_zlib_headers=yes],
66+
[have_zlib_headers=no])
67+
68+
if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
69+
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
70+
found_zlib="yes"
71+
fi
72+
])
73+
74+
if test "$PHP_MONGODB_ZLIB" = "system" -a "$found_zlib" = "no"; then
75+
AC_MSG_ERROR([zlib libraries and development headers could not be found])
4376
fi
4477
])
4578

46-
dnl If zlib was not found, use libmongoc's bundled version
47-
AS_IF([test "$found_zlib" != "yes"],[
79+
dnl Use libmongoc's bundled zlib if necessary
80+
AS_IF([test "$found_zlib" = "no" -a \( "$PHP_MONGODB_ZLIB" = "auto" -o "$PHP_MONGODB_ZLIB" = "yes" -o "$PHP_MONGODB_ZLIB" = "bundled" \)],[
4881
AC_CHECK_HEADER([unistd.h],[PHP_MONGODB_ZLIB_CFLAGS="$PHP_MONGODB_ZLIB_CFLAGS -DHAVE_UNISTD_H"])
4982
AC_CHECK_HEADER([stdarg.h],[PHP_MONGODB_ZLIB_CFLAGS="$PHP_MONGODB_ZLIB_CFLAGS -DHAVE_STDARG_H"])
5083
bundled_zlib="yes"
5184
])
5285

53-
PKG_CHECK_MODULES([PHP_MONGODB_ZSTD],[libzstd],[
54-
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZSTD_CFLAGS"
55-
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZSTD_LIBS],[MONGODB_SHARED_LIBADD])
56-
found_zstd="yes"
57-
],[
58-
PHP_CHECK_LIBRARY([zstd],
59-
[ZSTD_compress],
60-
[have_zstd_lib="yes"],
61-
[have_zstd_lib="no"])
62-
63-
AC_CHECK_HEADER([zstd.h],
64-
[have_zstd_headers=yes],
65-
[have_zstd_headers=no])
66-
67-
if test "$have_zstd_lib" = "yes" -a "$have_zstd_headers" = "yes"; then
68-
PHP_ADD_LIBRARY([zstd],,[MONGODB_SHARED_LIBADD])
86+
AS_IF([test "$PHP_MONGODB_ZSTD" = "auto" -o "$PHP_MONGODB_ZSTD" = "yes"],[
87+
PKG_CHECK_MODULES([PHP_MONGODB_ZSTD],[libzstd],[
88+
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZSTD_CFLAGS"
89+
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZSTD_LIBS],[MONGODB_SHARED_LIBADD])
6990
found_zstd="yes"
91+
],[
92+
PHP_CHECK_LIBRARY([zstd],
93+
[ZSTD_compress],
94+
[have_zstd_lib="yes"],
95+
[have_zstd_lib="no"])
96+
97+
AC_CHECK_HEADER([zstd.h],
98+
[have_zstd_headers=yes],
99+
[have_zstd_headers=no])
100+
101+
if test "$have_zstd_lib" = "yes" -a "$have_zstd_headers" = "yes"; then
102+
PHP_ADD_LIBRARY([zstd],,[MONGODB_SHARED_LIBADD])
103+
found_zstd="yes"
104+
fi
105+
])
106+
107+
if test "$PHP_MONGODB_ZSTD" = "yes" -a "$found_zstd" = "no"; then
108+
AC_MSG_ERROR([zstd libraries and development headers could not be found])
70109
fi
71110
])
72111

0 commit comments

Comments
 (0)