File Coverage

alienfile
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1 1     1   236721 use alienfile;
  1         4  
  1         7  
2 1     1   177 use Config;
  1         1  
  1         31  
3 1     1   4 use File::Which qw( which );
  1         1  
  1         40  
4 1     1   4 use Path::Tiny qw( path );
  1         3  
  1         32  
5 1     1   4 use Capture::Tiny qw( capture );
  1         1  
  1         33  
6 1     1   4 use File::Spec;
  1         1  
  1         1283  
7              
8             # NOTE: you can set ALIEN_CMAKE_FROM_SOURCE to force a build from source
9             # even on platforms which have binary versions of cmake available. Normally
10             # you should only need this for testing the build from source capability of
11             # this alienfile.
12              
13             configure {
14             requires 'Alien::Build' => '0.92';
15             requires 'File::Which';
16             requires 'Path::Tiny';
17             requires 'Capture::Tiny';
18             };
19              
20             probe sub {
21             my($build) = @_;
22             my $old_cmake = $build->install_prop->{my_old_cmake} = which 'cmake';
23            
24             if($old_cmake)
25             {
26             $build->log("found existing cmake: $old_cmake");
27             my $old_cmake_version = $build->install_prop->{my_old_cmake_version} = do {
28             my($out, undef, $old_cmake) = capture { system $old_cmake, '--version' };
29             $out =~ /cmake version ([0-9\.]+)/
30             ? $1
31             : undef;
32             };
33             if($old_cmake_version)
34             {
35             my($major) = $old_cmake_version =~ /^([0-9])\./;
36             if($major == 3)
37             {
38             $build->install_prop->{my_old_cmake_use} = 1;
39             $build->log("GOOD found cmake version $old_cmake_version");
40             return 'system' unless $ENV{ALIEN_CMAKE_FROM_SOURCE};
41             }
42             elsif ($major > 3)
43             {
44             $build->log("TOO NEW found cmake version $old_cmake_version");
45             }
46             else
47             {
48             $build->log("TOO OLD found cmake version $old_cmake_version");
49             }
50             }
51             else
52             {
53             $build->log("BAD unable to determine cmake version");
54             }
55             }
56             else
57             {
58             $build->log("no existing cmake found");
59             }
60            
61             'share';
62             };
63              
64             my $binary_release_name;
65             my $binary_format;
66              
67             # use binary release on Linux, Windws 32/64 bit
68             # do not use binary release on OS X as it comes as a .app bundle
69             # TODO: add aarch64 detection
70             if($^O eq 'linux' && $Config{archname} =~ /^x86_64/)
71             {
72             $binary_release_name = 'linux-x86_64';
73             $binary_format = 'tar.gz';
74             }
75             elsif($^O eq 'linux' && $Config{archname} =~ /^aarch64/)
76             {
77             $binary_release_name = 'linux-aarch64';
78             $binary_format = 'tar.gz';
79             }
80             elsif($^O eq 'MSWin32' && $Config{ptrsize} == 4)
81             {
82             $binary_release_name = 'windows-i386';
83             $binary_format = 'zip';
84             }
85             elsif($^O eq 'MSWin32' && $Config{ptrsize} == 8)
86             {
87             $binary_release_name = 'windows-x86_64';
88             $binary_format = 'zip';
89             }
90             elsif($^O eq 'darwin' && $Config{ptrsize} == 8)
91             {
92             my($major, $minor, $patch) = map {
93             my $v = $_;
94             $v =~ s/^\s+//;
95             $v =~ s/\s+$//;
96             $v;
97             } split /\./, [split /:/, `sw_vers|grep ProductVersion`]->[1];
98             if($major >= 11 || ($major == 10 && $minor >= 13))
99             {
100             $binary_release_name = 'macos-universal';
101             }
102             else
103             {
104             $binary_release_name = 'macos10.10-universal';
105             }
106             $binary_format = 'tar.gz';
107             }
108              
109             share {
110              
111              
112             # For platforms where there is a binary release, use that:
113             if($binary_release_name && !$ENV{ALIEN_CMAKE_FROM_SOURCE})
114             {
115             start_url 'https://cmake.org/files/v3.31/';
116             plugin Download => (
117             filter => qr/^cmake-3\.[0-9\.]+-\Q$binary_release_name\E\.\Q$binary_format\E$/,
118             version => qr/([0-9\.]+)/,
119             ($^O eq 'MSWin32' ? (bootstrap_ssl => 1) : ()),
120             );
121             plugin Extract => $binary_format;
122             if($^O eq 'MSWin32')
123             {
124             build sub {
125             my($build) = @_;
126             # This is a rare case where we actually want the borked windows
127             # type paths with backslashes
128             my $stage = File::Spec->catdir($build->install_prop->{stage});
129             path($stage)->mkpath unless -d $stage;
130             $build->system("xcopy . $stage /E");
131             };
132             }
133             elsif($^O eq 'darwin')
134             {
135             build [
136             'cp -a CMake.app/Contents/* %{.install.stage}',
137             sub { shift->runtime_prop->{style} = 'binary' },
138             ];
139             }
140             else
141             {
142             build [
143             'cp -ar * %{.install.stage}',
144             sub { shift->runtime_prop->{style} = 'binary' },
145             ];
146             }
147             }
148            
149             # For platforms without a (recent) binary release, build it from source
150             else
151             {
152             start_url 'https://cmake.org/download/';
153             plugin Download => (
154             filter => qr/^cmake-3\.[0-9\.]+\.tar.gz$/,
155             version => qr/([0-9\.]+)/,
156             );
157             plugin Extract => 'tar.gz';
158              
159             # CONSIDER: in the case where there is an older version of cmake
160             # found in the probe step above (stored in my_old_cmake), using
161             # the older version of cmake to build cmake instead of using the
162             # autoconf compat script.
163             plugin 'Build::Autoconf' => ( with_pic => 0 );
164             build [
165             '%{configure}',
166             '%{make}',
167             '%{make} install',
168             sub { shift->runtime_prop->{style} = 'source' },
169             ];
170             }
171            
172             gather sub {
173             my($build) = @_;
174             $build->runtime_prop->{command} = 'cmake';
175             };
176              
177             };
178              
179             sys {
180             gather sub {
181             my($build) = @_;
182             $build->runtime_prop->{version} = $build->install_prop->{my_old_cmake_version};
183             $build->runtime_prop->{command} = $build->install_prop->{my_old_cmake};
184             $build->runtime_prop->{style} = "system";
185             };
186             };