Boost¶
# Header-only libraries
hunter_add_package(Boost)
find_package(Boost CONFIG REQUIRED)
target_link_libraries(... Boost::boost)
Since boost 1.70 you should use for header only libraries as target:
target_link_libraries(... Boost::headers)
# Boost components (see list below)
hunter_add_package(Boost COMPONENTS system filesystem)
find_package(Boost CONFIG REQUIRED system filesystem)
target_link_libraries(... Boost::system Boost::filesystem)
Examples:
List of components and availability (other libraries are header-only):
hunter_append_component(${common_args} COMPONENT atomic SINCE 1.53.0)
hunter_append_component(${common_args} COMPONENT chrono SINCE 1.47.0)
hunter_append_component(${common_args} COMPONENT container SINCE 1.56.0)
hunter_append_component(${common_args} COMPONENT context SINCE 1.51.0)
hunter_append_component(${common_args} COMPONENT contract SINCE 1.67.0)
hunter_append_component(${common_args} COMPONENT coroutine SINCE 1.53.0)
hunter_append_component(${common_args} COMPONENT coroutine2 SINCE 1.60.0 UNTIL 1.65.0)
hunter_append_component(${common_args} COMPONENT date_time SINCE 1.29.0)
hunter_append_component(${common_args} COMPONENT exception SINCE 1.36.0)
hunter_append_component(${common_args} COMPONENT fiber SINCE 1.62.0)
hunter_append_component(${common_args} COMPONENT filesystem SINCE 1.30.0)
hunter_append_component(${common_args} COMPONENT graph SINCE 1.18.0)
hunter_append_component(${common_args} COMPONENT graph_parallel SINCE 1.18.0)
hunter_append_component(${common_args} COMPONENT iostreams SINCE 1.33.0)
hunter_append_component(${common_args} COMPONENT json SINCE 1.75.0)
hunter_append_component(${common_args} COMPONENT locale SINCE 1.48.0)
hunter_append_component(${common_args} COMPONENT log SINCE 1.54.0)
hunter_append_component(${common_args} COMPONENT math SINCE 1.23.0)
hunter_append_component(${common_args} COMPONENT metaparse SINCE 1.61.0 UNTIL 1.66.0)
hunter_append_component(${common_args} COMPONENT mpi SINCE 1.35.0)
hunter_append_component(${common_args} COMPONENT nowide SINCE 1.74.0)
hunter_append_component(${common_args} COMPONENT program_options SINCE 1.32.0)
hunter_append_component(${common_args} COMPONENT python SINCE 1.19.0)
hunter_append_component(${common_args} COMPONENT random SINCE 1.15.0)
hunter_append_component(${common_args} COMPONENT regex SINCE 1.18.0)
hunter_append_component(${common_args} COMPONENT serialization SINCE 1.32.0)
hunter_append_component(${common_args} COMPONENT signals SINCE 1.29.0 UNTIL 1.69.0)
hunter_append_component(${common_args} COMPONENT stacktrace SINCE 1.65.0)
hunter_append_component(${common_args} COMPONENT system SINCE 1.35.0)
hunter_append_component(${common_args} COMPONENT test SINCE 1.21.0)
hunter_append_component(${common_args} COMPONENT thread SINCE 1.25.0)
hunter_append_component(${common_args} COMPONENT timer SINCE 1.9.0)
hunter_append_component(${common_args} COMPONENT type_erasure SINCE 1.60.0)
hunter_append_component(${common_args} COMPONENT url SINCE 1.81.0)
hunter_append_component(${common_args} COMPONENT wave SINCE 1.33.0)
CMake options¶
You can use CMAKE_ARGS
feature
(see
customization)
to pass options to boost build or to append config macros in the default boost user
config file (boost/config/user.hpp
):
Options of special form
<COMPONENT-UPPERCASE>_<OPTION>=<VALUE>
will be added tob2
as-s <OPTION>=<VALUE>
while building component . For example:# Add 'NO_BZIP2=1' to the b2 build of iostreams library, # i.e. `b2 -s NO_BZIP2=1` hunter_config( Boost VERSION ${HUNTER_Boost_VERSION} CMAKE_ARGS IOSTREAMS_NO_BZIP2=1 )
Options
CONFIG_MACRO_<ID>=<VALUE>
will append#define <ID> <VALUE>
to the default boost user config header file. And optionsCONFIG_MACRO=<ID_1>;<ID_2>;...;<ID_n>
will append#define <ID_1>
,#define <ID_2>
, …,#define <ID_n>
. Example:hunter_config( Boost VERSION ${HUNTER_Boost_VERSION} CMAKE_ARGS CONFIG_MACRO=BOOST_REGEX_MATCH_EXTRA;BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS CONFIG_MACRO_BOOST_MPL_LIMIT_LIST_SIZE=3 )
Will append the next lines to
boost/config/user.hpp
:#define BOOST_REGEX_MATCH_EXTRA #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS #define BOOST_MPL_LIMIT_LIST_SIZE 3
Option
USE_CONFIG_FROM_BOOST=ON
use the package configuration file provided by the boost project.Since boost version 1.70.0, the boost project provide a well maintained package configuration file for use with find_package’s config mode. As minimum required CMake version you need 3.3.
See the difference between following example:
Option
BOOST_USE_WINAPI_VERSION=<API_VERSION>
use on Windows in order to set the Windows API version used for building the boost libraries.Since Boost 1.78.0 Boost.Log exports additional symbols when building for Windows 8 or newer. So it is recommended to set the CMake variable
BOOST_USE_WINAPI_VERSION
in the CMake-toolchain file (or theCMAKE_ARGS
) to the same value as the defines_WIN32_WINNT
andWINVER
.The version passed must match the hexadecimal integer values used for
_WIN32_WINNT
andWINVER
. The version numbers are described in Windows Headers documentation.API_VERSION
is passed as a hexadecimal integer e.g.BOOST_USE_WINAPI_VERSION=0x0603
sets the Windows API version to Windows 8.1.
Python¶
To require Boost Python to be built against a specific version of Python installed
on the system, option PYTHON_VERSION=<VALUE>
may be used. In this case,
if the required components of Python are located, user_config.jam
will be appended with the following line:
using python : <requested_version_number> : <path to Python executable> :
<path to Python include directory> : <path to directory containing the Python library> ;
Example for Python 2:
# config.cmake
hunter_config(
Boost
VERSION ${HUNTER_Boost_VERSION}
CMAKE_ARGS
PYTHON_VERSION=2.7.15
)
# CMakeLists.txt
hunter_add_package(Boost COMPONENTS python)
if(Boost_VERSION VERSION_LESS 106700)
find_package(Boost CONFIG REQUIRED python)
else()
find_package(Boost CONFIG REQUIRED python27)
endif()
Note
Python<x> component arguments to find_package(Boost ...)
after Boost version 1.67 require
a specific version suffix, e.g. python37.
Example for Python 3:
# config.cmake
hunter_config(
Boost
VERSION ${HUNTER_Boost_VERSION}
CMAKE_ARGS
PYTHON_VERSION=3.6.7
)
# CMakeLists.txt
hunter_add_package(Boost COMPONENTS python)
if(Boost_VERSION VERSION_LESS 106700)
find_package(Boost CONFIG REQUIRED python3)
else()
find_package(Boost CONFIG REQUIRED python36)
endif()
Python NumPy¶
To build the NumPy plugin for Boost Python use option HUNTER_ENABLE_BOOST_PYTHON_NUMPY=True
.
This will require pip_numpy
and therefore hunter_venv
, see their docs for details and
requirements.
Example:
# config.cmake
hunter_config(
Boost
VERSION ${HUNTER_Boost_VERSION}
CMAKE_ARGS
PYTHON_VERSION=${PYTHON_VERSION}
HUNTER_ENABLE_BOOST_PYTHON_NUMPY=True
)
Math¶
When using Boost Math you will need to link in the libraries, however these are not named math
but
rather are individual based on what you need to link it, the easiest of which is to link in all parts:
hunter_add_package(Boost COMPONENTS math)
find_package(Boost CONFIG REQUIRED math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l)
target_link_libraries(...
Boost::math_c99
Boost::math_c99f
Boost::math_c99l
Boost::math_tr1
Boost::math_tr1f
Boost::math_tr1l
)
If you are using only the header-only parts of Boost::Math then the libraries can be ignored:
hunter_add_package(Boost COMPONENTS math)
find_package(Boost CONFIG REQUIRED)