Alien-proj

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

    @PKG_CONFIG_PATH
      = map {my $r=$_; $r=~s{Alien-curl[/\\]lib[/\\]pkgconfig}{Alien-curl/dynamic/pkgconfig}i; $r}
        @PKG_CONFIG_PATH;
    $ENV{PKG_CONFIG_PATH} = join ':', @PKG_CONFIG_PATH;
    say $ENV{PKG_CONFIG_PATH};
    return;
}

sub pause {
    return;  #  re-enable in case of debug
    return if $on_automated_rig;
    return if !$on_windows;

    say "CONTINUE?";
    my $response = <>;
    while (not $response =~ /yes/) {
        $response = <>;
    }
}

sub update_cmake_lists_file {
    my ($orig, $build, @args) = @_;

    #  only needed on windows for v9.0.0 or earlier
    return $orig->($build, @args)
      if $on_windows and versioncmp (get_proj_version(), '9.0.0') < 0; 

    $build->log ('updating CMakeLists.txt to properly handle proj.pc');
    
    #my $h = $build->install_prop;
    #use Data::Printer;
    #p $h;
    
    use File::Find::Rule;
    my ($cmake_lists_file)
      = File::Find::Rule
                ->file()
                ->name( 'CMakeLists.txt' )
                ->in( $build->install_prop->{extract} );
    #$build->log ("====\ncmake file: $cmake_lists_file \n ====");
    open my $fh , '<', $cmake_lists_file
      or die "Could not open $cmake_lists_file for reading, $!";
    my $file_contents;

    my $define_check = <<EOD
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  set(CMAKE_INSTALL_LIBDIR lib)
endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
EOD
  ;
  
    while (my $line = <$fh>) {
        if ($line =~ /^\s*configure_proj_pc/) {
#say STDERR "ADDING TO CMAKE LISTS"; 
          $line .= $define_check;
        }
        $file_contents .= $line;
    }
    $fh->close;

    rename $cmake_lists_file, "$cmake_lists_file.bak";
    open my $ofh, '>', $cmake_lists_file
      or die "Could not open $cmake_lists_file for writing, $!";
    print {$ofh} $file_contents;
    $ofh->close or die $!;

    $orig->($build, @args);
}


sub find_lib_file {
  my %args = @_;
  
  my(@lib_files) = find_lib(
      %args,
      systempath => $args{alien} ? [] : undef,  #  only search the alien if one is passed
  );
  #  we grab the first, assuming they are
  #  all the same or point to the same origin
  my $libfile = $lib_files[0];
  $libfile =~ s|\\|/|g if $on_windows;
  Alien::Build->log ("Found $args{lib} dynamic lib: $libfile");
  return $libfile;
}

sub get_proj_version {
    my $h = get_alien_state_hash();
    return $h->{runtime}{version};
}

sub get_alien_state_hash {
    use JSON::PP;
    my $root = "$base_dir/_alien";
    my $f = "$root/state.json";
    my $h = {};
    if (-e $f) {
        open my $fh, '<', $f or die $!;
        my $d = do {
            local $/ = undef;
            <$fh>;
        };
        $h = JSON::PP::decode_json($d);
    }
    return $h;
}



( run in 1.561 second using v1.01-cache-2.11-cpan-2398b32b56e )