英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论