1 # ===========================================================================
2 # https://www.gnu.org/software/autoconf-archive/ax_lib_gdal.html
3 # ===========================================================================
7 # AX_LIB_GDAL([MINIMUM-VERSION])
11 # This macro provides tests of availability of GDAL/OGR library of
12 # particular version or newer.
14 # AX_LIB_GDAL macro takes only one argument which is optional. If there is
15 # no required version passed, then macro does not run version test.
17 # The --with-gdal option takes complete path to gdal-config utility,
19 # This macro calls AC_SUBST for:
34 # Copyright (c) 2011 Mateusz Loskot <mateusz@loskot.net>
35 # Copyright (c) 2011 Alessandro Candini <candini@meeo.it>
37 # Copying and distribution of this file, with or without modification, are
38 # permitted in any medium without royalty provided the copyright notice
39 # and this notice are preserved. This file is offered as-is, without any
44 AC_DEFUN([AX_LIB_GDAL],
46 dnl If gdal-config path is not given in ---with-gdal option,
47 dnl check if it is present in the system anyway
49 AS_HELP_STRING([--with-gdal=@<:@ARG@:>@],
50 [Specify full path to gdal-config script]),
51 [ac_gdal_config_path=$withval],
52 [gdal_config_system=check])
54 dnl if gdal-config is present in the system, fill the ac_gdal_config_path variable with it full path
55 AS_IF([test "x$gdal_config_system" = xcheck],
56 [AC_PATH_PROG([GDAL_CONFIG], [gdal-config])],
57 [AC_PATH_PROG([GDAL_CONFIG], [gdal-config],
58 [no], [`dirname $ac_gdal_config_path 2> /dev/null`])]
61 if test ! -x "$GDAL_CONFIG"; then
62 AC_MSG_ERROR([gdal-config does not exist or it is not an executable file])
75 dnl Check GDAL library (libgdal)
78 if test "$GDAL_CONFIG" != "no"; then
79 AC_MSG_CHECKING([for GDAL library])
81 GDAL_VERSION="`$GDAL_CONFIG --version`"
82 GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
83 GDAL_LDFLAGS="`$GDAL_CONFIG --libs`"
84 GDAL_DEP_LDFLAGS="`$GDAL_CONFIG --dep-libs`"
86 AC_DEFINE([HAVE_GDAL], [1], [Define to 1 if GDAL library are available])
93 AC_MSG_RESULT([$found_gdal])
95 if test "$found_gdal" = "yes"; then
96 AC_MSG_CHECKING([for OGR support in GDAL library])
98 GDAL_OGR_ENABLED="`$GDAL_CONFIG --ogr-enabled`"
99 AC_DEFINE([HAVE_GDAL_OGR], [1], [Define to 1 if GDAL library includes OGR support])
101 AC_MSG_RESULT([$GDAL_OGR_ENABLED])
105 dnl Check if required version of GDAL is available
108 gdal_version_req=ifelse([$1], [], [], [$1])
109 if test "$found_gdal" = "yes" -a -n "$gdal_version_req"; then
111 AC_MSG_CHECKING([if GDAL version is >= $gdal_version_req])
113 dnl Decompose required version string of GDAL
114 dnl and calculate its number representation
115 gdal_version_req_major=`expr $gdal_version_req : '\([[0-9]]*\)'`
116 gdal_version_req_minor=`expr $gdal_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
117 gdal_version_req_micro=`expr $gdal_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
118 if test "x$gdal_version_req_micro" = "x"; then
119 gdal_version_req_micro="0"
122 gdal_version_req_number=`expr $gdal_version_req_major \* 1000000 \
123 \+ $gdal_version_req_minor \* 1000 \
124 \+ $gdal_version_req_micro`
126 dnl Decompose version string of installed GDAL
127 dnl and calculate its number representation
128 gdal_version_major=`expr $GDAL_VERSION : '\([[0-9]]*\)'`
129 gdal_version_minor=`expr $GDAL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
130 gdal_version_micro=`expr $GDAL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
131 if test "x$gdal_version_micro" = "x"; then
132 gdal_version_micro="0"
135 gdal_version_number=`expr $gdal_version_major \* 1000000 \
136 \+ $gdal_version_minor \* 1000 \
137 \+ $gdal_version_micro`
139 gdal_version_check=`expr $gdal_version_number \>\= $gdal_version_req_number`
140 if test "$gdal_version_check" = "1"; then
144 AC_MSG_ERROR([GDAL $GDAL_VERSION found, but required version is $gdal_version_req])
148 AC_SUBST(GDAL_VERSION)
149 AC_SUBST(GDAL_CFLAGS)
150 AC_SUBST(GDAL_LDFLAGS)
151 AC_SUBST(GDAL_DEP_LDFLAGS)
152 AC_SUBST(GDAL_OGR_ENABLED)