diff --git a/depends/copy-if-different.pl b/depends/copy-if-different.pl new file mode 100755 index 000000000..2ba08a80e --- /dev/null +++ b/depends/copy-if-different.pl @@ -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); +} diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index ed5bfdcd2..9f8477993 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -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" diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 612a49715..8546c6e89 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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"