File Coverage

alienfile
Criterion Covered Total %
statement 17 18 94.4
branch 1 2 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod n/a
total 24 28 85.7


line stmt bran cond sub pod time code
1 1     1   187687 use alienfile;
  1         4  
  1         6  
2              
3 1     1   144 use Config;
  1         1  
  1         23  
4 1     1   5 use File::Spec;
  1         1  
  1         17  
5 1     1   3 use version;
  1         2  
  1         7  
6              
7             # NOTE: you can set ALIEN_CMAKE_FROM_SOURCE to force a build from source
8             # even on platforms which have binary versions of cmake available. Normally
9             # you should only need this for testing the build from source capability of
10             # this alienfile.
11              
12             plugin 'Probe::CommandLine' => (
13             command => 'cmake',
14             args => ['--version'],
15             match => qr/^cmake\s+version\s+4\.[0-9\.]+/m,
16             version => qr/^cmake\s+version\s+(4\.[0-9\.]+)/,
17             );
18              
19             share {
20             my $binary_release_name;
21             my $binary_format;
22              
23             if ($^O eq 'linux') {
24             my $linux_binary_ok = _glibc_at_least('2.17');
25             if ($linux_binary_ok) {
26             if ($Config{'archname'} =~ /^x86_64/) {
27             $binary_release_name = 'linux-x86_64';
28             $binary_format = 'tar.gz';
29             } elsif ($Config{'archname'} =~ /^aarch64/) {
30             $binary_release_name = 'linux-aarch64';
31             $binary_format = 'tar.gz';
32             }
33             }
34             } elsif ($^O eq 'MSWin32' && $Config{'ptrsize'} == 4) {
35             $binary_release_name = 'windows-i386';
36             $binary_format = 'zip';
37             } elsif ($^O eq 'MSWin32' && $Config{'ptrsize'} == 8) {
38             $binary_release_name = 'windows-x86_64';
39             $binary_format = 'zip';
40             } elsif ($^O eq 'darwin' && $Config{'ptrsize'} == 8) {
41             my ($major, $minor, $patch) = map {
42             my $v = $_;
43             $v =~ s/^\s+//;
44             $v =~ s/\s+$//;
45             $v;
46             } split /\./, [split /:/, `sw_vers|grep ProductVersion`]->[1];
47             if ($major >= 11 || ($major == 10 && $minor >= 13)) {
48             $binary_release_name = 'macos-universal';
49             } else {
50             $binary_release_name = 'macos10.10-universal';
51             }
52             $binary_format = 'tar.gz';
53             }
54              
55             # For platforms where there is a binary release, use that:
56             if ($binary_release_name && ! $ENV{ALIEN_CMAKE_FROM_SOURCE}) {
57             start_url 'https://cmake.org/files/v4.3';
58             plugin Download => (
59             filter => qr/^cmake-4\.[0-9\.]+-\Q$binary_release_name\E\.\Q$binary_format\E$/,
60             version => qr/([0-9\.]+)/,
61             ($^O eq 'MSWin32' ? (bootstrap_ssl => 1) : ()),
62             );
63             plugin Extract => $binary_format;
64             if ($^O eq 'MSWin32') {
65             build sub {
66             my $build = shift;
67             # This is a rare case where we actually want the borked windows
68             # type paths with backslashes.
69             my $stage = File::Spec->catdir($build->install_prop->{stage});
70             path($stage)->mkpath unless -d $stage;
71             $build->system("xcopy . $stage /E");
72             };
73             } elsif ($^O eq 'darwin') {
74             build [
75             'cp -a CMake.app/Contents/* %{.install.stage}',
76             sub { shift->runtime_prop->{style} = 'binary' },
77             ];
78             } else {
79             build [
80             'cp -ar * %{.install.stage}',
81             sub { shift->runtime_prop->{style} = 'binary' },
82             ];
83             }
84              
85             # For platforms without a (recent) binary release, build it from source.
86             } else {
87             start_url 'https://cmake.org/download/';
88             plugin Download => (
89             filter => qr/^cmake-4\.[0-9\.]+\.tar.gz$/,
90             version => qr/([0-9\.]+)/,
91             );
92             plugin Extract => 'tar.gz';
93             plugin 'Build::Autoconf' => ('with_pic' => 0);
94             build [
95             '%{configure}',
96             '%{make}',
97             '%{make} install',
98             sub { shift->runtime_prop->{style} = 'source' },
99             ];
100             }
101              
102             after 'gather' => sub {
103             my $build = shift;
104              
105             $build->runtime_prop->{'command'} = 'cmake';
106             };
107             };
108              
109             sub _glibc_at_least {
110 1     1   1 my $need = shift;
111              
112 1         6113 my $out = `getconf GNU_LIBC_VERSION 2>/dev/null`;
113 1 50 33     66 if (! defined $out || $out !~ /glibc\s+([0-9.]+)/) {
114 0         0 return 0;
115             }
116 1         15 my $glibc_version = $1;
117              
118 1         162 return version->parse("v$glibc_version") >= version->parse("v$need");
119             }
120