The project uses CMake build configuration.
The following controls are available during the configure stage:
TBB_TEST:BOOL - Enable testing (ON by default)
TBB_STRICT:BOOL - Treat compiler warnings as errors (ON by default)
TBB_SANITIZE:STRING - Sanitizer parameter, passed to compiler/linker
TBB_SIGNTOOL:FILEPATH - Tool for digital signing, used in post install step for libraries if provided.
TBB_SIGNTOOL_ARGS:STRING - Additional arguments for TBB_SIGNTOOL, used if TBB_SIGNTOOL is set.
TBB4PY_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) Python module build (OFF by default)
TBB_CPF:BOOL - Enable preview features of the library (OFF by default)
TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generated by `cpack` and `make install` will also include the vars script)(OFF by default)
TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by default)
- CMake >= 3.1
In order to perform out-of-source build you have to create a build directory and go there:
mkdir /tmp/my-build
cd /tmp/my-build
cmake <options> <repo_root>
Some useful options:
-G <generator>
- specify particular project generator, seecmake --help
for details.-DCMAKE_BUILD_TYPE=Debug
- specify for Debug build, it doesn't applicable for multi-config generators, e.g. for Visual Studio generator).
The TBBbind library has two versions: tbbbind
and tbbbind_2_0
. Each of these versions is linked with corresponding HWLOC library version: tbbbind
links with HWLOC 1.11.x , tbbbind_2_0
links with HWLOC 2.x.
To enable the TBBBind library build or special tests that performed inside the HWLOC environment, please specify the following CMake variables:
CMAKE_HWLOC_<HWLOC_VER>_LIBRARY_PATH
- path to the corresponding HWLOC version shared library on Linux or path to.lib
file on Windows.CMAKE_HWLOC_<HWLOC_VER>_INCLUDE_PATH
- path to the corresponding HWLOC version includes directory.
Windows requires one additional variable for correct TBBBind library building:
CMAKE_HWLOC_<HWLOC_VER>_DLL_PATH
- path to the corresponding HWLOC version.dll
file.
HWLOC_VER
variable used above can be replaced with one of the two values: 1_11
for the tbbbind
library configuration and 2
for the tbbbind_2_0
library configuration.
cmake --build . <options>
Some useful options:
--target <target>
- specific target, "all" is default.--config <Release|Debug>
- build configuration, applicable only for multi-config generators, e.g. Visual Studio generator.
Binaries are placed to ./<compiler-id>_<compiler-ver>_cxx<stdver>_<build-type>
(for example, ./gnu_4.8_cxx11_release
)
- Intel Compiler: just source Intel(R) C++ Compiler with
ia32
and build as usual. - MSVC: use switch for generator (e.g.
-A Win32
for VS2019) during the configuration stage and then build as usual. - GCC/Clang: specify
-m32
during the configuration:CXXFLAGS=-m32 cmake ..
orcmake -DCMAKE_CXX_FLAGS=-m32 ..
- Any other compiler which builds for 64-bit by default: specify 32-bit compiler key during the configuration as above.
- Dynamic linkage with CRT: default behavior, can be explicitly specified by setting
CMAKE_MSVC_RUNTIME_LIBRARY
toMultiThreadedDLL
orMultiThreadedDebugDLL
.
cmake .. # dynamic linkage is used by default
cmake -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL ..
cmake -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL -DCMAKE_BUILD_TYPE=Debug ..
- Static linkage with CRT: set
CMAKE_MSVC_RUNTIME_LIBRARY
toMultiThreaded
orMultiThreadedDebug
.
cmake -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ..
cmake -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug -DCMAKE_BUILD_TYPE=Debug ..
- Windows 10 Universal Windows application build: set
CMAKE_SYSTEM_NAME
toWindowsStore
andCMAKE_SYSTEM_VERSION
to10.0
.
Note: set TBB_NO_APPCONTAINER
to ON
in order to apply /APPCONTAINER:NO
option during the compilation (used for testing).
cmake -DCMAKE_SYSTEM_NAME:STRING=WindowsStore -DCMAKE_SYSTEM_VERSION:STRING=10.0 ..
- Universal Windows Driver build: set
TBB_WINDOWS_DRIVER
toON
and use static linkage with CRT (see above).
cmake -DTBB_WINDOWS_DRIVER=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ..
Using default ('all') target:
cmake --build .
or using specific test target:
cmake --build . --target <test> # e.g. test_version
Using CTest:
ctest
or using 'test' target:
cmake --build . --target test # currently doesn't work on Windows
mkdir build
cd build
cmake -DTBB_SANITIZE=thread .. # or -DTBB_SANITIZE=memory or any other sanitizer
make -j
ctest -V
- Valgrind tool executable
mkdir build
cd build
cmake -DTBB_VALGRIND_MEMCHECK=ON ..
make -j memcheck-<test name> # or memcheck-all to scan all tests
mkdir build
cd build
cmake -DTBB_TEST_SPEC=ON ..
make test_spec
NOTE: be careful about installation: avoid commands like make install
unless you fully understand the consequences.
The following install components are supported:
runtime
- oneTBB runtime package (core shared libraries and.dll
files on Windows).devel
- oneTBB development package (header files, CMake integration files, library symbolic links and.lib
files on Windows).tbb4py
- oneTBB Module for Python.
How to install specific components after configuration and build:
cmake -DCOMPONENT=<component> [-DBUILD_TYPE=<build-type>] -P cmake_install.cmake
Simple packaging using CPack is supported. The following commands allow to create a simple portable package which includes header files, libraries and integration files for CMake:
cmake <options> ..
cpack
It is a configuration module that is used for integration of prebuilt oneTBB. It consists of two files (TBBConfig.cmake and TBBConfigVersion.cmake) and can be used via find_package function.
How to use this module in your CMake project:
- Let CMake know where to search for TBBConfig, e.g. specify location of TBBConfig.cmake in
TBB_DIR
(for more details about search paths see find_package). - Use find_package to find oneTBB.
- Use provided variables and/or imported targets (described below) to work with the found oneTBB.
Example:
add_executable(foo foo.cpp)
find_package(TBB)
target_link_libraries(foo TBB::tbb)
oneTBB components can be passed to find_package after keyword COMPONENTS
or REQUIRED
.
Use basic names of components (tbb
, tbbmalloc
, etc.).
If components are not specified then the default set is used: tbb
, tbbmalloc
and tbbmalloc_proxy
.
If tbbmalloc_proxy
is requested, tbbmalloc
component will also be added and set as dependency for tbbmalloc_proxy
.
TBBConfig creates imported targets as
shared libraries using the following format: TBB::<component>
(for example, TBB::tbb
, TBB::tbbmalloc
).
Set TBB_FIND_RELEASE_ONLY
to TRUE
before calling find_package
in order to search only for release oneTBB version. This variable helps to avoid simultaneous linkage of release and debug oneTBB versions when CMake configuration is Debug
but a third-party component depends on release oneTBB version.
Variables set during TBB configuration:
Variable | Description |
---|---|
TBB_FOUND |
oneTBB is found |
TBB_<component>_FOUND |
Specific oneTBB component is found |
TBB_VERSION |
oneTBB version (format: <major>.<minor>.<patch>.<tweak> ) |
TBB_IMPORTED_TARGETS |
All created oneTBB imported targets (not supported for builds from source code) |
Starting from oneTBB 2021.1 GitHub release TBBConfig files in the binary packages are located under <tbb-root>/lib/cmake/TBB
.
For example, TBB_DIR
should be set to <tbb-root>/lib/cmake/TBB
.
TBBConfig files are automatically created during the build from source code and can be installed together with the library.
Also oneTBB provides a helper function that creates TBBConfig files from predefined templates: see tbb_generate_config
in cmake/config_generation.cmake
.
TBB4PY_BUILD
Cmake option provides ability to build Python module for oneTBB.
irml
- build IPC RML serverpython_build
- build oneTBB module for Python
python_build
target requirements:
- Python version 3.5 or newer
- SWIG version 3.0.6 or newer
Compile and link options may be specific for certain compilers. This part is handled in cmake/compilers/*
files.
Options in TBB CMake are handled via variables in two ways for convenience:
- by options group
- by specific option
Naming convention is the following: TBB_<SCOPE>_<STAGE>_<CATEGORY>
, where
<SCOPE>
could beLIB
- options applied during libraries build.TEST
- options applied during test build.BENCH
- options applied during benchmarks build.COMMON
- options applied during all (libraries, test, benchmarks) builds.
<STAGE>
could beCOMPILE
- options applied during the compilation.LINK
- options applied during the linkage.
<CATEGORY>
could beFLAGS
- list of flagsLIBS
- list of libraries
Examples
Variable | Description |
---|---|
TBB_COMMON_COMPILE_FLAGS |
Applied to libraries, tests and benchmarks as compile options |
TBB_LIB_LINK_FLAGS |
Applied to libraries as link options |
TBB_LIB_LINK_LIBS |
Applied to libraries as link libraries |
TBB_TEST_COMPILE_FLAGS |
Applied to tests as compile options |
If the option used only in part of the places (library, tests, benchmarks) as well as adding this option to the group of other options is not possible, then the option must be named using common sense.
Warnings supperssions should be added into TBB_WARNING_SUPPRESS
variable which is applied during the compilation of libraries, tests and benchmarks.
Additional warnings should be added into TBB_WARNING_TEST_FLAGS
variable which is applied during the compilation of tests.