From 282f98e9ae8d5f78647592597dba5c01bd9a04fc Mon Sep 17 00:00:00 2001 From: caiohamamura Date: Thu, 23 May 2024 09:56:49 -0400 Subject: [PATCH] * Always copy proj data dir from the same pkg-config datadir it used during installation --- R/zzz.R | 17 +++++------ configure | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- configure.ac | 8 ++++++ src/Makevars.in | 13 +++++++++ 4 files changed, 100 insertions(+), 13 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 6044347..9c6e4cb 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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() +} \ No newline at end of file diff --git a/configure b/configure index ef92b11..58f3445 100755 --- a/configure +++ b/configure @@ -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 @@ -725,7 +726,8 @@ GDAL_LIBS CC CFLAGS PROJ_CFLAGS -PROJ_LIBS' +PROJ_LIBS +PROJ_DATADIR' # Initialize some variables set by options. @@ -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. @@ -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 ################## @@ -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 @@ -5018,6 +5074,9 @@ Usage: $0 [OPTION]... [TAG]... Configuration files: $config_files +Configuration commands: +$config_commands + Report bugs to the package provider." _ACEOF @@ -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;; @@ -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 @@ -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 @@ -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 @@ -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. diff --git a/configure.ac b/configure.ac index e1fa547..74bc24d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ################## diff --git a/src/Makevars.in b/src/Makevars.in index 545a4f7..1432c82 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -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 \ No newline at end of file