Replace some instances of "cmake -E copy_if_different" with a standalone script
@JapaMala reported that CMake < 3.5 doesn't support copy_if_different with multiple source files. https://cmake.org/cmake/help/v3.5/release/3.5.html#command-linedevelop
parent
4941c06654
commit
04ad7a0a42
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# A replacement for "cmake -E copy_if_different" that supports multiple files,
|
||||||
|
# which old cmake versions do not support
|
||||||
|
|
||||||
|
# Usage: copy-if-different.pl src-file [src-file...] dest-dir
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Digest::SHA;
|
||||||
|
use File::Basename;
|
||||||
|
use File::Copy;
|
||||||
|
|
||||||
|
sub sha_file {
|
||||||
|
my $filename = shift;
|
||||||
|
my $sha = Digest::SHA->new(256);
|
||||||
|
$sha->addfile($filename);
|
||||||
|
return $sha->hexdigest;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $dest_dir = pop @ARGV or die "no destination dir";
|
||||||
|
-d $dest_dir or die "not a directory: $dest_dir";
|
||||||
|
my @src_files = @ARGV or die "no source files";
|
||||||
|
|
||||||
|
foreach my $file (@src_files) {
|
||||||
|
my $dest = "$dest_dir/" . basename($file);
|
||||||
|
next if -f $dest && sha_file($file) eq sha_file($dest);
|
||||||
|
copy($file, $dest);
|
||||||
|
}
|
Loading…
Reference in New Issue