use alienfile;
use Env qw( @PATH );
use File::Which qw( which );
use Path::Tiny qw( path );

configure {
  requires 'File::Which';
  requires 'Path::Tiny';
};

my @cmake_flags;

if($^O eq 'darwin')
{
  unless(which 'llvm-config')
  {
    if(-d "/usr/local/Cellar/llvm")
    {
      foreach my $dir (path("/usr/local/Cellar/llvm")->children)
      {
        my $path = $dir->child('lib/cmake/llvm');
        if(-d $path)
        {
          push @cmake_flags, "-DLLVM_DIR=$path";
        }
      }
    }
  }
}

plugin 'Probe::CommandLine' => (
  command => 'castxml',
  args    => ['--version'],
  match    => qr/castxml version/,
  version  => qr/castxml version (\S+)/,
);

share {
  plugin 'Download::GitHub' => (
    github_user => 'castxml',
    github_repo => 'castxml',
  );
  plugin Extract => 'tar.gz';
  plugin 'Build::CMake';

  build [
    [
      '%{cmake}',
      @cmake_flags,
      @{ meta->prop->{plugin_build_cmake}->{args} },
      '%{.install.extract}',
    ],
    '%{make}',
    '%{make} install',
  ]
};


