Skip to content

Commit 770c9ad

Browse files
committed
* Always copy proj data dir from the same pkg-config datadir it used during installation
1 parent ec88ed3 commit 770c9ad

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

R/zzz.R

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
OLD_PROJ <- Sys.getenv("PROJ_LIB")
2+
13
.onUnload <- function(libpath) {
24
library.dynam.unload("gdalBindings", libpath)
5+
Sys.setenv("PROJ_LIB" = OLD_PROJ)
36
invisible()
47
}
58

69
#' @useDynLib gdalBindings, .registration=TRUE
710
.onLoad <- function(libname, pkgname) {
8-
Rcpp::loadModule("gdal_module", TRUE, TRUE)
9-
InitializeGDAL()
10-
}
11-
12-
.onAttach <- function(libname, pkgname) {
13-
if (Sys.getenv("PROJ_LIB") == "") {
11+
if (system.file("proj", package = pkgname)[1] != "") {
1412
Sys.setenv("PROJ_LIB" = system.file("proj", package = pkgname)[1])
1513
}
16-
if (Sys.getenv("GDAL_DATA") == "") {
17-
Sys.setenv("GDAL_DATA" = system.file("gdal", package = pkgname)[1])
18-
}
19-
}
14+
Rcpp::loadModule("gdal_module", TRUE, TRUE)
15+
InitializeGDAL()
16+
}

configure

+38-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ ac_includes_default="\
646646
ac_header_c_list=
647647
ac_subst_vars='LTLIBOBJS
648648
LIBOBJS
649+
PROJ_DATADIR
649650
PROJ_LIBS
650651
PROJ_CFLAGS
651652
GDAL_DEP_LIBS
@@ -725,7 +726,8 @@ GDAL_LIBS
725726
CC
726727
CFLAGS
727728
PROJ_CFLAGS
728-
PROJ_LIBS'
729+
PROJ_LIBS
730+
PROJ_DATADIR'
729731

730732

731733
# Initialize some variables set by options.
@@ -1359,6 +1361,8 @@ Some influential environment variables:
13591361
CFLAGS C compiler flags
13601362
PROJ_CFLAGS C compiler flags for PROJ, overriding pkg-config
13611363
PROJ_LIBS linker flags for PROJ, overriding pkg-config
1364+
PROJ_DATADIR
1365+
value of datadir for proj, overriding pkg-config
13621366
13631367
Use these variables to override the choices made by `configure' or to help
13641368
it to find libraries and programs with nonstandard names/locations.
@@ -4429,6 +4433,39 @@ printf "%s\n" "yes" >&6; }
44294433

44304434
fi
44314435

4436+
# Copy PROJ datadir
4437+
4438+
if test -n "$PROJ_DATADIR"; then
4439+
pkg_cv_PROJ_DATADIR="$PROJ_DATADIR"
4440+
elif test -n "$PKG_CONFIG"; then
4441+
if test -n "$PKG_CONFIG" && \
4442+
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"proj\""; } >&5
4443+
($PKG_CONFIG --exists --print-errors "proj") 2>&5
4444+
ac_status=$?
4445+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
4446+
test $ac_status = 0; }; then
4447+
pkg_cv_PROJ_DATADIR=`$PKG_CONFIG --variable="datadir" "proj" 2>/dev/null`
4448+
test "x$?" != "x0" && pkg_failed=yes
4449+
else
4450+
pkg_failed=yes
4451+
fi
4452+
else
4453+
pkg_failed=untried
4454+
fi
4455+
PROJ_DATADIR=$pkg_cv_PROJ_DATADIR
4456+
4457+
if test "x$PROJ_DATADIR" = x""
4458+
then :
4459+
4460+
fi
4461+
4462+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking proj datadir path" >&5
4463+
printf %s "checking proj datadir path... " >&6; }
4464+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PROJ_DATADIR" >&5
4465+
printf "%s\n" "$PROJ_DATADIR" >&6; }
4466+
4467+
4468+
44324469
##################
44334470
## END
44344471
##################

configure.ac

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ AC_SUBST([GDAL_DEP_LIBS])
105105
################
106106
PKG_CHECK_MODULES([PROJ], [proj])
107107

108+
# Copy PROJ datadir
109+
PKG_CHECK_VAR([PROJ_DATADIR], [proj], [datadir])
110+
111+
AC_MSG_CHECKING([proj datadir path])
112+
AC_MSG_RESULT([$PROJ_DATADIR])
113+
114+
AC_SUBST([PROJ_DATADIR])
115+
108116
##################
109117
## END
110118
##################

src/Makevars.in

+13
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
PKG_CPPFLAGS = @GDAL_CFLAGS@ @PROJ_CFLAGS@
22
PKG_LIBS = @GDAL_LIBS@ @GDAL_DEP_LIBS@ @PROJ_LIBS@
3+
4+
# Copy PROJ data directory to inst/proj
5+
PROJ_DATADIR = @PROJ_DATADIR@
6+
7+
copy_proj_data:
8+
if [ -n "$(PROJ_DATADIR)" ]; then \
9+
cp -r $PROJ_DATADIR ./inst/proj/;
10+
else \
11+
echo "PROJ_DATADIR is empty. Skipping file copy."; \
12+
fi
13+
14+
# Override the default build rule to include the custom file copying rule
15+
all: copy_proj_data

0 commit comments

Comments
 (0)