use alienfile;

plugin PkgConfig => 'liblz4';

share {
  plugin 'Download::GitHub' => (
    github_user => 'lz4',
    github_repo => 'lz4',
  );
  plugin 'Build::CMake';
  # Disable building `lz4` tool for now as it is dynamically linked by default
  # by the CMake build.
  my $build_tool = 0;
  my $build_dir = '_build';
  build [
    ['%{cmake}',
      @{ meta->prop->{plugin_build_cmake}->{args} },

      (
        qw(-DLZ4_BUILD_CLI=ON),     # tool
      )x!!( $build_tool ),
      qw(-DBUILD_STATIC_LIBS=ON), # xs
      qw(-DBUILD_SHARED_LIBS=ON), # ffi

      qw(-S), '%{.install.extract}/build/cmake',
      qw(-B), $build_dir,
    ],
    [ '%{make}', qw( -C ), $build_dir ],
    [ '%{make}', qw( -C ), $build_dir, 'install' ],
  ];
  plugin 'Gather::IsolateDynamic';
}
