- Notifications
You must be signed in to change notification settings - Fork35
FindTBB is aCMake find package module forIntel® 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(APPENDCMAKE_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 targetsinclude_directories(${TBB_INCLUDE_DIRS})add_definitions(${TBB_DEFINITIONS})# Create your executable targetadd_executable(my_exec my_exec.cc)# Link your target with TBB librariestarget_link_libraries(my_exec${TBB_LIBRARIES})
The complete, exampleCMakeLists.txt
file is,
cmake_minimum_required (VERSION 2.8.8)project (MyProject)# Add the project modules directory to the CMake modules search path.list(APPENDCMAKE_MODULE_PATH${PROJECT_SOURCE_DIR}/cmake/modules/)# Find TBB libraries and header filesfind_package(TBB)# Add include dirctory and compile definitions for all targetsinclude_directories(${TBB_INCLUDE_DIRS})add_definitions(${TBB_DEFINITIONS})# Create your executable targetadd_executable(my_exec my_exec.cc)# Link your target with TBB librariestarget_link_libraries(my_exec${TBB_LIBRARIES})
When runningcmake
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 theTBB_INSTALL_DIR
orTBBROOT
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 .