From 04ad7a0a42fedd3a0a33c4c0b2c9380f1341b900 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 2 Nov 2016 16:23:32 -0400 Subject: [PATCH] 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 --- depends/copy-if-different.pl | 30 ++++++++++++++++++++++++++++++ library/CMakeLists.txt | 2 +- plugins/CMakeLists.txt | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100755 depends/copy-if-different.pl 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"