Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare files in CMake

Tags:

cmake

Is there a way to compare files using cmake? I've checked all parameters from https://cmake.org/cmake/help/latest/command/file.html

like image 781
Amit Avatar asked Jan 24 '19 18:01

Amit


1 Answers

cmake executable has a tool mode, when it performs some useful actions instead of project's configuration. And compare_files is one of the commands for that mode.

For get features of the CMake command line tool mode in the CMakeLists.txt, use execute_process command:

execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files <file1> <file2>
                 RESULT_VARIABLE compare_result
)
if( compare_result EQUAL 0)
    message("The files are identical.")
elseif( compare_result EQUAL 1)
    message("The files are different.")
else()
    message("Error while comparing the files.")
endif()
like image 127
Tsyvarev Avatar answered Oct 19 '22 02:10

Tsyvarev