diff --git a/Help/command/file.rst b/Help/command/file.rst index d47d5173e7..56a572495a 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -28,6 +28,7 @@ Synopsis file(`STRINGS`_ [...]) file(`\`_ ) file(`TIMESTAMP`_ [...]) + file(`DIFFERENT`_ FILES ) `Writing`_ file({`WRITE`_ | `APPEND`_} ...) @@ -160,6 +161,16 @@ Reading See the :command:`string(TIMESTAMP)` command for documentation of the ```` and ``UTC`` options. +.. signature:: + file(DIFFERENT FILES ) + + Compare the contents of ```` and ```` byte for byte and + store true in ```` if they differ, or false if they are the + same. If either file does not exist, or an error occurs while comparing + the files, the files are considered different. Relative paths are + evaluated with respect to the current working directory rather than the + current source directory, so absolute paths are recommended. + Writing ^^^^^^^ diff --git a/Tests/RunCMake/file/DIFFERENT.cmake b/Tests/RunCMake/file/DIFFERENT.cmake new file mode 100644 index 0000000000..bf78c7be34 --- /dev/null +++ b/Tests/RunCMake/file/DIFFERENT.cmake @@ -0,0 +1,24 @@ +set(a "${CMAKE_CURRENT_BINARY_DIR}/a.txt") +set(b "${CMAKE_CURRENT_BINARY_DIR}/b.txt") +set(c "${CMAKE_CURRENT_BINARY_DIR}/c.txt") +set(d "${CMAKE_CURRENT_BINARY_DIR}/d.txt") +set(missing "${CMAKE_CURRENT_BINARY_DIR}/missing.txt") +file(CONFIGURE OUTPUT "${a}" CONTENT "same\n" NEWLINE_STYLE LF) +file(CONFIGURE OUTPUT "${b}" CONTENT "same\n" NEWLINE_STYLE LF) +file(CONFIGURE OUTPUT "${c}" CONTENT "same\n" NEWLINE_STYLE CRLF) +file(CONFIGURE OUTPUT "${d}" CONTENT "diff\n" NEWLINE_STYLE LF) +file(REMOVE "${missing}") + +file(DIFFERENT result FILES "${a}" "${b}") +if(result) + message(SEND_ERROR "Identical files reported as different") +endif() + +foreach(pair IN ITEMS "a;c" "a;d" "a;missing" "missing;a" "missing;missing") + list(GET pair 0 lhs) + list(GET pair 1 rhs) + file(DIFFERENT result FILES "${${lhs}}" "${${rhs}}") + if(NOT result) + message(SEND_ERROR "Files ${lhs} and ${rhs} reported as same") + endif() +endforeach() diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake index 3771db4aba..6a6adebe48 100644 --- a/Tests/RunCMake/file/RunCMakeTest.cmake +++ b/Tests/RunCMake/file/RunCMakeTest.cmake @@ -42,6 +42,8 @@ run_cmake(TIMESTAMP) run_cmake(REMOVE-empty) +run_cmake_script(DIFFERENT) + run_cmake_script(COPY_FILE-file-replace) run_cmake_script(COPY_FILE-dir-to-file-capture) run_cmake_script(COPY_FILE-dir-to-file-fail)