问题描述
我经常使用Boost,但是每次尝试使用Boost时,我都会对应该在cmake中添加的Boost模块的名称感到怀疑。
例如,在我上一个项目中,我想使用boost::concurrent::sync_queue
,但我在任何地方都找不到模块的名称。我终于找到了已经使用它的随机github项目,偶然地发现了它,所以我只看了CMakeLists.txt
。
最后我得到了这一行:
find_package(Boost 1.70 required COMPONENTS thread )
但是首先我尝试过:
find_package(Boost 1.70 required COMPONENTS concurrent )
find_package(Boost 1.70 required COMPONENTS threading )
find_package(Boost 1.70 required COMPONENTS threads )
正如我在所有项目中都记得的那样,这是cmake最令人沮丧的阶段之一。 我发现this site,但是cmake中只有可用的标志/选项。
您有没有设置/列出/索引或提示如何将使用的类/功能从boost链接到所需组件? 如果这样的索引与增强版本有关,那将是无价且非常方便的。
解决方法
来自CMake\share\cmake-3.*\Modules\FindBoost.cmake
:
FindBoost
---------
Find Boost include dirs and libraries
Use this module by invoking find_package with the form::
find_package(Boost
[version] [EXACT] # Minimum or EXACT version e.g. 1.67.0
[REQUIRED] # Fail with error if Boost is not found
[COMPONENTS <libs>...] # Boost libraries by their canonical name
# e.g. "date_time" for "libboost_date_time"
[OPTIONAL_COMPONENTS <libs>...]
# Optional Boost libraries by their canonical name)
) # e.g. "date_time" for "libboost_date_time"
它说要使用:
按规范名称增强库,例如“ date_time”代表“ libboost_date_time”