始终在cmakelists.txt的顶部添加cmake_minimum_requred是安全/好练习吗?
Cmake newbie在这里,很抱歉问一些太微不足道的东西...
始终添加cmake_minimum_required(版本...)
在顶级cmakelists.txt文件上是安全的吗?假设有一个大项目分为子项目,每个项目都有自己的cmakelists.txt文件。
cmakelists.txt文件在这种情况下看起来
add_subdirectory(subproject_1)
...
add_subdirectory(subproject_n)
应该添加在顶部吗?应该跳过吗? 毕竟,这项工作是由subproject cmakelist.txt文件完成的,因此我没有看到这样做的理由,除非“每个人都这样做”,否则我不确定是这样。
谢谢。
CMake newbie here, sorry for asking something too trivial...
Is it safe to always add cmake_minimum_required(VERSION ...)
on top CMakeLists.txt file? Suppose there is a one big project dividided into subproject, each one with it's own CMakeLists.txt file.
CMakeLists.txt file in this case looks something like
add_subdirectory(subproject_1)
...
add_subdirectory(subproject_n)
should cmake_minimum_required(VERSION ...)
still be added on top? Should it be skipped?
After all, the work is done by subproject CMakeList.txt files, so I do not see a reason to do it, unless "everybody does it" which I am not sure is the case.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它总是安全的,尽管当您想升级基线时,经过并碰到所有版本会很烦人(这应该经常发生)。您应该在单个项目中使用一致的策略集。
对于那些打算是可构建独立的子项目(即它们在顶部具有
project()
),这是一个很难的要求。 Cmake执行的第一个语句应始终 becmake_minimum_required
。It is always safe, though it will be annoying to go through and bump all of the versions when you want to upgrade your baseline (which should happen frequently). You should use a consistent policy set within a single project.
For those subprojects which are intended to be buildable standalone (i.e. they have
project()
at the top), it is a hard requirement. The first statement executed by CMake should always becmake_minimum_required
.