Skip to content

Commit

Permalink
* Always copy proj data dir from the same pkg-config datadir it used …
Browse files Browse the repository at this point in the history
…during installation
  • Loading branch information
caiohamamura committed May 23, 2024
1 parent ec88ed3 commit 282f98e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 13 deletions.
17 changes: 7 additions & 10 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
OLD_PROJ <- Sys.getenv("PROJ_LIB")

.onUnload <- function(libpath) {
library.dynam.unload("gdalBindings", libpath)
Sys.setenv("PROJ_LIB" = OLD_PROJ)
invisible()
}

#' @useDynLib gdalBindings, .registration=TRUE
.onLoad <- function(libname, pkgname) {
Rcpp::loadModule("gdal_module", TRUE, TRUE)
InitializeGDAL()
}

.onAttach <- function(libname, pkgname) {
if (Sys.getenv("PROJ_LIB") == "") {
if (system.file("proj", package = pkgname)[1] != "") {
Sys.setenv("PROJ_LIB" = system.file("proj", package = pkgname)[1])
}
if (Sys.getenv("GDAL_DATA") == "") {
Sys.setenv("GDAL_DATA" = system.file("gdal", package = pkgname)[1])
}
}
Rcpp::loadModule("gdal_module", TRUE, TRUE)
InitializeGDAL()
}
75 changes: 72 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ ac_includes_default="\
ac_header_c_list=
ac_subst_vars='LTLIBOBJS
LIBOBJS
PROJ_DATADIR
PROJ_LIBS
PROJ_CFLAGS
GDAL_DEP_LIBS
Expand Down Expand Up @@ -725,7 +726,8 @@ GDAL_LIBS
CC
CFLAGS
PROJ_CFLAGS
PROJ_LIBS'
PROJ_LIBS
PROJ_DATADIR'


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

fi

# Copy PROJ datadir

if test -n "$PROJ_DATADIR"; then
pkg_cv_PROJ_DATADIR="$PROJ_DATADIR"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"proj\""; } >&5
($PKG_CONFIG --exists --print-errors "proj") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_PROJ_DATADIR=`$PKG_CONFIG --variable="datadir" "proj" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi
PROJ_DATADIR=$pkg_cv_PROJ_DATADIR

if test "x$PROJ_DATADIR" = x""
then :

fi

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking proj datadir path" >&5
printf %s "checking proj datadir path... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PROJ_DATADIR" >&5
printf "%s\n" "$PROJ_DATADIR" >&6; }

if test "x$PROJ_DATADIR" = "x"
then :

{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "Unable to identify proj datadir path.
See \`config.log' for more details" "$LINENO" 5; }

else $as_nop

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Copying proj data files to inst/proj" >&5
printf "%s\n" "$as_me: Copying proj data files to inst/proj" >&6;}
ac_config_commands="$ac_config_commands proj-data"




fi


##################
## END
##################
Expand Down Expand Up @@ -4994,6 +5049,7 @@ esac
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
# Files that config.status was made for.
config_files="$ac_config_files"
config_commands="$ac_config_commands"
_ACEOF
Expand All @@ -5018,6 +5074,9 @@ Usage: $0 [OPTION]... [TAG]...
Configuration files:
$config_files
Configuration commands:
$config_commands
Report bugs to the package provider."
_ACEOF
Expand Down Expand Up @@ -5136,6 +5195,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"proj-data") CONFIG_COMMANDS="$CONFIG_COMMANDS proj-data" ;;
"src/Makevars") CONFIG_FILES="$CONFIG_FILES src/Makevars" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
Expand All @@ -5149,6 +5209,7 @@ done
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files
test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands
fi
# Have a temporary directory for convenience. Make it in the build tree
Expand Down Expand Up @@ -5337,7 +5398,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
fi # test -n "$CONFIG_FILES"
eval set X " :F $CONFIG_FILES "
eval set X " :F $CONFIG_FILES :C $CONFIG_COMMANDS"
shift
for ac_tag
do
Expand Down Expand Up @@ -5547,9 +5608,16 @@ which seems to be undefined. Please make sure it is defined" >&2;}
;;
:C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
printf "%s\n" "$as_me: executing $ac_file commands" >&6;}
;;
esac
case $ac_file$ac_mode in
"proj-data":C) cp -r $PROJ_DATADIR inst/proj ;;
esac
done # for ac_tag
Expand All @@ -5560,6 +5628,7 @@ ac_clean_files=$ac_clean_files_save
test $ac_write_fail = 0 ||
as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
proj-data
# configure is writing to config.log, and then calls config.status.
# config.status does its own redirection, appending to config.log.
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ AC_SUBST([GDAL_DEP_LIBS])
################
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])

AC_SUBST([PROJ_DATADIR])

##################
## END
##################
Expand Down
13 changes: 13 additions & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
PKG_CPPFLAGS = @GDAL_CFLAGS@ @PROJ_CFLAGS@
PKG_LIBS = @GDAL_LIBS@ @GDAL_DEP_LIBS@ @PROJ_LIBS@

# Copy PROJ data directory to inst/proj
PROJ_DATADIR = @PROJ_DATADIR@

copy_proj_data:
if [ -n "$(PROJ_DATADIR)" ]; then \
cp -r $PROJ_DATADIR ./inst/proj/;
else \
echo "PROJ_DATADIR is empty. Skipping file copy."; \
fi

# Override the default build rule to include the custom file copying rule
all: copy_proj_data

0 comments on commit 282f98e

Please sign in to comment.