blib/lib/Alien/Build/Plugin/Build/CMake.pm

filter: Statementstmt 58.4% 38 / 65 Branchbran 27.2% 6 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 10 / 16 Podpod 100% 3 / 3 totaltotal 53.7% 57 / 106 CC 13 SCAR 20.8
CC
13
Cov
51%
cmake_generator
20.4
init
13.3
is_dmake
5.6
CRAP 8.0
« blib/lib/Test/Alien/Build.pm ↑ Summary example/openssl.alienfile »
1 package Alien::Build::Plugin::Build::CMake;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Capture::Tiny qw( capture );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: CMake plugin for Alien::Build
11 3 our $VERSION = '2.88'; # VERSION
12  
13  
14 sub cmake_generator
15 3 ▶{
Subroutine cmake_generator: called CC=5 SCAR=30.1
Pod documented
16 3 ▶ if($^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 3 3
17 {
18 0 ▶ return 'MinGW Makefiles' if is_dmake();
Branch: 1 branch
BranchTrueFalseTotal
if is_dmake() 0 0 0
19  
20 {
21 0 ▶ my($out, $err) = capture { system $Config{make}, '/?' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ return 'NMake Makefiles' if $out =~ /NMAKE/;
Branch: 1 branch
BranchTrueFalseTotal
if $out =~ /NMAKE/ 0 0 0
23 }
24  
25 {
26 0 ▶ my($out, $err) = capture { system $Config{make}, '--version' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 ▶ return 'MinGW Makefiles' if $out =~ /GNU Make/;
Branch: 1 branch
BranchTrueFalseTotal
if $out =~ /GNU Make/ 0 0 0
28 }
29  
30 0 die 'make not detected';
31 }
32 else
33 {
34 3 return 'Unix Makefiles';
35 }
36 }
37  
38 sub init
39 2 ▶{
Subroutine init: called CC=6 SCAR=25.9
Pod documented
40 2 my($self, $meta) = @_;
41  
42 2 ▶ $meta->prop->{destdir} = $^O eq 'MSWin32' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 2 2
43  
44 2 $meta->add_requires('configure' => 'Alien::Build::Plugin::Build::CMake' => '0.99');
45 2 $meta->add_requires('share' => 'Alien::cmake3' => '0.02');
46  
47 2 ▶ if(is_dmake())
Branch: 1 branch
BranchTrueFalseTotal
if (is_dmake()) 0 2 2
48 {
49 # even on at least some older versions of strawberry that do not
50 # use it, come with gmake in the PATH. So to save us the effort
51 # of having to install Alien::gmake lets just use that version
52 # if we can find it!
53 0 my $found_gnu_make = 0;
54  
55 0 foreach my $exe (qw( gmake make mingw32-make ))
56 {
57 0 ▶ my($out, $err) = capture { system $exe, '--version' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 ▶ if($out =~ /GNU Make/)
Branch: 1 branch
BranchTrueFalseTotal
if ($out =~ /GNU Make/) 0 0 0
59 {
60 0 ▶ $meta->interpolator->replace_helper('make' => sub { $exe });
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 0 $found_gnu_make = 1;
62 0 last;
63 }
64 }
65  
66 0 ▶ if(!$found_gnu_make)
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_gnu_make) 0 0 0
67 {
68 0 $meta->add_requires('share' => 'Alien::gmake' => '0.20');
69 0 ▶ $meta->interpolator->replace_helper('make' => sub { require Alien::gmake; Alien::gmake->exe });
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 }
71 }
72  
73 2 ▶ $meta->interpolator->replace_helper('cmake' => sub { require Alien::cmake3; Alien::cmake3->exe });
Subroutine __ANON__: called CC=1 SCAR=0.0
74 2 $meta->interpolator->add_helper('cmake_generator' => \&cmake_generator);
75  
76 2 my @args = (
77 -G => '%{cmake_generator}',
78 '-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true',
79 '-DCMAKE_INSTALL_PREFIX:PATH=%{.install.prefix}',
80 '-DCMAKE_INSTALL_LIBDIR:PATH=lib',
81 '-DCMAKE_MAKE_PROGRAM:PATH=%{make}',
82 );
83  
84 2 $meta->prop->{plugin_build_cmake}->{args} = \@args;
85  
86 2 $meta->default_hook(
87 build => [
88 ['%{cmake}', @args, '%{.install.extract}' ],
89 ['%{make}' ],
90 ['%{make}', 'install' ],
91 ],
92 );
93  
94 # TODO: handle destdir on windows ??
95 }
96  
97 3 my $is_dmake;
98  
99 sub is_dmake
100 2 ▶{
Subroutine is_dmake: called CC=4 SCAR=17.2
Pod documented
101 2 ▶ unless(defined $is_dmake)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $is_dmake) 1 1 2
102 {
103 1 ▶ if($^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1 1
104 {
105 0 ▶ my($out, $err) = capture { system $Config{make}, '-V' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 ▶ $is_dmake = $out =~ /dmake/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$out =~ /dmake/ ? : 0 0 0
107 }
108 else
109 {
110 1 $is_dmake = 0;
111 }
112 }
113  
114 2 $is_dmake;
115 }
116  
117 3 1;
118  
119 __END__
« blib/lib/Test/Alien/Build.pm ↑ Summary example/openssl.alienfile »