From: Paul Ramsey Date: Tue, 30 Jul 2019 22:27:22 +0000 (+0000) Subject: Use protobuf version to enable/disable mvt/geobuf X-Git-Tag: 3.0.0alpha4~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f8d8afad08ffc54183fec153bcdd21542786e40;p=postgis Use protobuf version to enable/disable mvt/geobuf Closes #4419 git-svn-id: http://svn.osgeo.org/postgis/trunk@17648 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 7db986330..a728f4d8f 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12 - #4403, Support for shp2pgsql ability to reproject with copy mode (-D) (Regina Obe) - #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 3.0.0alpha3 2019/07/01 diff --git a/configure.ac b/configure.ac index fccf7bdcd..d54e8d724 100644 --- a/configure.ac +++ b/configure.ac @@ -1044,6 +1044,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]) @@ -1626,7 +1641,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([ Wagyu: ${HAVE_WAGYU}]) diff --git a/postgis/Makefile.in b/postgis/Makefile.in index e925dc38e..69653f453 100644 --- a/postgis/Makefile.in +++ b/postgis/Makefile.in @@ -57,7 +57,10 @@ SPGIST_OBJ= gserialized_spgist_2d.o gserialized_spgist_3d.o gserialized_spgist_n 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 UTHASH_INCLUDE = -I../deps/uthash/include endif @@ -220,9 +223,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 d8d218d15..6170eff40 100644 --- a/postgis/geobuf.c +++ b/postgis/geobuf.c @@ -26,7 +26,7 @@ #include "geobuf.h" #include "pgsql_compat.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 c84bfbb9c..54d4e89b1 100644 --- a/postgis_config.h.in +++ b/postgis_config.h.in @@ -41,6 +41,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/core/Makefile.in b/regress/core/Makefile.in index 14c955a6a..3d04e5287 100644 --- a/regress/core/Makefile.in +++ b/regress/core/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_SPGIST=@HAVE_SPGIST@ INTERRUPTTESTS=@INTERRUPTTESTS@ @@ -207,8 +208,11 @@ ifeq ($(HAVE_PROTOBUF),yes) # ST_AsMVT, ST_AsGeobuf TESTS += \ mvt \ - geobuf \ mvt_jsonb +ifeq ($(shell expr $(PROTOCC_VERSION) ">=" 10100),1) + TESTS += \ + geobuf +endif endif all install uninstall: