]> granicus.if.org Git - postgis/commitdiff
Reorganize protobuf detection so that separate directories can be specified, and...
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 14 Aug 2019 22:07:40 +0000 (22:07 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 14 Aug 2019 22:07:40 +0000 (22:07 +0000)
References #4481

git-svn-id: http://svn.osgeo.org/postgis/trunk@17711 b70326c6-7e19-0410-871a-916f4a2858ee

configure.ac
postgis/Makefile.in
postgis/postgis_libprotobuf.c
postgis_config.h.in
regress/core/Makefile.in
regress/core/geobuf.sql
regress/core/geobuf_expected
regress/core/mvt.sql
regress/core/mvt_expected

index d54e8d724197dd5731de50d617b1a00a24c9b269..e5be89b438748ba6c08e2856aa72bc053d96d47b 100644 (file)
@@ -973,95 +973,103 @@ dnl Detect if protobuf-c installed
 dnl ===========================================================================
 
 CHECK_PROTOBUF=yes
-HAVE_PROTOBUF=no
+HAVE_PROTOBUF=yes
 
 AC_ARG_WITH([protobuf],
        [AS_HELP_STRING([--without-protobuf], [build without protobuf-c support])],
        [CHECK_PROTOBUF="$withval"], [])
 
-dnl User didn't turn off protobuf support so...
+dnl User didn't turn OFF protobuf support so...
 if test "$CHECK_PROTOBUF" != "no"; then
 
-    AC_ARG_WITH([protobufdir],
-       [AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],
-       [PROTOBUFDIR="$withval"], [PROTOBUFDIR=])
-
-    dnl User specified the directory to find protobuf in, check that and
-    dnl fail if it doesn't work
-    if test ! "x$PROTOBUFDIR" = "x"; then
-       dnl Make sure that the directory exists
-       if test "x$PROTOBUFDIR" = "xyes"; then
-               AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/path/to])
-       else
-               AC_MSG_RESULT([Using user-specified protobuf-c directory: $PROTOBUFDIR])
-
-               dnl Add the include directory to PROTOBUF_CPPFLAGS
-               PROTOBUF_CPPFLAGS="-I$PROTOBUFDIR/include"
-               PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib"
-       fi
-
-        dnl Check that we can find the protobuf/protobuf.h header file
-        CPPFLAGS_SAVE="$CPPFLAGS"
-        CPPFLAGS="$PROTOBUF_CPPFLAGS"
-        AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [],
-                   AC_MSG_ERROR([unable to find $PROTOBUFDIR/include/protobuf-c/protobuf-c.h])
-        )
-        CPPFLAGS="$CPPFLAGS_SAVE"
-
-        dnl Ensure we can link against libprotobuf-c
-        LIBS_SAVE="$LIBS"
-        LIBS="$PROTOBUF_LDFLAGS"
-        AC_CHECK_LIB([protobuf-c], [protobuf_c_message_check], [],
-            AC_MSG_ERROR([unable to link protobuf-c from $PROTOBUFDIR/lib])
-        )
-        HAVE_PROTOBUF=yes
-        PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib -lprotobuf-c"
-        LIBS="$LIBS_SAVE"
-
-    dnl No user-specified protobuf dir, try to find one using pkg-config
-    else
-        if test -z "$PKG_CONFIG"; then
-               AC_MSG_WARN([Cannot find pkg-config, disabling protobuf support.])
-               HAVE_PROTOBUF=no
-        else
-               dnl Ensure libprotobuf-c is of minimum required version
-               PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.1.0], [
-                    HAVE_PROTOBUF=yes;
-                    PROTOBUF_CPPFLAGS=$PROTOBUFC_CFLAGS;
-                    PROTOBUF_LDFLAGS=$PROTOBUFC_LIBS
-                ],
-                [HAVE_PROTOBUF=no])
-        fi
-    fi
+       dnl Need to find libdir, incdir and protoc-c compiler
 
-    if test "$HAVE_PROTOBUF" = "yes"; then
-       AC_PATH_PROG(PROTOCC, protoc-c)
-       if test "x$PROTOCC" = "x"; then
-         AC_MSG_WARN([Protobuf compiler missing, disabling protobuf support.])
-         HAVE_PROTOBUF=no
-       else
-         AC_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
-       fi
-    fi
+       CPPFLAGS_SAVE="$CPPFLAGS"
+       LDFLAGS_SAVE="$LDFLAGS"
+
+       dnl Try pkgconfig first
+       if test -n "$PKG_CONFIG"; then
+               dnl Ensure libprotobuf-c is of minimum required version
+               PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.0.0], [
+                               PROTOBUF_CPPFLAGS="$PROTOBUFC_CFLAGS";
+                               PROTOBUF_LDFLAGS="$PROTOBUFC_LIBS";
+                       ], [
+                               AC_MSG_RESULT([libprotobuf-c not found in pkg-config])
+                       ])
+       fi
+
+       AC_ARG_WITH([protobufdir],
+               [AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],[
+                       if test "x$withval" = "xyes"; then
+                               AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/usr/local])
+                       else
+                               PROTOBUF_LDFLAGS="-L$withval/lib -lprotobuf-c";
+                               PROTOBUF_CPPFLAGS="-I$withval/include"
+                       fi
+               ], [])
+
+       AC_ARG_WITH([protobuf-inc],
+               [AS_HELP_STRING([--with-protobuf-inc=PATH], [google/protobuf-c/protobuf-c.h header installation directory])], [
+                       PROTOBUF_CPPFLAGS="-I$withval"
+               ],[])
+
+       AC_ARG_WITH([protobuf-lib],
+               [AS_HELP_STRING([--with-protobuf-lib=PATH], [libprotobuf-c.so/dll/dylib library installation directory])], [
+                       PROTOBUF_LDFLAGS="-L$withval -lprotobuf-c"
+               ],[])
+
+       if test -n "$PROTOBUF_CPPFLAGS"; then
+               CPPFLAGS="$PROTOBUF_CPPFLAGS"
+       fi
+
+       if test -n "$PROTOBUF_LDFLAGS"; then
+               LDFLAGS="$PROTOBUF_LDFLAGS"
+       fi
 
-    dnl Get version number for protoc-c
+       dnl confirm that discovered/configured include path works
+       AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [],
+               AC_MSG_RESULT([unable to find protobuf-c/protobuf-c.h using $CPPFLAGS])
+               HAVE_PROTOBUF=no
+       )
+
+       dnl confirm that discovered/configured library path works
+       AC_CHECK_LIB([protobuf-c], [protobuf_c_message_init], [],
+               AC_MSG_RESULT([unable to link protobuf-c using $LDFLAGS])
+               HAVE_PROTOBUF=no
+       )
+
+       AC_CHECK_LIB([protobuf-c], [protobuf_c_version],
+               AC_DEFINE([HAVE_PROTOBUF_C_VERSION], [1], [Define to 1 if protobuf_c_version() is present]),
+               [])
+
+       AC_MSG_CHECKING([protobuf-c version])
+       AC_PROTOBUFC_VERSION([PROTOC_VERSION])
+       AC_MSG_RESULT([$PROTOC_VERSION])
+
+       CPPFLAGS="$CPPFLAGS_SAVE"
+       LDFLAGS="$LDFLAGS_SAVE"
+
+       dnl confirm that protobuf compiler is available
+       AC_PATH_PROG(PROTOCC, protoc-c)
+       if test -z "$PROTOCC"; then
+               AC_MSG_RESULT([Cannot find protoc-c protobuf compiler on the PATH: $PATH])
+               HAVE_PROTOBUF=no
+       fi
+
+       dnl all tests passed! turn on compile-time defines
     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_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
+               AC_DEFINE_UNQUOTED([LIBPROTOBUF_VERSION], [$PROTOC_VERSION], [Numeric version number for libprotobuf-c])
+               if test $PROTOC_VERSION -ge 1001000; then
+                       AC_DEFINE([HAVE_GEOBUF], [1], [Define to 1 if libprotobuf is >= 1.1])
+               fi
+       fi
 
-    AC_SUBST([PROTOCC_VERSION])
+    AC_SUBST([HAVE_PROTOBUF])
+    AC_SUBST([PROTOC_VERSION])
     AC_SUBST([PROTOBUF_CPPFLAGS])
     AC_SUBST([PROTOBUF_LDFLAGS])
-    AC_SUBST([HAVE_PROTOBUF])
+
 fi
 
 
@@ -1642,9 +1650,9 @@ 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}])
+AC_MSG_RESULT([  protobuf support:     ${HAVE_PROTOBUF}])
 if test "x$HAVE_PROTOBUF" = "xyes"; then
-  AC_MSG_RESULT([  protobuf-c version:   ${PROTOCC_SEMVER}])
+  AC_MSG_RESULT([  protobuf version:     ${PROTOC_VERSION}])
 fi
 
 AC_MSG_RESULT([  PCRE support:         ${HAVE_PCRE}])
index fd6607dc541d4be1b4daa8bb0488dbfb2442fbfb..03c95b7d29f265c524955d530e79554868d9cfd3 100644 (file)
@@ -58,7 +58,7 @@ endif
 
 ifeq (@HAVE_PROTOBUF@,yes)
 PROTOBUF_OBJ = vector_tile.pb-c.o
-ifeq ($(shell expr @PROTOCC_VERSION@ ">=" 10100),1)
+ifeq ($(shell expr @PROTOC_VERSION@ ">=" 1001000),1)
 PROTOBUF_OBJ += geobuf.pb-c.o
 endif
 UTHASH_INCLUDE = -I../deps/uthash/include
@@ -223,7 +223,7 @@ 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)
+ifeq ($(shell expr $(PROTOC_VERSION) ">=" 1001000),1)
 lwgeom_out_geobuf.o: geobuf.pb-c.h
 geobuf.o: geobuf.pb-c.h
 endif
index 99e208fb124bac9a43fd13128a6da8a05c474f76..0ffce0e4cb939e9a1d5f5eff2c686fe60a46acf3 100644 (file)
 PG_FUNCTION_INFO_V1(postgis_libprotobuf_version);
 Datum postgis_libprotobuf_version(PG_FUNCTION_ARGS)
 {
-#ifndef HAVE_LIBPROTOBUF
-       PG_RETURN_NULL();
-#else /* HAVE_LIBPROTOBUF  */
+#ifdef HAVE_PROTOBUF_C_VERSION
        const char *ver = protobuf_c_version();
        text *result = cstring_to_text(ver);
        PG_RETURN_POINTER(result);
+#else
+       PG_RETURN_NULL();
 #endif
 }
 
@@ -33,4 +33,4 @@ Datum postgis_wagyu_version(PG_FUNCTION_ARGS)
        text *result = cstring_to_text(ver);
        PG_RETURN_POINTER(result);
 #endif
-}
\ No newline at end of file
+}
index 54d4e89b19d74d0af07cade7ebe037db920c1eae..57afbecc0bfbef0c18da9ad4f25569bd77b88ec9 100644 (file)
 /* Define to 1 if libprotobuf-c is present */
 #undef HAVE_LIBPROTOBUF
 
+/* Define to 1 if protobuf_c_version() is present */
+#undef HAVE_PROTOBUF_C_VERSION
+
+/* Numeric version number for libprotobuf */
+#undef LIBPROTOBUF_VERSION
+
 /* Define to 1 if libprotobuf-c is >= version 1.1 */
 #undef HAVE_GEOBUF
 
index 0cc1038735b4e9e77db58cefa83f2502ade13555..000fd287fd778339975d3696ed936f0ea0d4724a 100644 (file)
@@ -23,7 +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@
+PROTOC_VERSION=@PROTOC_VERSION@
 HAVE_SPGIST=@HAVE_SPGIST@
 INTERRUPTTESTS=@INTERRUPTTESTS@
 
@@ -216,7 +216,7 @@ ifeq ($(HAVE_PROTOBUF),yes)
        TESTS += \
                mvt \
                mvt_jsonb
-ifeq ($(shell expr $(PROTOCC_VERSION) ">=" 10100),1)
+ifeq ($(shell expr $(PROTOC_VERSION) ">=" 1001000),1)
        TESTS += \
                geobuf
 endif
index e91815edfa16c69ca3234dce20bf81fa4fe83f3f..8bc9332a292e131d08a5875824f644381db7dc2f 100644 (file)
@@ -19,3 +19,12 @@ SELECT 'T9', encode(ST_AsGeobuf(q, 'geom'), 'base64')
     FROM (SELECT ST_MakePoint(1, 2, 3) as geom) AS q;
 SELECT 'T10', encode(ST_AsGeobuf(q), 'base64')
     FROM (SELECT ST_MakePoint(1, 2, 3) as geom) AS q;
+
+WITH geom AS (
+       SELECT 'TRIANGLE((0 0, 1 1, 0 1, 0 0))'::geometry geom
+       union all
+       SELECT 'TIN(((0 0, 1 1, 0 1, 0 0)))'::geometry geom
+       union all
+       SELECT 'TRIANGLE EMPTY'::geometry geom
+)
+select '#4399', 'ST_AsGeobuf', ST_AsGeobuf(geom.*)::text from geom;
index b76a90bb9caee0280c33eacbce332ed19926e717..e6c7e72c22ea7bba7aedab0f0eebc1b4240933bb 100644 (file)
@@ -10,3 +10,4 @@ T7|GAAiJgokCiIIBRIGAgEDAgUDGhZQUCcKMh0oRhMJACcoCR4ePCgTCQAU
 T8|GAAiGAoWChQIBiIGCAAaAggMIggIAhoECAwGCA==
 T9|EAMYACILCgkKBwgAGgMCBAY=
 T10|EAMYACILCgkKBwgAGgMCBAY=
+#4399|ST_AsGeobuf|\x180022260a0c0a0a08041a060000020201000a100a0e0806220a08041a060000020201000a040a020804
index 33141e37717aa82e1b7575990433fe5aa61aef38..491a714c08405fbfadaa411c2085e2bacacf75ae 100644 (file)
@@ -733,6 +733,4 @@ WITH geom AS (
        union all
        SELECT 'TRIANGLE EMPTY'::geometry geom
 )
-select '#4399', 'ST_AsGeobuf', ST_AsGeobuf(geom.*)::text from geom
-union all
 select '#4399', 'ST_AsMVTGeom', ST_AsMVTGeom(geom, ST_MakeBox2D(ST_Point(0, 0), ST_Point(32, 32)))::text from geom;
index fcff3169dbbad32a4f7c5685e770d4f1fd932a53..e88d4b015b55d54b8a55213200f6a47bd91d0608 100644 (file)
@@ -142,7 +142,6 @@ Ag==
 #4348Reversed2|t
 #4348Point|t
 #4348Crash|t
-#4399|ST_AsGeobuf|\x180022260a0c0a0a08041a060000020201000a100a0e0806220a08041a060000020201000a040a020804
 #4399|ST_AsMVTGeom|011100000001000000040000000000000000000000000000000000B0400000000000000000000000000000AF400000000000006040000000000000AF400000000000000000000000000000B040
 #4399|ST_AsMVTGeom|011100000001000000040000000000000000000000000000000000B0400000000000000000000000000000AF400000000000006040000000000000AF400000000000000000000000000000B040
 #4399|ST_AsMVTGeom|