FindBoost 查找Boost的inlude目录和库

FindBoost

查找Boostinlude目录和库

用如下形式通过调用find_package使用这个模块

find_package(
Boost  [version][EXACT]   #Minimum or EXACT version e.g. 1.36.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"

该模块查找头文件和要求的组件库,或者一个通过“BoostCMake”构建提供的CMake包配置文件。对于后者情形,跳过下面的“BoostCMake”段落,对于前者,用变量报告这个结果:

Boost_FOUND                     - True if headers and requested libraries were found
Boost_INCLUDE_DIRS              - Boost include directories
Boost_LIBRARY_DIRS              - Link directories for Boost libraries
Boost_LIBRARIES                 - Boost component libraries to be linked
Boost_<C>_FOUND                 - True if component <C> was found (<C> is upper-case)
Boost_<C>_LIBRARY               - Libraries to link for component <C> (may include target_link_libraries debug/optimized keywords)
Boost_VERSION                   - BOOST_VERSION value from boost/version.hpp
Boost_LIB_VERSION               - Version string appended to library filenames
Boost_MAJOR_VERSION             - Boost major version number (X in X.y.z)
Boost_MINOR_VERSION             - Boost minor version number (Y in x.Y.z)
Boost_SUBMINOR_VERSION          - Boost subminor version number (Z in x.y.Z)
Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows)
                         -Pass to add_definitions() to have diagnostic information about Boost's automatic linking displayed during compilation

该模块从这些变量中读取关于搜索位置的提示:

BOOST_ROOT                       - Preferred installation prefix 首选安装前缀
 (or BOOSTROOT)
BOOST_INCLUDEDIR                - Preferred include directory e.g. <prefix>/include
BOOST_LIBRARYDIR                - Preferred library directory e.g. <prefix>/lib Boost_NO_SYSTEM_PATHS         - Set to ON to disable searching in locations not specified by these hint variables. Default is OFF.
Boost_ADDITIONAL_VERSIONS     -List of Boost versions not known to this module (Boost installlocations may contain the version)

并在CMakecache记录中持续(persistently)存储结果:

Boost_INCLUDE_DIR             - Directory containing Boost headers
Boost_LIBRARY_DIR_RELEASE     - Directory containing release Boost libraries
Boost_LIBRARY_DIR_DEBUG       - Directory containing debug Boost libraries
Boost_<C>_LIBRARY_DEBUG       - Component <C> library debug variant
Boost_<C>_LIBRARY_RELEASE     - Component <C> library release variant

用户可以设置这些提示或结果作为cache记录。工程项目不应直接读取这些这些记录,但可替代的是,可以使用以上结果变量。注意一些提示(hints)以大写的“BOOST”开始。如果它们没有被指定为CMake变量或者cache记录,可以指定这些变量为环境变量。



该模块首先用上面的提示变量(不包括BOOST_LIBRARYDIR)搜索Boost头文件,且存储结果于Boost_INCLUDE_DIR。然后,用上面的提示(不包括BOOST_INCLUDEDIRand Boost_ADDITIONAL_VERSIONS)搜索组建库,在Boost_INCLUDE_DIR附近的”lib”目录,库名配置设置如下。它保存库路径在Boost_LIBRARY_DIR_DEBUGBoost_LIBRARY_DIR_RELEASE中,在Boost_<C>_LIBRARY_DEBUGBoost_<C>_LIBRARY_RELEASE中单独的库位置。当在相同的构建树(不包括环境变量)中,对以前的搜索使用的设置进行改变时,该模块会弃用受以前的改变所影响的搜索结果,且再进行搜索。

Boost库开始使用用它们的文件名编码的变种。用户或者项目工程能区分这些模块,通过设置变量来寻找何种变种。:

Boost_USE_MULTITHREADED             - Set to OFF to use the non-multithreaded libraries ('mt' tag). Default is ON.
Boost_USE_STATIC_LIBS               - Set to ON to force the use of the static libraries. Default is OFF.
Boost_USE_STATIC_RUNTIME            - Set to ON or OFF to specify whether to use libraries linked statically to the C++ runtime ('s'tag). Default is platform dependent.
Boost_USE_DEBUG_RUNTIME             - Set to ON or OFF to specify whether to use libraries linked to the MS debug C++ runtime('g'tag). Default is ON.
Boost_USE_DEBUG_PYTHON              - Set to ON to use libraries compiled with a debug Python build ('y' tag). Default is OFF.
Boost_USE_STLPORT                   - Set to ON to use libraries compiled with STLPort('p' tag). Default is OFF.
Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS   -Set to ON to use libraries compiled with STLPort deprecated "native iostreams"('n'tag). Default is OFF.
Boost_COMPILER                      - Set to the compiler-specific library suffix(e.g."-gcc43"). Default is auto-computed for the C++ compiler in use.
Boost_THREADAPI                     - Suffix for "thread" component library name,such as "pthread" or "win32". Names with and without this suffix will both be tried.
Boost_NAMESPACE                     - Alternate namespace used to build boost with e.g.if set to "myboost", will search for myboost_thread instead of boost_thread.

能设置来控制该模块的的别的一些变量是:

Boost_DEBUG                  - Set to ON to enable debug output from FindBoost. Please enable this before filing any bug report.
Boost_DETAILED_FAILURE_MSG   -Set to ON to add detailed information to the failure message even when the REQUIRED option is not given to the find_package call.
Boost_REALPATH               - Set to ON to resolve symlinks for discovered libraries to assist with packaging. For example,the "system" component library may be resolved to   
                        "/usr/lib/libboost_system.so.1.42.0" instead of "/usr/lib/libboost_system.so". This does not affect linking and should not be enabled unless the user                                 needs this information.
Boost_LIBRARY_DIR             - Default value for Boost_LIBRARY_DIR_RELEASE and Boost_LIBRARY_DIR_DEBUG.

对于VisualStudioBorland编译器,Boostheaders要求自动链接到相应的库。这要求匹配的库在链接库搜索路径中时能隐式链接或者有效。在这种情形中,设置Boost_USE_STATIC_LIBSOFF可能不会取得动态链接。典型的Boost自动链接要求静态库,有些例外(诸如Boost.Python).

使用:

add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})

来要求Boost去报告关于自动链接请求的信息。

仅仅查找Boostheaders的例子:

find_package(Boost 1.36.0)
if(Boost_FOUND)     include_directories(${Boost_INCLUDE_DIRS})     add_executable(foo foo.cc)
endif()

寻找Boostheaders和一些静态库的例子:

set(Boost_USE_STATIC_LIBS  ON)         # only find static libs
set(Boost_USE_MULTITHREADED  ON)
set(Boost_USE_STATIC_RUNTIME  OFF)
find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...)
if(Boost_FOUND)     include_directories(${Boost_INCLUDE_DIRS})     add_executable(foo foo.cc)     target_link_libraries(foo ${Boost_LIBRARIES})
endif()

BoostCMake

如果Boost使用boost-cmake项目工程来构建,它用一个find_package的配置模式为使用提供一个包配置文件。这个模块寻找称之为BoostConfig.cmakeor boost-config.cmake的包配置文件,且在cache记录“Boost_DIR”中存储结果。如果找到,加载包配置文件,这个模块没有返回进一步的动作。要详细了解,请见BoostCMake包配置的文档。

Boost_NO_BOOST_CMAKEON将禁止对boost-cmake的搜索。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值