[英]How and when to make use of the cmake 3.18 option Boost_NO_BOOST_CMAKE?
The Cmake 3.18 official documentation states: Cmake 3.18 官方文档指出:
If Boost was built using the boost-cmake project or from Boost 1.70.0 on it provides a package configuration file for use with find_package's config mode.
如果 Boost 是使用 boost-cmake 项目或从 Boost 1.70.0 构建的,它会提供一个 package 配置文件,用于 find_package 的配置模式。 This module looks for the package configuration file called BoostConfig.cmake or boost-config.cmake and stores the result in CACHE entry “Boost_DIR”.
该模块查找名为 BoostConfig.cmake 或 boost-config.cmake 的 package 配置文件,并将结果存储在缓存条目“Boost_DIR”中。 If found, the package configuration file is loaded and this module returns with no further action.
如果找到,则加载 package 配置文件,此模块将返回,无需进一步操作。 See documentation of the Boost CMake package configuration for details on what it provides.
有关其提供的详细信息,请参阅 Boost CMake package 配置的文档。
Set Boost_NO_BOOST_CMAKE to ON, to disable the search for boost-cmake.
将 Boost_NO_BOOST_CMAKE 设置为 ON,以禁用对 boost-cmake 的搜索。
It may make sense for experts in cmake, but as this explanation lacks broader context explanation, it does not really help the cmake beginner.对于 cmake 的专家来说可能有意义,但由于这种解释缺乏更广泛的上下文解释,因此对 cmake 初学者并没有真正的帮助。
Could someone expand on this documentation?有人可以扩展此文档吗? For example, why to set Boost_NO_CMAKE to ON, when the default behavior could be problematic, and how to set the option for best practice?
例如,为什么要将 Boost_NO_CMAKE 设置为 ON,什么时候默认行为可能会出现问题,以及如何设置最佳实践选项?
For example, there are some basic explanations here on the fact that Boost 1.70 comes with a new way of using Boost with CMake, that is making use of the Boost BoostConfig.cmake rather than the one coming from the CMake distribution.例如, 这里有一些基本解释,即 Boost 1.70 提供了一种使用 Boost 和 CMake 的新方法,即使用 Boost BoostConfig.cmake 而不是来自 ZDF4716ADAB93B948E0B1098E0B10 发行版。
Old way:老办法:
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost REQUIRED COMPONENTS thread timer)
include_directories(${Boost_INCLUDE_DIRS}
...)
link_directories(${Boost_LIBRARY_DIRS}
...)
target_link_libraries(...
${Boost_LIBRARIES}
...)
New way:新的方法:
set(Boost_NO_BOOST_CMAKE OFF)
find_package(Boost REQUIRED COMPONENTS thread timer)
target_link_libraries(...
Boost::thread
Boost::timer
...)
Expanding on this information (for example how to make the changes when we don't have control of the code projects, or how to ensure retro-compatibility) would definitely be useful for non-experts in cmake.扩展此信息(例如,当我们无法控制代码项目时如何进行更改,或如何确保追溯兼容性)对于 cmake 中的非专家肯定有用。
When Boost wasn't supporting CMake officially, the latter had its own FindBoost.cmake
module.当Boost官方不支持CMake时,后者有自己的
FindBoost.cmake
模块。 With every Boost release, the CMake team ought to fix it for the latest Boost version and some other things, so the updated module get available only w/ next CMake release.对于每个 Boost 版本,CMake 团队应该为最新的 Boost 版本和其他一些东西修复它,因此更新的模块仅在下一个 CMake 版本中可用。 The shipped module used in Module Mode of the
find_package
dedicated to packages w/o full-functional CMake support.在
find_package
的模块模式中使用的发货模块专用于没有全功能 CMake 支持的包。
Since (relatively) recently, Boost has its official CMake support providing the BoostConfig.cmake
module used by find_package
in Config Mode .由于(相对)最近,Boost 拥有其官方 CMake 支持,提供
BoostConfig.cmake
模块,供find_package
在Config Mode中使用。 However, depending on CMake settings, the used find_package
signature and Boost version(s) installed the find result may vary.但是,根据 CMake 设置,使用的
find_package
签名和安装的 Boost 版本可能会有所不同。
The Boost_NO_BOOST_CMAKE
prevents the FindBoost.cmake
module from use of BoostConfig.cmake
. Boost_NO_BOOST_CMAKE
防止FindBoost.cmake
模块使用BoostConfig.cmake
。 Meaning that whatever Boost version installed and found, even if it has the "native" CMake support -- FindBoost.cmake
should ignore it (ie, the module, not the found result).这意味着无论安装和找到什么 Boost 版本,即使它具有“本机”CMake 支持
FindBoost.cmake
都应该忽略它(即模块,而不是找到的结果)。
Why?为什么? Because even if the CMake team tries to keep its
FindBoost.cmake
backward compatible w/ older CMake/Boost releases and synchronized w/ the modern Boost at the same time there is a possibility to face with a difference in their behavior.因为即使 CMake 团队试图保持其
FindBoost.cmake
与旧版 CMake/Boost 版本向后兼容并同时与现代 Boost 同步,也有可能面临他们行为上的差异。 To give a user (who cares about compatibility) the full control over what and how to find (via FindBoost.cmake
) the mentioned variable has added.为了让用户(关心兼容性)完全控制查找内容和查找方式(通过
FindBoost.cmake
),添加了上述变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.