Alien-gdal

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

my @alien_deps = qw(
        Alien::geos::af
        Alien::proj
        Alien::sqlite
        Alien::libtiff
  );

#  make sure we get GEOS, PROJ and other support
foreach my $alien (@alien_deps) {
  eval "require $alien";
  my $e = $@;
  warn $e if $e;
  if (!$e && $alien->install_type eq 'share') {
    log "Prepending $alien bin dir to path";
    unshift @PATH, $alien->bin_dir;
  }
}
my $have_spatialite = eval 'require
  Alien::spatialite';
if ($have_spatialite && Alien::spatialite->version ge 5) {
  if (!$on_windows and Alien::spatialite->install_type('share')
      and $Alien::spatialite::VERSION lt 1.06) {
    $have_spatialite = undef;  #  rpath issues before this
  }
  else {
    log "Prepending Alien::spatialite bin dir to path";
    unshift @PATH, Alien::spatialite->bin_dir;
    push @alien_deps, 'Alien::spatialite' if Alien::spatialite->install_type eq 'share';
  }
}
else {
  $have_spatialite = undef;
}

#  configure script does not seem to detect the proj lib distributed with Strawberry perl
#use FFI::CheckLib;
#my $proj_lib = FFI::CheckLib::find_lib (lib => 'proj');
Alien::Build->log ('$ENV{PROJ_LIB} IS ' . ($ENV{PROJ_LIB} // ''));


#  make libtool noisy for debug purposes
#$ENV{LTFLAGS} = "--debug --verbose" if $on_windows;


use Cwd;
my $base_dir = getcwd();

my $min_target_version = '3.1.0';

plugin 'PkgConfig' => (
    pkg_name => 'gdal',
    minimum_version => $min_target_version,
);


share {

  #  add existing alien files to path etc
  #  not very elegant...
  #  disable for now - config tests fail
  #  it looks to be already noted in https://github.com/Perl5-Alien/Alien-Build/issues/12
  #  might also be able to access via old hash via https://metacpan.org/pod/Alien::Build#install_prop
  my $have_alien_gdal = eval 'require Alien::gdal';
  my $copy_from_dir;
  if ($ENV{ALIEN_SHARE_RECYCLE} && $have_alien_gdal && Alien::gdal->install_type eq 'share') {
      my $ag_version = Alien::gdal->version;
      say "Found existing gdal via alien ($ag_version) in " .  Alien::gdal->dist_dir;
      #  append the relevant path
      if (versioncmp($ag_version, $min_target_version) >= 0) {
        $copy_from_dir = Alien::gdal->dist_dir;
      }
  }

  if ($copy_from_dir) {
    #  files are copied in the extract hook
    meta->register_hook(download => sub {
      Path::Tiny->new ('fauxdownload.txt')->touch;
    });

    if($^O eq 'MSWin32') {
      meta->register_hook(extract => sub {
        my($build) = @_;
        $copy_from_dir =~ s|/|\\|g;  #  it seems that xcopy needs backslashes in paths
        $build->system("xcopy $copy_from_dir . /E /Q");
      });
    }
    else {
      meta->register_hook(extract => sub {
        my ($build) = @_;
        "cp -aR $copy_from_dir .";
      });
    }

    meta->after_hook( extract => sub {
      my($build) = @_;
      $build->log('CURRENTLY IN ' . cwd());
      File::Path::rmtree '_alien';
    });

    plugin 'Build::Copy';

  }
  else {
    my $with_local = '';
    my $with_cpp11 = '';
    
    requires 'Alien::cmake3';
    requires 'Alien::MSYS' if $on_windows;
    #requires 'Alien::patchelf' if !($on_windows || $^O =~ /darwin/i);
    
    Alien::Build->log ("Proj library version is " . Alien::proj->version);
    die "Proj version must be at least 6.0.0"
      if not Alien::proj->atleast_version ('6.0.0');  

    plugin 'Build::SearchDep' => (
      aliens   => [grep {$_->install_type eq 'share'} @alien_deps],
      public_I => 1,
      public_l => 1,
    );
  
    start_url 'https://download.osgeo.org/gdal/CURRENT';



( run in 0.561 second using v1.01-cache-2.11-cpan-df04353d9ac )