copy_if_different在CMake中相对于copy的优势是什么?

huangapple go评论116阅读模式
英文:

What is the advantage of copy_if_different over copy in CMake?

问题

The CMake Command-Line Tools support a copy and a copy_if_different:

The copy_if_different is almost always slower because it must read the source and the target file, compare them and then copy if the contents have not been equal.

On the other hand copy will always just execute the copy part. This is slower then skipping the copy based on the files timestamps. Nevertheless it is much faster then copy_if_different.

When should I use copy and when copy_if_different?

英文:

The CMake Command-Line Tools support a copy and a copy_if_different:

The copy_if_different is almost always slower because it must read the source and the target file, compare them and then copy if the contents have not been equal.

On the other hand copy will always just execute the copy part. This is slower then skipping the copy based on the files timestamps. Nevertheless it is much faster then copy_if_different.

When should I use copy and when copy_if_different?

答案1

得分: 4

如果复制文件的时间戳相关,请使用 copy_if_different,否则请使用 copy

例如,如果您要复制的内容在另一个自定义命令的 DEPENDS 参数中提到,那么无条件地复制这些文件会触发重新构建该其他自定义命令,因为复制的时间戳会更新。如果没有更改,使用 copy_if_different 不会发生这种情况,因为目标文件不会更新。

英文:

If the timestamp of the copied file is relevant, then use copy_if_different, otherwise use copy.

E.g. if what you're copying is mentioned in the DEPENDS argument of another custom command then copying these files unconditionally triggers a re-build of that other custom command as well, as the timestamp of the copy will be newer. That will not happen with copy_if_different as the target file will not be updated if there were no changes.

huangapple
  • 本文由 发表于 2023年5月17日 18:17:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76271010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定