1 # The MIT License (MIT)
3 # Copyright (c) 2015 Justus Calvin
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 # Find TBB include directories and libraries.
31 # find_package(TBB [major[.minor]] [EXACT]
33 # [[COMPONENTS] [components...]]
34 # [OPTIONAL_COMPONENTS components...])
36 # where the allowed components are tbbmalloc and tbb_preview. Users may modify
37 # the behavior of this module with the following variables:
39 # * TBB_ROOT_DIR - The base directory the of TBB installation.
40 # * TBB_INCLUDE_DIR - The directory that contains the TBB headers files.
41 # * TBB_LIBRARY - The directory that contains the TBB library files.
42 # * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library.
43 # These libraries, if specified, override the
44 # corresponding library search results, where <library>
45 # may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug,
46 # tbb_preview, or tbb_preview_debug.
47 # * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will
48 # be used instead of the release version.
50 # Users may modify the behavior of this module with the following environment
57 # This module will set the following variables:
59 # * TBB_FOUND - Set to false, or undefined, if we haven’t found, or
60 # don’t want to use TBB.
61 # * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is
63 # * TBB_VERSION - The full version string
64 # * TBB_VERSION_MAJOR - The major version
65 # * TBB_VERSION_MINOR - The minor version
66 # * TBB_INTERFACE_VERSION - The interface version number defined in
68 # * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of
69 # <library>, where <library> may be tbb, tbb_debug,
70 # tbbmalloc, tbbmalloc_debug, tbb_preview, or
72 # * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of
73 # <library>, where <library> may be tbb, tbb_debug,
74 # tbbmalloc, tbbmalloc_debug, tbb_preview, or
77 # The following varibles should be used to build and link with TBB:
79 # * TBB_INCLUDE_DIRS - The include directory for TBB.
80 # * TBB_LIBRARIES - The libraries to link against to use TBB.
81 # * TBB_DEFINITIONS - Definitions to use when compiling code that uses TBB.
83 include(FindPackageHandleStandardArgs)
87 ##################################
88 # Check the build type
89 ##################################
91 if(NOT DEFINED TBB_USE_DEBUG_BUILD)
92 if(CMAKE_BUILD_TYPE MATCHES "[Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo]")
93 set(TBB_USE_DEBUG_BUILD FALSE)
95 set(TBB_USE_DEBUG_BUILD FALSE)
99 ##################################
100 # Set the TBB search directories
101 ##################################
103 # Define search paths based on user input and environment variables
104 set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT})
106 # Define the search directories based on the current platform
107 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
108 set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
109 "C:/Program Files (x86)/Intel/TBB")
110 # TODO: Set the proper suffix paths based on compiler introspection.
112 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
114 set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
116 # TODO: Check to see which C++ library is being used by the compiler.
117 if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
118 # The default C++ library on OS X 10.9 and later is libc++
119 set(TBB_LIB_PATH_SUFFIX "lib/libc++")
121 set(TBB_LIB_PATH_SUFFIX "lib")
123 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
125 set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
127 # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
128 # <arch>/gcc4.1. For now, assume that the compiler is more recent than
129 # gcc 4.4.x or later.
130 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
131 set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4")
132 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
133 set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4")
137 ##################################
138 # Find the TBB include dir
139 ##################################
141 find_path(TBB_INCLUDE_DIRS tbb/tbb.h
142 HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
143 PATHS ${TBB_DEFAULT_SEARCH_DIR}
144 PATH_SUFFIXES include)
146 set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR}) # Set it directly!!
149 ##################################
150 # Find TBB components
151 ##################################
153 # Find each component
154 foreach(_comp tbb_preview tbbmalloc tbb)
155 # Search for the libraries
156 find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}
157 HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
158 PATHS ${TBB_DEFAULT_SEARCH_DIR}
159 PATH_SUFFIXES "${TBB_LIB_PATH_SUFFIX}")
161 find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug
162 HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
163 PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
164 PATH_SUFFIXES "${TBB_LIB_PATH_SUFFIX}")
166 # Set the library to be used for the component
167 if(NOT TBB_${_comp}_LIBRARY)
168 if(TBB_USE_DEBUG_BUILD AND TBB_${_comp}_LIBRARY_DEBUG)
169 set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}")
170 elseif(TBB_${_comp}_LIBRARY_RELEASE)
171 set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_RELEASE}")
172 elseif(TBB_${_comp}_LIBRARY_DEBUG)
173 set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}")
177 # Set the TBB library list and component found variables
178 if(TBB_${_comp}_LIBRARY)
179 list(APPEND TBB_LIBRARIES "${TBB_${_comp}_LIBRARY}")
180 set(TBB_${_comp}_FOUND TRUE)
182 set(TBB_${_comp}_FOUND FALSE)
185 mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
186 mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
187 mark_as_advanced(TBB_${_comp}_LIBRARY)
191 ##################################
193 ##################################
195 if(TBB_tbb_LIBRARY MATCHES "debug")
196 set(TBB_DEFINITIONS "-DTBB_USE_DEBUG=1")
199 ##################################
200 # Set version strings
201 ##################################
204 file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
205 string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
206 TBB_VERSION_MAJOR "${_tbb_version_file}")
207 string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
208 TBB_VERSION_MINOR "${_tbb_version_file}")
209 string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
210 TBB_INTERFACE_VERSION "${_tbb_version_file}")
211 set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
214 find_package_handle_standard_args(TBB
215 REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
217 VERSION_VAR TBB_VERSION)
219 mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)