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-line
develop
lethosor 2016-11-02 16:23:32 -04:00
parent 4941c06654
commit 04ad7a0a42
3 changed files with 32 additions and 2 deletions

@ -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);
}

@ -239,7 +239,7 @@ ADD_CUSTOM_COMMAND(
COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto/
--cpp_out=dllexport_decl=DFHACK_EXPORT:${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/
${PROJECT_PROTOS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/depends/copy-if-different.pl
${PROJECT_PROTO_TMP_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/proto/
COMMENT "Generating core protobufs"

@ -64,7 +64,7 @@ ADD_CUSTOM_COMMAND(
-I=${CMAKE_CURRENT_SOURCE_DIR}/proto/
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto/tmp/
${PROJECT_PROTOS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/depends/copy-if-different.pl
${PROJECT_PROTO_TMP_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/proto/
COMMENT "Generating plugin protobufs"