1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2015 Justus Calvin
4
+ #
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:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
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
21
+ # SOFTWARE.
22
+
23
+ #
24
+ # FindTBB
25
+ # -------
26
+ #
27
+ # Find TBB include directories and libraries.
28
+ #
29
+ # Usage:
30
+ #
31
+ # find_package(TBB [major[.minor]] [EXACT]
32
+ # [QUIET] [REQUIRED]
33
+ # [[COMPONENTS] [components...]]
34
+ # [OPTIONAL_COMPONENTS components...])
35
+ #
36
+ # where the allowed components are tbbmalloc and tbb_preview. Users may modify
37
+ # the behavior of this module with the following variables:
38
+ #
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.
49
+ #
50
+ # Users may modify the behavior of this module with the following environment
51
+ # variables:
52
+ #
53
+ # * TBB_INSTALL_DIR
54
+ # * TBBROOT
55
+ # * LIBRARY_PATH
56
+ #
57
+ # This module will set the following variables:
58
+ #
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
62
+ # not available.
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
67
+ # tbb/tbb_stddef.h.
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
71
+ # tbb_preview_debug.
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
75
+ # tbb_preview_debug.
76
+ #
77
+ # The following varibles should be used to build and link with TBB:
78
+ #
79
+ # * TBB_INCLUDE_DIRS - The include directory for TBB.
80
+ # * TBB_LIBRARIES - The libraries to link against to use TBB.
81
+ # * TBB_LIBRARIES_RELEASE - The release libraries to link against to use TBB.
82
+ # * TBB_LIBRARIES_DEBUG - The debug libraries to link against to use TBB.
83
+ # * TBB_DEFINITIONS - Definitions to use when compiling code that uses
84
+ # TBB.
85
+ # * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that
86
+ # uses TBB.
87
+ # * TBB_DEFINITIONS_DEBUG - Definitions to use when compiling debug code that
88
+ # uses TBB.
89
+ #
90
+ # This module will also create the "tbb" target that may be used when building
91
+ # executables and libraries.
92
+
93
+ include (FindPackageHandleStandardArgs)
94
+
95
+ if (NOT TBB_FOUND)
96
+
97
+ ##################################
98
+ # Check the build type
99
+ ##################################
100
+
101
+ if (NOT DEFINED TBB_USE_DEBUG_BUILD)
102
+ if (CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)" )
103
+ set (TBB_BUILD_TYPE DEBUG)
104
+ else ()
105
+ set (TBB_BUILD_TYPE RELEASE)
106
+ endif ()
107
+ elseif (TBB_USE_DEBUG_BUILD)
108
+ set (TBB_BUILD_TYPE DEBUG)
109
+ else ()
110
+ set (TBB_BUILD_TYPE RELEASE)
111
+ endif ()
112
+
113
+ ##################################
114
+ # Set the TBB search directories
115
+ ##################################
116
+
117
+ # Define search paths based on user input and environment variables
118
+ set (TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT} )
119
+
120
+ # Define the search directories based on the current platform
121
+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
122
+ set (TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
123
+ "C:/Program Files (x86)/Intel/TBB" )
124
+
125
+ # Set the target architecture
126
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
127
+ set (TBB_ARCHITECTURE "intel64" )
128
+ else ()
129
+ set (TBB_ARCHITECTURE "ia32" )
130
+ endif ()
131
+
132
+ # Set the TBB search library path search suffix based on the version of VC
133
+ if (WINDOWS_STORE)
134
+ set (TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc11_ui" )
135
+ elseif (MSVC14)
136
+ set (TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc14" )
137
+ elseif (MSVC12)
138
+ set (TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc12" )
139
+ elseif (MSVC11)
140
+ set (TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc11" )
141
+ elseif (MSVC10)
142
+ set (TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc10" )
143
+ endif ()
144
+
145
+ # Add the library path search suffix for the VC independent version of TBB
146
+ list (APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE} /vc_mt" )
147
+
148
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
149
+ # OS X
150
+ set (TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb" )
151
+
152
+ # TODO: Check to see which C++ library is being used by the compiler.
153
+ if (NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
154
+ # The default C++ library on OS X 10.9 and later is libc++
155
+ set (TBB_LIB_PATH_SUFFIX "lib/libc++" "lib" )
156
+ else ()
157
+ set (TBB_LIB_PATH_SUFFIX "lib" )
158
+ endif ()
159
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
160
+ # Linux
161
+ set (TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb" )
162
+
163
+ # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
164
+ # <arch>/gcc4.1. For now, assume that the compiler is more recent than
165
+ # gcc 4.4.x or later.
166
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
167
+ set (TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4" )
168
+ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$" )
169
+ set (TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4" )
170
+ endif ()
171
+ endif ()
172
+
173
+ ##################################
174
+ # Find the TBB include dir
175
+ ##################################
176
+
177
+ find_path (TBB_INCLUDE_DIRS tbb/tbb.h
178
+ HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
179
+ PATHS ${TBB_DEFAULT_SEARCH_DIR}
180
+ PATH_SUFFIXES include )
181
+
182
+ ##################################
183
+ # Set version strings
184
+ ##################################
185
+
186
+ if (TBB_INCLUDE_DIRS)
187
+ file (READ "${TBB_INCLUDE_DIRS} /tbb/tbb_stddef.h" _tbb_version_file)
188
+ string (REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\ 1"
189
+ TBB_VERSION_MAJOR "${_tbb_version_file} " )
190
+ string (REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\ 1"
191
+ TBB_VERSION_MINOR "${_tbb_version_file} " )
192
+ string (REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\ 1"
193
+ TBB_INTERFACE_VERSION "${_tbb_version_file} " )
194
+ set (TBB_VERSION "${TBB_VERSION_MAJOR} .${TBB_VERSION_MINOR} " )
195
+ endif ()
196
+
197
+ ##################################
198
+ # Find TBB components
199
+ ##################################
200
+
201
+ if (TBB_VERSION VERSION_LESS 4.3)
202
+ set (TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb)
203
+ else ()
204
+ set (TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
205
+ endif ()
206
+
207
+ # Find each component
208
+ foreach (_comp ${TBB_SEARCH_COMPOMPONENTS} )
209
+ if (";${TBB_FIND_COMPONENTS} ;tbb;" MATCHES ";${_comp} ;" )
210
+
211
+ # Search for the libraries
212
+ find_library (TBB_${_comp} _LIBRARY_RELEASE ${_comp}
213
+ HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
214
+ PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
215
+ PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX} )
216
+
217
+ find_library (TBB_${_comp} _LIBRARY_DEBUG ${_comp} _debug
218
+ HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
219
+ PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
220
+ PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX} )
221
+
222
+ if (TBB_${_comp} _LIBRARY_DEBUG)
223
+ list (APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp} _LIBRARY_DEBUG}" )
224
+ endif ()
225
+ if (TBB_${_comp} _LIBRARY_RELEASE)
226
+ list (APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp} _LIBRARY_RELEASE}" )
227
+ endif ()
228
+ if (TBB_${_comp} _LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp} _LIBRARY)
229
+ set (TBB_${_comp} _LIBRARY "${TBB_${_comp} _LIBRARY_${TBB_BUILD_TYPE} }" )
230
+ endif ()
231
+
232
+ if (TBB_${_comp} _LIBRARY AND EXISTS "${TBB_${_comp} _LIBRARY}" )
233
+ set (TBB_${_comp} _FOUND TRUE )
234
+ else ()
235
+ set (TBB_${_comp} _FOUND FALSE )
236
+ endif ()
237
+
238
+ # Mark internal variables as advanced
239
+ mark_as_advanced (TBB_${_comp} _LIBRARY_RELEASE)
240
+ mark_as_advanced (TBB_${_comp} _LIBRARY_DEBUG)
241
+ mark_as_advanced (TBB_${_comp} _LIBRARY)
242
+
243
+ endif ()
244
+ endforeach ()
245
+
246
+ ##################################
247
+ # Set compile flags and libraries
248
+ ##################################
249
+
250
+ set (TBB_DEFINITIONS_RELEASE "" )
251
+ set (TBB_DEFINITIONS_DEBUG "-DTBB_USE_DEBUG=1" )
252
+
253
+ if (TBB_LIBRARIES_${TBB_BUILD_TYPE} )
254
+ set (TBB_DEFINITIONS "${TBB_DEFINITIONS_${TBB_BUILD_TYPE} }" )
255
+ set (TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE} }" )
256
+ elseif (TBB_LIBRARIES_RELEASE)
257
+ set (TBB_DEFINITIONS "${TBB_DEFINITIONS_RELEASE} " )
258
+ set (TBB_LIBRARIES "${TBB_LIBRARIES_RELEASE} " )
259
+ elseif (TBB_LIBRARIES_DEBUG)
260
+ set (TBB_DEFINITIONS "${TBB_DEFINITIONS_DEBUG} " )
261
+ set (TBB_LIBRARIES "${TBB_LIBRARIES_DEBUG} " )
262
+ endif ()
263
+
264
+ find_package_handle_standard_args(TBB
265
+ REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
266
+ HANDLE_COMPONENTS
267
+ VERSION_VAR TBB_VERSION)
268
+
269
+ ##################################
270
+ # Create targets
271
+ ##################################
272
+
273
+ if (NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
274
+ # Start fix to support different targets for tbb, tbbmalloc, etc.
275
+ # (Jose Luis Blanco, Jan 2019)
276
+ # Iterate over tbb, tbbmalloc, etc.
277
+ foreach (libname ${TBB_SEARCH_COMPOMPONENTS} )
278
+ if ((NOT TBB_${libname} _LIBRARY_RELEASE) AND (NOT TBB_${libname} _LIBRARY_DEBUG))
279
+ continue ()
280
+ endif ()
281
+
282
+ add_library (${libname} SHARED IMPORTED )
283
+
284
+ set_target_properties (${libname} PROPERTIES
285
+ INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
286
+ IMPORTED_LOCATION ${TBB_${libname} _LIBRARY_RELEASE})
287
+ if (TBB_${libname} _LIBRARY_RELEASE AND TBB_${libname} _LIBRARY_DEBUG)
288
+ set_target_properties (${libname} PROPERTIES
289
+ INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>"
290
+ IMPORTED_LOCATION_DEBUG ${TBB_${libname} _LIBRARY_DEBUG}
291
+ IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_${libname} _LIBRARY_DEBUG}
292
+ IMPORTED_LOCATION_RELEASE ${TBB_${libname} _LIBRARY_RELEASE}
293
+ IMPORTED_LOCATION_MINSIZEREL ${TBB_${libname} _LIBRARY_RELEASE}
294
+ )
295
+ elseif (TBB_${libname} _LIBRARY_RELEASE)
296
+ set_target_properties (${libname} PROPERTIES IMPORTED_LOCATION ${TBB_${libname} _LIBRARY_RELEASE})
297
+ else ()
298
+ set_target_properties (${libname} PROPERTIES
299
+ INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG} "
300
+ IMPORTED_LOCATION ${TBB_${libname} _LIBRARY_DEBUG}
301
+ )
302
+ endif ()
303
+ endforeach ()
304
+ # End of fix to support different targets
305
+ endif ()
306
+
307
+ mark_as_advanced (TBB_INCLUDE_DIRS TBB_LIBRARIES)
308
+
309
+ unset (TBB_ARCHITECTURE)
310
+ unset (TBB_BUILD_TYPE)
311
+ unset (TBB_LIB_PATH_SUFFIX)
312
+ unset (TBB_DEFAULT_SEARCH_DIR)
313
+
314
+ endif ()
0 commit comments