-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure.ac
244 lines (200 loc) · 6.07 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Initialize the package and version
AC_INIT([gdalBindings],[0.1.33])
# Initialize autoconfig
AC_PREREQ([2.71])
# Check for the required version of pkg-config
PKG_PROG_PKG_CONFIG([0.15.0])
# Pick R specific compiler and flags
CXX=`"${R_HOME}/bin/R" CMD config CXX`
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS`
AC_MSG_CHECKING([the operating system name])
os_name=`"${R_HOME}/bin/Rscript" -e "cat(Sys.info()[['sysname']])"`
AC_MSG_RESULT([$os_name])
# Check for the presence of a C compiler
AC_PROG_CXX()
#################
## GDAL
#################
# Define a function to give an error message if GDAL is not installed
AC_DEFUN([GDAL_INSTALLATION_ERROR], [
AC_MSG_ERROR([
Please make sure the GDAL development package is installed:
- On Debian/Ubuntu: sudo apt-get install libgdal-dev
- On Fedora: sudo dnf install gdal-devel
- On Arch Linux: sudo pacman -S gdal
- On macOS (Homebrew): brew install gdal
- On macOS (MacPorts): sudo port install gdal
])
])
# Define a function to test if gdal test program compiles
# args: message, action if compiles, action if fails
AC_DEFUN([GDAL_TEST_PROGRAM_IFELSE], [
AC_MSG_CHECKING([$1])
AC_LANG_PUSH([C++])
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[[#include <gdal.h>]],
[[GDALAllRegister();]]
)
]
,[
AC_MSG_RESULT([yes])
$2
], # Action if the program compiles correctly
[
AC_MSG_RESULT([no])
$3
] # Action if the program fails to compile
)
AC_LANG_POP([C++])
])
# Check for GDAL using pkg-config
PKG_CHECK_MODULES([GDAL], [gdal])
PKG_CHECK_MODULES_STATIC([GDAL_STATIC], [gdal])
GDAL_PKG_CONFIG_CFLAGS=$GDAL_CFLAGS
GDAL_PKG_CONFIG_LIBS=$GDAL_LIBS
# Check for GDAL gdal-config
# Allow the user to specify the path to gdal-config
AC_ARG_WITH([gdal-config],
[AS_HELP_STRING([--with-gdal-config=PATH], [specify the path to gdal-config])],
[gdal_config_path=$withval], [gdal_config_path=""])
# Check if the user has specified a custom path
AS_IF([test -n "$gdal_config_path"],
[
# Check if the gdal-config exists at the specified path
AC_CHECK_PROG([GDAL_CONFIG], [$gdal_config_path], [$gdal_config_path])
AS_IF([test -z "$GDAL_CONFIG"], [
AC_MSG_ERROR([gdal-config not found at specified path: $gdal_config_path])])],
[
# Check for gdal-config in the default PATH
AC_PATH_PROG([GDAL_CONFIG], [gdal-config])
# If not found, error out with instructions
AS_IF([test -z "$GDAL_CONFIG"], [
AC_MSG_NOTICE([
gdal-config not found.
If you have installed the GDAL libraries, then make sure that
gdal-config is in your path. Try typing gdal-config at a
shell prompt and see if it runs. If not, use:
--configure-args='--with-gdal-config=/usr/local/bin/gdal-config'
with appropriate values for your installation.
If you have not installed the GDAL libraries,
])
GDAL_INSTALLATION_ERROR
]
)])
# Output the found path of gdal-config
AC_MSG_NOTICE([Using gdal-config at $GDAL_CONFIG])
# Get compiler and linker flags from gdal-config
GDAL_CONFIG_CFLAGS=`${GDAL_CONFIG} --cflags`
GDAL_CONFIG_LIBS=$($GDAL_CONFIG --libs)
GDAL_CONFIG_DEP_LIBS=$($GDAL_CONFIG --dep-libs)
# Define CXXFLAGS which are used by default to compile the test program
CXXFLAGS="${CXXFLAGS} ${GDAL_CFLAGS}"
# Define CPPFLAGS which are used by default by AC_CHECK_HEADER
CPPFLAGS="${CPPFLAGS} ${GDAL_CFLAGS}"
# Check if gdal.h header file is present
AC_CHECK_HEADER([gdal.h],
[],
[
AC_MSG_NOTICE([gdal.h not found in given locations.])
GDAL_INSTALLATION_ERROR
]
)
GDAL_LIBS=$GDAL_CONFIG_LIBS
LIBS="${GDAL_LIBS}"
gdal_can_compile=no
# Try to link GDAL with gdal-config --libs only
GDAL_LIBS=$GDAL_CONFIG_LIBS
LIBS="${GDAL_LIBS}"
GDAL_TEST_PROGRAM_IFELSE(
[whether GDAL can be linked using only `gdal-config --libs`],
[
gdal_can_compile=yes
]
)
# Try to link GDAL with gdal-config --libs and --dep-libs
AS_IF([test "x$gdal_can_compile" = "xno"], [
GDAL_LIBS="${GDAL_CONFIG_LIBS} ${GDAL_CONFIG_DEP_LIBS}"
LIBS="${GDAL_LIBS}"
GDAL_TEST_PROGRAM_IFELSE(
[whether GDAL can be linked using `gdal-config --libs` and `--dep-libs`],
[
gdal_can_compile=yes
]
)
])
# Try to link GDAL with `pkg-config --libs gdal` only
AS_IF([test "x$gdal_can_compile" = "xno"], [
GDAL_LIBS=$GDAL_PKG_CONFIG_LIBS
LIBS="${GDAL_LIBS}"
GDAL_TEST_PROGRAM_IFELSE(
[whether GDAL can be linked using only `pkg-config --libs gdal`],
[
gdal_can_compile=yes
]
)
])
AS_IF([test "x$gdal_can_compile" = "xno"], [
# Now try to link GDAL with pkg-config --libs --static gdal
GDAL_LIBS="${$GDAL_STATIC_LIBS}"
LIBS="${GDAL_LIBS}"
GDAL_TEST_PROGRAM_IFELSE(
[whether GDAL can be linked using `pkg-config --libs --static gdal`],
[
gdal_can_compile=yes
]
)
])
AS_IF([test "x$gdal_can_compile" = "xno"], [
AC_MSG_NOTICE([
Could not link to GDAL using `pkg-config` nor `gdal-config`.
])
GDAL_INSTALLATION_ERROR
]
)
AC_SUBST([GDAL_LIBS])
################
## PROJ
################
PKG_CHECK_MODULES([PROJ], [proj])
# Copy PROJ datadir
PKG_CHECK_VAR([PROJ_DATADIR], [proj], [datadir])
AC_MSG_CHECKING([proj datadir path])
AC_MSG_RESULT([$PROJ_DATADIR])
# Try to use the PROJ datadir
AC_MSG_CHECKING([whether PROJ can be ran using the datadir])
AC_LANG_PUSH([C++])
LIBS="${PROJ_LIBS}"
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[
#include <proj.h>
]], [[
const char* paths[] = {"$PROJ_DATADIR"};
proj_context_set_search_paths(NULL, 1, paths);
proj_create(NULL, "EPSG:4326");
int ret = proj_context_errno(NULL);
return ret;
]])
], [
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
AC_MSG_ERROR([PROJ test program failed to run])
])
AC_LANG_POP([C++])
AC_SUBST([PROJ_DATADIR])
##################
## END
##################
# Configure the output files
output_files="src/Makevars"
AS_IF([test "x$os_name" = "xWindows"],
[
output_files="src/Makevars.ucrt"
rm -f src/Makevars.ucrt.in
cp src/Makevars.in src/Makevars.ucrt.in
]
)
AC_CONFIG_FILES([$output_files])
AC_OUTPUT