如何在CMake中比较文件 [英] How to compare files in CMake

查看:92
本文介绍了如何在CMake中比较文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用cmake比较文件?
我已经检查了 https://cmake.org中的所有参数/cmake/help/latest/command/file.html

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

推荐答案

cmake 可执行文件具有工具模式,当它执行一些有用的操作而不是项目的配置时。而 compare_files 是该模式的命令之一。

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.

用于获取CMake命令行工具模式的功能 CMakeLists.txt ,使用 execute_process 命令:

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

这篇关于如何在CMake中比较文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆