package Alien::Build::Plugin::Build::CMake;
use strict;
use warnings;
use 5.008004;
use Config;
use Alien::Build::Plugin;
use Capture::Tiny qw( capture );
# ABSTRACT: CMake plugin for Alien::Build
our $VERSION = '2.84'; # VERSION
sub cmake_generator
{
if($^O eq 'MSWin32')
{
return 'MinGW Makefiles' if is_dmake();
{
my($out, $err) = capture { system $Config{make}, '/?' };
return 'NMake Makefiles' if $out =~ /NMAKE/;
}
{
my($out, $err) = capture { system $Config{make}, '--version' };
return 'MinGW Makefiles' if $out =~ /GNU Make/;
}
die 'make not detected';
}
else
{
return 'Unix Makefiles';
}
}
sub init
{
my($self, $meta) = @_;
$meta->prop->{destdir} = $^O eq 'MSWin32' ? 0 : 1;
$meta->add_requires('configure' => 'Alien::Build::Plugin::Build::CMake' => '0.99');
$meta->add_requires('share' => 'Alien::cmake3' => '0.02');
if(is_dmake())
{
# even on at least some older versions of strawberry that do not
# use it, come with gmake in the PATH. So to save us the effort
# of having to install Alien::gmake lets just use that version
# if we can find it!
my $found_gnu_make = 0;
foreach my $exe (qw( gmake make mingw32-make ))
{
my($out, $err) = capture { system $exe, '--version' };
if($out =~ /GNU Make/)
{
$meta->interpolator->replace_helper('make' => sub { $exe });
$found_gnu_make = 1;
last;
}
}
if(!$found_gnu_make)
{
$meta->add_requires('share' => 'Alien::gmake' => '0.20');
$meta->interpolator->replace_helper('make' => sub { require Alien::gmake; Alien::gmake->exe });
}
}
$meta->interpolator->replace_helper('cmake' => sub { require Alien::cmake3; Alien::cmake3->exe });
$meta->interpolator->add_helper('cmake_generator' => \&cmake_generator);
my @args = (
-G => '%{cmake_generator}',
'-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true',
'-DCMAKE_INSTALL_PREFIX:PATH=%{.install.prefix}',
'-DCMAKE_INSTALL_LIBDIR:PATH=lib',
'-DCMAKE_MAKE_PROGRAM:PATH=%{make}',
);
$meta->prop->{plugin_build_cmake}->{args} = \@args;
$meta->default_hook(
build => [
['%{cmake}', @args, '%{.install.extract}' ],
['%{make}' ],
['%{make}', 'install' ],
],
);
# TODO: handle destdir on windows ??
}
my $is_dmake;
sub is_dmake
{
unless(defined $is_dmake)
{
if($^O eq 'MSWin32')
{
my($out, $err) = capture { system $Config{make}, '-V' };
$is_dmake = $out =~ /dmake/ ? 1 : 0;
}
else
{
$is_dmake = 0;
}
}
$is_dmake;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::Build::CMake - CMake plugin for Alien::Build
=head1 VERSION
version 2.84
=head1 SYNOPSIS
use alienfile;
share {
plugin 'Build::CMake';
build [
# this is the default build step, if you do not specify one.
[ '%{cmake}',
@{ meta->prop->{plugin_build_cmake}->{args} },
# ... put extra cmake args here ...
'%{.install.extract}'
],
'%{make}',
'%{make} install',
];
};
=head1 DESCRIPTION
This plugin helps build alienized projects that use C