-
Notifications
You must be signed in to change notification settings - Fork 35
Home
FindTBB is a CMake find package module for Intel® Thread Building Blocks (TBB).
To use FindTBB in your CMake project, the first step is to setup your CMake project script.
-
Put a copy of the
FindTBB.cmake
file to your project. The typically location iscmake/modules/FindTBB.cmake
. -
Add the module directory to the CMake modules path to your
CMakeLists.txt
file.list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
-
Call
find_package
in yourCMakeLists.txt
file to find TBB header files and libraries. For example, a simple code might be,find_package(TBB)
-
Build your executable or library with TBB, again in your ```CMakeLists.txt file,
# Add include dirctory and compile definitions for all targets include_directories(${TBB_INCLUDE_DIRS}) add_definitions(${TBB_DEFINITIONS}) # Create your executable target add_executable(my_exec my_exec.cc) # Link your target with TBB libraries target_link_libraries(my_exec ${TBB_LIBRARIES})
The complete, example CMakeLists.txt
file is,
cmake_minimum_required (VERSION 2.8.8)
project (MyProject)
# Add the project modules directory to the CMake modules search path.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
# Find TBB libraries and header files
find_package(TBB)
# Add include dirctory and compile definitions for all targets
include_directories(${TBB_INCLUDE_DIRS})
add_definitions(${TBB_DEFINITIONS})
# Create your executable target
add_executable(my_exec my_exec.cc)
# Link your target with TBB libraries
target_link_libraries(my_exec ${TBB_LIBRARIES})
When running cmake
for your project you may need to specify the location of the TBB install directory, include directory, and/or library direcory. For example, if you have installed TBB in the /path/to/tbb
directory,
$ cmake -DTBB_ROOT_DIR=/path/to/tbb .
FindTBB can also use the TBB_INSTALL_DIR
or TBBROOT
environment variables to specify the install directory of TBB.
$ export TBBROOT=/path/to/tbb
$ cmake .
If TBB does not use standard install paths (e.g. the open source version of TBB), you will need to specify the include and library directory.
$ cmake -DTBB_INCLUDE_DIR=/path/to/tbb/include -DTBB_LIBRARY=/path/to/tbb/lib .