How to compare files in CMake

旧巷老猫 提交于 2020-06-15 06:45:27

问题


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


回答1:


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()


来源:https://stackoverflow.com/questions/54353120/how-to-compare-files-in-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!