[postgis-tickets] r17712 - Improve libprotobuf detection for old systems

Paul Ramsey pramsey at cleverelephant.ca
Wed Aug 14 03:13:55 PDT 2019


Author: pramsey
Date: 2019-08-14 15:13:55 -0700 (Wed, 14 Aug 2019)
New Revision: 17712

Modified:
   branches/2.5/NEWS
   branches/2.5/configure.ac
   branches/2.5/postgis/Makefile.in
   branches/2.5/postgis/postgis_libprotobuf.c
   branches/2.5/postgis_config.h.in
   branches/2.5/regress/Makefile.in
Log:
Improve libprotobuf detection for old systems 
References #4481



Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/NEWS	2019-08-14 22:13:55 UTC (rev 17712)
@@ -21,6 +21,7 @@
   - #4470, ST_GeomFromGeoJSON crash on empty rings (Darafei Praliaskouski)
   - #4420, update path does not exists for address_standardizer extension (Regina Obe)
   - #4480, Geography Distance inconsistent with Intersects (Paul Ramsey)
+  - #4481, Improve libprotobuf detection for old systems (Paul Ramsey)
 
 
 PostGIS 2.5.2

Modified: branches/2.5/configure.ac
===================================================================
--- branches/2.5/configure.ac	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/configure.ac	2019-08-14 22:13:55 UTC (rev 17712)
@@ -939,7 +939,7 @@
 dnl ===========================================================================
 
 CHECK_PROTOBUF=yes
-HAVE_PROTOBUF=no
+HAVE_PROTOBUF=yes
 
 AC_ARG_WITH([protobuf],
 	[AS_HELP_STRING([--without-protobuf], [build without protobuf-c support])],
@@ -948,86 +948,84 @@
 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 Need to find libdir, incdir and protoc-c compiler
 
-    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])
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	LDFLAGS_SAVE="$LDFLAGS"
 
-    		dnl Add the include directory to PROTOBUF_CPPFLAGS
-    		PROTOBUF_CPPFLAGS="-I$PROTOBUFDIR/include"
-    		PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib"
-    	fi
+	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
 
-        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"
+	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
+		], [])
 
-        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"
+	if test -n "$PROTOBUF_CPPFLAGS"; then
+		CPPFLAGS="$PROTOBUF_CPPFLAGS"
+	fi
 
-    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], [
-                    HAVE_PROTOBUF=yes;
-                    PROTOBUF_CPPFLAGS=$PROTOBUFC_CFLAGS;
-                    PROTOBUF_LDFLAGS=$PROTOBUFC_LIBS
-                ],
-                [HAVE_PROTOBUF=no])
-        fi
-    fi
+	if test -n "$PROTOBUF_LDFLAGS"; then
+		LDFLAGS="$PROTOBUF_LDFLAGS"
+	fi
 
-    if test "$HAVE_PROTOBUF" = "yes"; then
-    	AC_PATH_PROG(PROTOCC, protoc-c)
-    	if test "x$PROTOCC" = "x"; then
-    	  AC_MSG_WARN([Protobuf compiler not in path, disabling protobuf support.])
-    	  HAVE_PROTOBUF=no
-    	else
-    	  AC_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
-    	fi
-    fi
+	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 Get version number for protoc-c
+	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
 
 
@@ -1524,7 +1522,7 @@
 
 AC_MSG_RESULT([  protobuf-c support:   ${HAVE_PROTOBUF}])
 if test "x$HAVE_PROTOBUF" = "xyes"; then
-  AC_MSG_RESULT([  protobuf-c version:   ${PROTOCC_SEMVER}])
+  AC_MSG_RESULT([  protobuf-c version:   ${PROTOC_VERSION}])
 fi
 
 AC_MSG_RESULT([  PCRE support:         ${HAVE_PCRE}])

Modified: branches/2.5/postgis/Makefile.in
===================================================================
--- branches/2.5/postgis/Makefile.in	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/postgis/Makefile.in	2019-08-14 22:13:55 UTC (rev 17712)
@@ -56,7 +56,7 @@
 
 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
 endif
@@ -206,7 +206,7 @@
 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

Modified: branches/2.5/postgis/postgis_libprotobuf.c
===================================================================
--- branches/2.5/postgis/postgis_libprotobuf.c	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/postgis/postgis_libprotobuf.c	2019-08-14 22:13:55 UTC (rev 17712)
@@ -10,11 +10,11 @@
 PG_FUNCTION_INFO_V1(postgis_libprotobuf_version);
 Datum postgis_libprotobuf_version(PG_FUNCTION_ARGS)
 {
-#ifndef HAVE_LIBPROTOBUF
+#ifndef HAVE_PROTOBUF_C_VERSION
 	PG_RETURN_NULL();
-#else /* HAVE_LIBPROTOBUF  */
+#else /* HAVE_PROTOBUF_C_VERSION  */
 	const char *ver = protobuf_c_version();
 	text *result = cstring_to_text(ver);
 	PG_RETURN_POINTER(result);
 #endif
-}
\ No newline at end of file
+}

Modified: branches/2.5/postgis_config.h.in
===================================================================
--- branches/2.5/postgis_config.h.in	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/postgis_config.h.in	2019-08-14 22:13:55 UTC (rev 17712)
@@ -61,6 +61,12 @@
 /* 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
 

Modified: branches/2.5/regress/Makefile.in
===================================================================
--- branches/2.5/regress/Makefile.in	2019-08-14 22:07:40 UTC (rev 17711)
+++ branches/2.5/regress/Makefile.in	2019-08-14 22:13:55 UTC (rev 17712)
@@ -23,7 +23,7 @@
 POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 HAVE_JSON=@HAVE_JSON@
 HAVE_PROTOBUF=@HAVE_PROTOBUF@
-PROTOCC_VERSION=@PROTOCC_VERSION@
+PROTOC_VERSION=@PROTOC_VERSION@
 HAVE_SFCGAL=@HAVE_SFCGAL@
 HAVE_BRIN=@HAVE_BRIN@
 HAVE_SPGIST=@HAVE_SPGIST@
@@ -252,7 +252,7 @@
 	# ST_AsMVT, ST_AsGeobuf
 	TESTS += \
 		mvt
-ifeq ($(shell expr $(PROTOCC_VERSION) ">=" 10100),1)
+ifeq ($(shell expr $(PROTOC_VERSION) ">=" 1001000),1)
 	TESTS += \
 		geobuf
 endif



More information about the postgis-tickets mailing list