From: Paul Ramsey Date: Tue, 30 Jul 2019 22:27:06 +0000 (+0000) Subject: Use protobuf version to enable/disable mvt/geobuf X-Git-Tag: 2.4.8~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f1b5e41ad407ed40eacc27872df5ac2b9730d6e;p=postgis Use protobuf version to enable/disable mvt/geobuf References #4419 git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@17646 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 08918ea4d..89c0db839 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ PostGIS 2.4.8 - #4445, Fix bug in lwgeom_le (Raúl Marín) - #4466, Fix undefined behaviour in _postgis_gserialized_stats (Raúl Marín) - #4209, Handle NULL geometry values in pgsql2shp (Paul Ramsey) + - #4419, Use protobuf version to enable/disable mvt/geobuf (Paul Ramsey) PostGIS 2.4.7 diff --git a/configure.ac b/configure.ac index ac25077b9..793dca6c6 100644 --- a/configure.ac +++ b/configure.ac @@ -995,6 +995,21 @@ if test "$CHECK_PROTOBUF" != "no"; then fi fi + dnl Get version number for protoc-c + if test "$HAVE_PROTOBUF" = "yes"; then + AC_PATH_PROG(PROTOCC, protoc-c) + PROTOCC_SEMVER=$($PROTOCC --version | grep protobuf-c | awk '{print $2}') + AC_MSG_RESULT([checking protoc-c version... $PROTOCC_SEMVER]) + PROTOCC_VERSION_MAJOR=$(echo "$PROTOCC_SEMVER" | tr '.' ' ' | awk '{print $1}') + PROTOCC_VERSION_MINOR=$(echo "$PROTOCC_SEMVER" | tr '.' ' ' | awk '{print $2}') + PROTOCC_VERSION_PATCH=$(echo "$PROTOCC_SEMVER" | tr '.' ' ' | awk '{print $3}') + PROTOCC_VERSION=$(expr 10000 \* $PROTOCC_VERSION_MAJOR + 100 \* $PROTOCC_VERSION_MINOR + $PROTOCC_VERSION_PATCH) + if test $PROTOCC_VERSION -ge 10100; then + AC_DEFINE([HAVE_GEOBUF], [1], [Define to 1 if libprotobuf-c is >= 1.1]) + fi + fi + + AC_SUBST([PROTOCC_VERSION]) AC_SUBST([PROTOBUF_CPPFLAGS]) AC_SUBST([PROTOBUF_LDFLAGS]) AC_SUBST([HAVE_PROTOBUF]) @@ -1497,7 +1512,12 @@ AC_MSG_RESULT([ PROJ4 version: ${POSTGIS_PROJ_VERSION}]) AC_MSG_RESULT([ Libxml2 config: ${XML2CONFIG}]) AC_MSG_RESULT([ Libxml2 version: ${POSTGIS_LIBXML2_VERSION}]) AC_MSG_RESULT([ JSON-C support: ${HAVE_JSON}]) + AC_MSG_RESULT([ protobuf-c support: ${HAVE_PROTOBUF}]) +if test "x$HAVE_PROTOBUF" = "xyes"; then + AC_MSG_RESULT([ protobuf-c version: ${PROTOCC_SEMVER}]) +fi + AC_MSG_RESULT([ PCRE support: ${HAVE_PCRE}]) AC_MSG_RESULT([ Perl: ${PERL}]) AC_MSG_RESULT() diff --git a/postgis/Makefile.in b/postgis/Makefile.in index a514fe051..26abbba4d 100644 --- a/postgis/Makefile.in +++ b/postgis/Makefile.in @@ -51,7 +51,10 @@ BRIN_OBJ= brin_2d.o brin_nd.o brin_common.o endif ifeq (@HAVE_PROTOBUF@,yes) -PROTOBUF_OBJ=vector_tile.pb-c.o geobuf.pb-c.o +PROTOBUF_OBJ = vector_tile.pb-c.o +ifeq ($(shell expr @PROTOCC_VERSION@ ">=" 10100),1) +PROTOBUF_OBJ += geobuf.pb-c.o +endif endif # SQL preprocessor @@ -197,9 +200,11 @@ geobuf.pb-c.c geobuf.pb-c.h: geobuf.proto ifeq (@HAVE_PROTOBUF@,yes) lwgeom_out_mvt.o: vector_tile.pb-c.h mvt.o: vector_tile.pb-c.h +ifeq ($(shell expr $(PROTOCC_VERSION) ">=" 10100),1) lwgeom_out_geobuf.o: geobuf.pb-c.h geobuf.o: geobuf.pb-c.h endif +endif # Borrow the $libdir substitution from PGXS but customise by running the preprocessor # and adding the version number diff --git a/postgis/geobuf.c b/postgis/geobuf.c index 25593f75d..5fa6c32c2 100644 --- a/postgis/geobuf.c +++ b/postgis/geobuf.c @@ -25,7 +25,7 @@ #include #include "geobuf.h" -#ifdef HAVE_LIBPROTOBUF +#if defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF #define FEATURES_CAPACITY_INITIAL 50 #define MAX_PRECISION 1e6 diff --git a/postgis/geobuf.h b/postgis/geobuf.h index 6614139d3..2e0ae5f06 100644 --- a/postgis/geobuf.h +++ b/postgis/geobuf.h @@ -42,7 +42,7 @@ #include "lwgeom_pg.h" #include "lwgeom_log.h" -#ifdef HAVE_LIBPROTOBUF +#if defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF #include "geobuf.pb-c.h" diff --git a/postgis/lwgeom_out_geobuf.c b/postgis/lwgeom_out_geobuf.c index 88bf47b69..1221fab5a 100644 --- a/postgis/lwgeom_out_geobuf.c +++ b/postgis/lwgeom_out_geobuf.c @@ -45,8 +45,8 @@ PG_FUNCTION_INFO_V1(pgis_asgeobuf_transfn); Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS) { -#ifndef HAVE_LIBPROTOBUF - elog(ERROR, "Missing libprotobuf-c"); +#if ! (defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF) + elog(ERROR, "Missing libprotobuf-c >= version 1.1"); PG_RETURN_NULL(); #else MemoryContext aggcontext; @@ -82,8 +82,8 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(pgis_asgeobuf_finalfn); Datum pgis_asgeobuf_finalfn(PG_FUNCTION_ARGS) { -#ifndef HAVE_LIBPROTOBUF - elog(ERROR, "Missing libprotobuf-c"); +#if ! (defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF) + elog(ERROR, "Missing libprotobuf-c >= version 1.1"); PG_RETURN_NULL(); #else uint8_t *buf; diff --git a/postgis_config.h.in b/postgis_config.h.in index a84f482dc..da60dffa5 100644 --- a/postgis_config.h.in +++ b/postgis_config.h.in @@ -61,6 +61,9 @@ /* Define to 1 if libprotobuf-c is present */ #undef HAVE_LIBPROTOBUF +/* Define to 1 if libprotobuf-c is >= version 1.1 */ +#undef HAVE_GEOBUF + /* Define to 1 if libjson is present */ #undef HAVE_LIBJSON diff --git a/regress/Makefile.in b/regress/Makefile.in index 84b94b369..249ef78de 100644 --- a/regress/Makefile.in +++ b/regress/Makefile.in @@ -23,6 +23,7 @@ POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@ POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@ HAVE_JSON=@HAVE_JSON@ HAVE_PROTOBUF=@HAVE_PROTOBUF@ +PROTOCC_VERSION=@PROTOCC_VERSION@ HAVE_SFCGAL=@HAVE_SFCGAL@ HAVE_BRIN=@HAVE_BRIN@ MINGWBUILD=@MINGWBUILD@ @@ -251,8 +252,11 @@ ifeq ($(HAVE_PROTOBUF),yes) # protobuf-c adds: # ST_AsMVT, ST_AsGeobuf TESTS += \ - mvt \ + mvt +ifeq ($(shell expr $(PROTOCC_VERSION) ">=" 10100),1) + TESTS += \ geobuf +endif ifeq ($(shell expr $(POSTGIS_PGSQL_VERSION) ">=" 94),1) TESTS += \ mvt_jsonb