Added
Link Here
|
1 |
--- cmake/modules/FindTBB.cmake.orig 2021-07-16 10:14:03 UTC |
2 |
+++ cmake/modules/FindTBB.cmake |
3 |
@@ -1,332 +1,456 @@ |
4 |
-# The MIT License (MIT) |
5 |
+# - Find ThreadingBuildingBlocks include dirs and libraries |
6 |
+# Use this module by invoking find_package with the form: |
7 |
+# find_package(TBB |
8 |
+# [REQUIRED] # Fail with error if TBB is not found |
9 |
+# ) # |
10 |
+# Once done, this will define |
11 |
# |
12 |
-# Copyright (c) 2015 Justus Calvin |
13 |
-# |
14 |
-# Permission is hereby granted, free of charge, to any person obtaining a copy |
15 |
-# of this software and associated documentation files (the "Software"), to deal |
16 |
-# in the Software without restriction, including without limitation the rights |
17 |
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
18 |
-# copies of the Software, and to permit persons to whom the Software is |
19 |
-# furnished to do so, subject to the following conditions: |
20 |
-# |
21 |
-# The above copyright notice and this permission notice shall be included in all |
22 |
-# copies or substantial portions of the Software. |
23 |
-# |
24 |
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
25 |
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
26 |
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
27 |
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
28 |
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
29 |
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
30 |
-# SOFTWARE. |
31 |
- |
32 |
+# TBB_FOUND - system has TBB |
33 |
+# TBB_INCLUDE_DIRS - the TBB include directories |
34 |
+# TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or |
35 |
+# malloc proxy |
36 |
+# TBB::tbb - imported target for the TBB library |
37 |
# |
38 |
-# FindTBB |
39 |
-# ------- |
40 |
+# TBB_VERSION_MAJOR - Major Product Version Number |
41 |
+# TBB_VERSION_MINOR - Minor Product Version Number |
42 |
+# TBB_INTERFACE_VERSION - Engineering Focused Version Number |
43 |
+# TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version |
44 |
+# still supported. This uses the engineering |
45 |
+# focused interface version numbers. |
46 |
# |
47 |
-# Find TBB include directories and libraries. |
48 |
+# TBB_MALLOC_FOUND - system has TBB malloc library |
49 |
+# TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories |
50 |
+# TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined |
51 |
+# TBB::malloc - imported target for the TBB malloc library |
52 |
# |
53 |
-# Usage: |
54 |
+# TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library |
55 |
+# TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories |
56 |
+# TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined |
57 |
+# TBB::malloc_proxy - imported target for the TBB malloc proxy library |
58 |
# |
59 |
-# find_package(TBB [major[.minor]] [EXACT] |
60 |
-# [QUIET] [REQUIRED] |
61 |
-# [[COMPONENTS] [components...]] |
62 |
-# [OPTIONAL_COMPONENTS components...]) |
63 |
# |
64 |
-# where the allowed components are tbbmalloc and tbb_preview. Users may modify |
65 |
-# the behavior of this module with the following variables: |
66 |
+# This module reads hints about search locations from variables: |
67 |
+# ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds |
68 |
+# ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation |
69 |
+# ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb |
70 |
+# libraries. Should be specified with ENV TBB_ROOT |
71 |
+# and optionally... |
72 |
+# ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build |
73 |
# |
74 |
-# * TBB_ROOT_DIR - The base directory the of TBB installation. |
75 |
-# * TBB_INCLUDE_DIR - The directory that contains the TBB headers files. |
76 |
-# * TBB_LIBRARY - The directory that contains the TBB library files. |
77 |
-# * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library. |
78 |
-# These libraries, if specified, override the |
79 |
-# corresponding library search results, where <library> |
80 |
-# may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug, |
81 |
-# tbb_preview, or tbb_preview_debug. |
82 |
-# * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will |
83 |
-# be used instead of the release version. |
84 |
-# * TBB_STATIC - Static linking of libraries with a _static suffix. |
85 |
-# For example, on Windows a tbb_static.lib will be searched for |
86 |
-# instead of tbb.lib. |
87 |
# |
88 |
-# Users may modify the behavior of this module with the following environment |
89 |
-# variables: |
90 |
+# Modified by Robert Maynard from the original OGRE source |
91 |
# |
92 |
-# * TBB_INSTALL_DIR |
93 |
-# * TBBROOT |
94 |
-# * LIBRARY_PATH |
95 |
+#------------------------------------------------------------------- |
96 |
+# This file is part of the CMake build system for OGRE |
97 |
+# (Object-oriented Graphics Rendering Engine) |
98 |
+# For the latest info, see http://www.ogre3d.org/ |
99 |
# |
100 |
-# This module will set the following variables: |
101 |
+# The contents of this file are placed in the public domain. Feel |
102 |
+# free to make use of it in any way you like. |
103 |
+#------------------------------------------------------------------- |
104 |
# |
105 |
-# * TBB_FOUND - Set to false, or undefined, if we haven’t found, or |
106 |
-# don’t want to use TBB. |
107 |
-# * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is |
108 |
-# not available. |
109 |
-# * TBB_VERSION - The full version string |
110 |
-# * TBB_VERSION_MAJOR - The major version |
111 |
-# * TBB_VERSION_MINOR - The minor version |
112 |
-# * TBB_INTERFACE_VERSION - The interface version number defined in |
113 |
-# tbb/tbb_stddef.h. |
114 |
-# * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of |
115 |
-# <library>, where <library> may be tbb, tbb_debug, |
116 |
-# tbbmalloc, tbbmalloc_debug, tbb_preview, or |
117 |
-# tbb_preview_debug. |
118 |
-# * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of |
119 |
-# <library>, where <library> may be tbb, tbb_debug, |
120 |
-# tbbmalloc, tbbmalloc_debug, tbb_preview, or |
121 |
-# tbb_preview_debug. |
122 |
+#============================================================================= |
123 |
+# Copyright 2010-2012 Kitware, Inc. |
124 |
+# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> |
125 |
# |
126 |
-# The following varibles should be used to build and link with TBB: |
127 |
+# Distributed under the OSI-approved BSD License (the "License"); |
128 |
+# see accompanying file Copyright.txt for details. |
129 |
# |
130 |
-# * TBB_INCLUDE_DIRS - The include directory for TBB. |
131 |
-# * TBB_LIBRARIES - The libraries to link against to use TBB. |
132 |
-# * TBB_LIBRARIES_RELEASE - The release libraries to link against to use TBB. |
133 |
-# * TBB_LIBRARIES_DEBUG - The debug libraries to link against to use TBB. |
134 |
-# * TBB_DEFINITIONS - Definitions to use when compiling code that uses |
135 |
-# TBB. |
136 |
-# * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that |
137 |
-# uses TBB. |
138 |
-# * TBB_DEFINITIONS_DEBUG - Definitions to use when compiling debug code that |
139 |
-# uses TBB. |
140 |
+# This software is distributed WITHOUT ANY WARRANTY; without even the |
141 |
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
142 |
+# See the License for more information. |
143 |
+#============================================================================= |
144 |
+# (To distribute this file outside of CMake, substitute the full |
145 |
+# License text for the above reference.) |
146 |
+ |
147 |
+ |
148 |
+#============================================================================= |
149 |
+# FindTBB helper functions and macros |
150 |
# |
151 |
-# This module will also create the "tbb" target that may be used when building |
152 |
-# executables and libraries. |
153 |
|
154 |
-unset(TBB_FOUND CACHE) |
155 |
-unset(TBB_INCLUDE_DIRS CACHE) |
156 |
-unset(TBB_LIBRARIES) |
157 |
-unset(TBB_LIBRARIES_DEBUG) |
158 |
-unset(TBB_LIBRARIES_RELEASE) |
159 |
+# Use TBBConfig.cmake if possible. |
160 |
|
161 |
-include(FindPackageHandleStandardArgs) |
162 |
+set(_tbb_find_quiet) |
163 |
+if (TBB_FIND_QUIETLY) |
164 |
+ set(_tbb_find_quiet QUIET) |
165 |
+endif () |
166 |
+set(_tbb_find_components) |
167 |
+set(_tbb_find_optional_components) |
168 |
+foreach (_tbb_find_component IN LISTS TBB_FIND_COMPONENTS) |
169 |
+ if (TBB_FIND_REQUIRED_${_tbb_find_component}) |
170 |
+ list(APPEND _tbb_find_components "${_tbb_find_component}") |
171 |
+ else () |
172 |
+ list(APPEND _tbb_find_optional_components "${_tbb_find_component}") |
173 |
+ endif () |
174 |
+endforeach () |
175 |
+unset(_tbb_find_component) |
176 |
+find_package(TBB CONFIG ${_tbb_find_quiet} |
177 |
+ COMPONENTS ${_tbb_find_components} |
178 |
+ OPTIONAL_COMPONENTS ${_tbb_find_optional_components}) |
179 |
+unset(_tbb_find_quiet) |
180 |
+unset(_tbb_find_components) |
181 |
+unset(_tbb_find_optional_components) |
182 |
+if (TBB_FOUND) |
183 |
+ return () |
184 |
+endif () |
185 |
|
186 |
-find_package(Threads QUIET REQUIRED) |
187 |
+#==================================================== |
188 |
+# Fix the library path in case it is a linker script |
189 |
+#==================================================== |
190 |
+function(tbb_extract_real_library library real_library) |
191 |
+ if(NOT UNIX OR NOT EXISTS ${library}) |
192 |
+ set(${real_library} "${library}" PARENT_SCOPE) |
193 |
+ return() |
194 |
+ endif() |
195 |
|
196 |
-if(NOT TBB_FOUND) |
197 |
+ #Read in the first 4 bytes and see if they are the ELF magic number |
198 |
+ set(_elf_magic "7f454c46") |
199 |
+ file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX) |
200 |
+ if(_hex_data STREQUAL _elf_magic) |
201 |
+ #we have opened a elf binary so this is what |
202 |
+ #we should link to |
203 |
+ set(${real_library} "${library}" PARENT_SCOPE) |
204 |
+ return() |
205 |
+ endif() |
206 |
|
207 |
- ################################## |
208 |
- # Check the build type |
209 |
- ################################## |
210 |
- |
211 |
- if(NOT DEFINED TBB_USE_DEBUG_BUILD) |
212 |
- if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug)") |
213 |
- set(TBB_BUILD_TYPE DEBUG) |
214 |
- else() |
215 |
- set(TBB_BUILD_TYPE RELEASE) |
216 |
- endif() |
217 |
- elseif(TBB_USE_DEBUG_BUILD) |
218 |
- set(TBB_BUILD_TYPE DEBUG) |
219 |
+ file(READ ${library} _data OFFSET 0 LIMIT 1024) |
220 |
+ if("${_data}" MATCHES "INPUT \\(([^(]+)\\)") |
221 |
+ #extract out the .so name from REGEX MATCH command |
222 |
+ set(_proper_so_name "${CMAKE_MATCH_1}") |
223 |
+ |
224 |
+ #construct path to the real .so which is presumed to be in the same directory |
225 |
+ #as the input file |
226 |
+ get_filename_component(_so_dir "${library}" DIRECTORY) |
227 |
+ set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE) |
228 |
else() |
229 |
- set(TBB_BUILD_TYPE RELEASE) |
230 |
+ #unable to determine what this library is so just hope everything works |
231 |
+ #and pass it unmodified. |
232 |
+ set(${real_library} "${library}" PARENT_SCOPE) |
233 |
endif() |
234 |
- |
235 |
- ################################## |
236 |
- # Set the TBB search directories |
237 |
- ################################## |
238 |
- |
239 |
- # Define search paths based on user input and environment variables |
240 |
- set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT}) |
241 |
- |
242 |
- # Define the search directories based on the current platform |
243 |
- if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
244 |
- set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB" |
245 |
- "C:/Program Files (x86)/Intel/TBB") |
246 |
+endfunction() |
247 |
|
248 |
- # Set the target architecture |
249 |
- if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
250 |
- set(TBB_ARCHITECTURE "intel64") |
251 |
- else() |
252 |
- set(TBB_ARCHITECTURE "ia32") |
253 |
- endif() |
254 |
+#=============================================== |
255 |
+# Do the final processing for the package find. |
256 |
+#=============================================== |
257 |
+macro(findpkg_finish PREFIX TARGET_NAME) |
258 |
+ if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) |
259 |
+ set(${PREFIX}_FOUND TRUE) |
260 |
+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) |
261 |
+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) |
262 |
+ else () |
263 |
+ if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY) |
264 |
+ message(FATAL_ERROR "Required library ${PREFIX} not found.") |
265 |
+ endif () |
266 |
+ endif () |
267 |
|
268 |
- # Set the TBB search library path search suffix based on the version of VC |
269 |
- if(WINDOWS_STORE) |
270 |
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui") |
271 |
- elseif(MSVC14) |
272 |
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14") |
273 |
- elseif(MSVC12) |
274 |
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12") |
275 |
- elseif(MSVC11) |
276 |
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11") |
277 |
- elseif(MSVC10) |
278 |
- set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10") |
279 |
- endif() |
280 |
+ if (NOT TARGET "TBB::${TARGET_NAME}") |
281 |
+ if (${PREFIX}_LIBRARY_RELEASE) |
282 |
+ tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release) |
283 |
+ endif () |
284 |
+ if (${PREFIX}_LIBRARY_DEBUG) |
285 |
+ tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug) |
286 |
+ endif () |
287 |
+ add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED) |
288 |
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
289 |
+ INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}") |
290 |
+ if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE) |
291 |
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
292 |
+ IMPORTED_LOCATION "${real_release}" |
293 |
+ IMPORTED_LOCATION_DEBUG "${real_debug}" |
294 |
+ IMPORTED_LOCATION_RELEASE "${real_release}") |
295 |
+ elseif (${PREFIX}_LIBRARY_RELEASE) |
296 |
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
297 |
+ IMPORTED_LOCATION "${real_release}") |
298 |
+ elseif (${PREFIX}_LIBRARY_DEBUG) |
299 |
+ set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
300 |
+ IMPORTED_LOCATION "${real_debug}") |
301 |
+ endif () |
302 |
+ endif () |
303 |
|
304 |
- # Add the library path search suffix for the VC independent version of TBB |
305 |
- list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt") |
306 |
+ #mark the following variables as internal variables |
307 |
+ mark_as_advanced(${PREFIX}_INCLUDE_DIR |
308 |
+ ${PREFIX}_LIBRARY |
309 |
+ ${PREFIX}_LIBRARY_DEBUG |
310 |
+ ${PREFIX}_LIBRARY_RELEASE) |
311 |
+endmacro() |
312 |
|
313 |
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
314 |
- # OS X |
315 |
- set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") |
316 |
- |
317 |
- # TODO: Check to see which C++ library is being used by the compiler. |
318 |
- if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0) |
319 |
- # The default C++ library on OS X 10.9 and later is libc++ |
320 |
- set(TBB_LIB_PATH_SUFFIX "lib/libc++" "lib") |
321 |
- else() |
322 |
- set(TBB_LIB_PATH_SUFFIX "lib") |
323 |
- endif() |
324 |
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
325 |
- # Linux |
326 |
- set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") |
327 |
- |
328 |
- # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or |
329 |
- # <arch>/gcc4.1. For now, assume that the compiler is more recent than |
330 |
- # gcc 4.4.x or later. |
331 |
- if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") |
332 |
- set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4") |
333 |
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") |
334 |
- set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4") |
335 |
- endif() |
336 |
- endif() |
337 |
- |
338 |
- ################################## |
339 |
- # Find the TBB include dir |
340 |
- ################################## |
341 |
- |
342 |
- find_path(TBB_INCLUDE_DIRS tbb/tbb.h |
343 |
- HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR} |
344 |
- PATHS ${TBB_DEFAULT_SEARCH_DIR} |
345 |
- PATH_SUFFIXES include) |
346 |
+#=============================================== |
347 |
+# Generate debug names from given release names |
348 |
+#=============================================== |
349 |
+macro(get_debug_names PREFIX) |
350 |
+ foreach(i ${${PREFIX}}) |
351 |
+ set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i}) |
352 |
+ endforeach() |
353 |
+endmacro() |
354 |
|
355 |
- ################################## |
356 |
- # Set version strings |
357 |
- ################################## |
358 |
+#=============================================== |
359 |
+# See if we have env vars to help us find tbb |
360 |
+#=============================================== |
361 |
+macro(getenv_path VAR) |
362 |
+ set(ENV_${VAR} $ENV{${VAR}}) |
363 |
+ # replace won't work if var is blank |
364 |
+ if (ENV_${VAR}) |
365 |
+ string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} ) |
366 |
+ endif () |
367 |
+endmacro() |
368 |
|
369 |
- if(TBB_INCLUDE_DIRS) |
370 |
- file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) |
371 |
- string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" |
372 |
- TBB_VERSION_MAJOR "${_tbb_version_file}") |
373 |
- string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" |
374 |
- TBB_VERSION_MINOR "${_tbb_version_file}") |
375 |
- string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" |
376 |
- TBB_INTERFACE_VERSION "${_tbb_version_file}") |
377 |
- set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}") |
378 |
- endif() |
379 |
+#=============================================== |
380 |
+# Couple a set of release AND debug libraries |
381 |
+#=============================================== |
382 |
+macro(make_library_set PREFIX) |
383 |
+ if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG) |
384 |
+ set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG}) |
385 |
+ elseif (${PREFIX}_RELEASE) |
386 |
+ set(${PREFIX} ${${PREFIX}_RELEASE}) |
387 |
+ elseif (${PREFIX}_DEBUG) |
388 |
+ set(${PREFIX} ${${PREFIX}_DEBUG}) |
389 |
+ endif () |
390 |
+endmacro() |
391 |
|
392 |
- ################################## |
393 |
- # Find TBB components |
394 |
- ################################## |
395 |
|
396 |
- if(TBB_VERSION VERSION_LESS 4.3) |
397 |
- set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb) |
398 |
- else() |
399 |
- set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb) |
400 |
- endif() |
401 |
+#============================================================================= |
402 |
+# Now to actually find TBB |
403 |
+# |
404 |
|
405 |
- if(TBB_STATIC) |
406 |
- set(TBB_STATIC_SUFFIX "_static") |
407 |
- endif() |
408 |
+# Get path, convert backslashes as ${ENV_${var}} |
409 |
+getenv_path(TBB_ROOT) |
410 |
|
411 |
- # Find each component |
412 |
- foreach(_comp ${TBB_SEARCH_COMPOMPONENTS}) |
413 |
- if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};") |
414 |
+# initialize search paths |
415 |
+set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT}) |
416 |
+set(TBB_INC_SEARCH_PATH "") |
417 |
+set(TBB_LIB_SEARCH_PATH "") |
418 |
|
419 |
- unset(TBB_${_comp}_LIBRARY_DEBUG CACHE) |
420 |
- unset(TBB_${_comp}_LIBRARY_RELEASE CACHE) |
421 |
|
422 |
- # Search for the libraries |
423 |
- find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}${TBB_STATIC_SUFFIX} |
424 |
- HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} |
425 |
- PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH |
426 |
- PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) |
427 |
+# If user built from sources |
428 |
+set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX}) |
429 |
+if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT) |
430 |
+ getenv_path(TBB_BUILD_DIR) |
431 |
+ if (NOT ENV_TBB_BUILD_DIR) |
432 |
+ set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build) |
433 |
+ endif () |
434 |
|
435 |
- find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}${TBB_STATIC_SUFFIX}_debug |
436 |
- HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} |
437 |
- PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH |
438 |
- PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) |
439 |
+ # include directory under ${ENV_TBB_ROOT}/include |
440 |
+ list(APPEND TBB_LIB_SEARCH_PATH |
441 |
+ ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release |
442 |
+ ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug) |
443 |
+endif () |
444 |
|
445 |
- if(TBB_${_comp}_LIBRARY_DEBUG) |
446 |
- list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}") |
447 |
- endif() |
448 |
- if(TBB_${_comp}_LIBRARY_RELEASE) |
449 |
- list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}") |
450 |
- endif() |
451 |
- if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY) |
452 |
- set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}") |
453 |
- endif() |
454 |
|
455 |
- if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}") |
456 |
- set(TBB_${_comp}_FOUND TRUE) |
457 |
- else() |
458 |
- set(TBB_${_comp}_FOUND FALSE) |
459 |
- endif() |
460 |
+# For Windows, let's assume that the user might be using the precompiled |
461 |
+# TBB packages from the main website. These use a rather awkward directory |
462 |
+# structure (at least for automatically finding the right files) depending |
463 |
+# on platform and compiler, but we'll do our best to accommodate it. |
464 |
+# Not adding the same effort for the precompiled linux builds, though. Those |
465 |
+# have different versions for CC compiler versions and linux kernels which |
466 |
+# will never adequately match the user's setup, so there is no feasible way |
467 |
+# to detect the "best" version to use. The user will have to manually |
468 |
+# select the right files. (Chances are the distributions are shipping their |
469 |
+# custom version of tbb, anyway, so the problem is probably nonexistent.) |
470 |
+if (WIN32 AND MSVC) |
471 |
+ set(COMPILER_PREFIX "vc7.1") |
472 |
+ if (MSVC_VERSION EQUAL 1400) |
473 |
+ set(COMPILER_PREFIX "vc8") |
474 |
+ elseif(MSVC_VERSION EQUAL 1500) |
475 |
+ set(COMPILER_PREFIX "vc9") |
476 |
+ elseif(MSVC_VERSION EQUAL 1600) |
477 |
+ set(COMPILER_PREFIX "vc10") |
478 |
+ elseif(MSVC_VERSION EQUAL 1700) |
479 |
+ set(COMPILER_PREFIX "vc11") |
480 |
+ elseif(MSVC_VERSION EQUAL 1800) |
481 |
+ set(COMPILER_PREFIX "vc12") |
482 |
+ elseif(MSVC_VERSION GREATER_EQUAL 1900) |
483 |
+ set(COMPILER_PREFIX "vc14") |
484 |
+ endif () |
485 |
|
486 |
- # Mark internal variables as advanced |
487 |
- mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE) |
488 |
- mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG) |
489 |
- mark_as_advanced(TBB_${_comp}_LIBRARY) |
490 |
+ # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path |
491 |
+ foreach (dir IN LISTS TBB_PREFIX_PATH) |
492 |
+ if (CMAKE_CL_64) |
493 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib) |
494 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX}) |
495 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib) |
496 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX}) |
497 |
+ else () |
498 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib) |
499 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX}) |
500 |
+ endif () |
501 |
+ endforeach () |
502 |
+endif () |
503 |
|
504 |
- endif() |
505 |
- endforeach() |
506 |
+# For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9) |
507 |
+# and above and AppleClang |
508 |
+if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND |
509 |
+ NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0) |
510 |
+ set (USE_LIBCXX OFF) |
511 |
+ cmake_policy(GET CMP0025 POLICY_VAR) |
512 |
|
513 |
- ################################## |
514 |
- # Set compile flags and libraries |
515 |
- ################################## |
516 |
+ if (POLICY_VAR STREQUAL "NEW") |
517 |
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") |
518 |
+ set (USE_LIBCXX ON) |
519 |
+ endif () |
520 |
+ else () |
521 |
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
522 |
+ set (USE_LIBCXX ON) |
523 |
+ endif () |
524 |
+ endif () |
525 |
|
526 |
- set(TBB_DEFINITIONS_RELEASE "") |
527 |
- set(TBB_DEFINITIONS_DEBUG "TBB_USE_DEBUG=1") |
528 |
- |
529 |
- if(TBB_LIBRARIES_${TBB_BUILD_TYPE}) |
530 |
- set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}") |
531 |
+ if (USE_LIBCXX) |
532 |
+ foreach (dir IN LISTS TBB_PREFIX_PATH) |
533 |
+ list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib) |
534 |
+ endforeach () |
535 |
+ endif () |
536 |
+endif () |
537 |
+ |
538 |
+# check compiler ABI |
539 |
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
540 |
+ set(COMPILER_PREFIX) |
541 |
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) |
542 |
+ list(APPEND COMPILER_PREFIX "gcc4.8") |
543 |
endif() |
544 |
- |
545 |
- if(NOT MSVC AND NOT TBB_LIBRARIES) |
546 |
- set(TBB_LIBRARIES ${TBB_LIBRARIES_RELEASE}) |
547 |
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) |
548 |
+ list(APPEND COMPILER_PREFIX "gcc4.7") |
549 |
endif() |
550 |
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) |
551 |
+ list(APPEND COMPILER_PREFIX "gcc4.4") |
552 |
+ endif() |
553 |
+ list(APPEND COMPILER_PREFIX "gcc4.1") |
554 |
+elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
555 |
+ set(COMPILER_PREFIX) |
556 |
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess |
557 |
+ list(APPEND COMPILER_PREFIX "gcc4.8") |
558 |
+ endif() |
559 |
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) |
560 |
+ list(APPEND COMPILER_PREFIX "gcc4.7") |
561 |
+ endif() |
562 |
+ list(APPEND COMPILER_PREFIX "gcc4.4") |
563 |
+else() # Assume compatibility with 4.4 for other compilers |
564 |
+ list(APPEND COMPILER_PREFIX "gcc4.4") |
565 |
+endif () |
566 |
|
567 |
- set(TBB_DEFINITIONS "") |
568 |
- if (MSVC AND TBB_STATIC) |
569 |
- set(TBB_DEFINITIONS __TBB_NO_IMPLICIT_LINKAGE) |
570 |
- endif () |
571 |
+# if platform architecture is explicitly specified |
572 |
+set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM}) |
573 |
+if (TBB_ARCH_PLATFORM) |
574 |
+ foreach (dir IN LISTS TBB_PREFIX_PATH) |
575 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib) |
576 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM}) |
577 |
+ endforeach () |
578 |
+endif () |
579 |
|
580 |
- unset (TBB_STATIC_SUFFIX) |
581 |
+foreach (dir IN LISTS TBB_PREFIX_PATH) |
582 |
+ foreach (prefix IN LISTS COMPILER_PREFIX) |
583 |
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8) |
584 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64) |
585 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix}) |
586 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib) |
587 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib) |
588 |
+ else () |
589 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32) |
590 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix}) |
591 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib) |
592 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib) |
593 |
+ endif () |
594 |
+ endforeach() |
595 |
+endforeach () |
596 |
|
597 |
- find_package_handle_standard_args(TBB |
598 |
- REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES |
599 |
- FAIL_MESSAGE "TBB library cannot be found. Consider set TBBROOT environment variable." |
600 |
- HANDLE_COMPONENTS |
601 |
- VERSION_VAR TBB_VERSION) |
602 |
+# add general search paths |
603 |
+foreach (dir IN LISTS TBB_PREFIX_PATH) |
604 |
+ list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb |
605 |
+ ${dir}/Libs) |
606 |
+ list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include |
607 |
+ ${dir}/include/tbb) |
608 |
+endforeach () |
609 |
|
610 |
- ################################## |
611 |
- # Create targets |
612 |
- ################################## |
613 |
+set(TBB_LIBRARY_NAMES tbb) |
614 |
+get_debug_names(TBB_LIBRARY_NAMES) |
615 |
|
616 |
- if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND) |
617 |
- add_library(TBB::tbb UNKNOWN IMPORTED) |
618 |
- set_target_properties(TBB::tbb PROPERTIES |
619 |
- INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS}" |
620 |
- INTERFACE_LINK_LIBRARIES "Threads::Threads;${CMAKE_DL_LIBS}" |
621 |
- INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS} |
622 |
- IMPORTED_LOCATION ${TBB_LIBRARIES}) |
623 |
- if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG) |
624 |
- set_target_properties(TBB::tbb PROPERTIES |
625 |
- INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS};$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:${TBB_DEFINITIONS_DEBUG}>;$<$<CONFIG:Release>:${TBB_DEFINITIONS_RELEASE}>" |
626 |
- IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG} |
627 |
- IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_RELEASE} |
628 |
- IMPORTED_LOCATION_RELEASE ${TBB_LIBRARIES_RELEASE} |
629 |
- IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE} |
630 |
- ) |
631 |
- endif() |
632 |
- endif() |
633 |
|
634 |
- mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES) |
635 |
+find_path(TBB_INCLUDE_DIR |
636 |
+ NAMES tbb/tbb.h |
637 |
+ PATHS ${TBB_INC_SEARCH_PATH}) |
638 |
|
639 |
- unset(TBB_ARCHITECTURE) |
640 |
- unset(TBB_BUILD_TYPE) |
641 |
- unset(TBB_LIB_PATH_SUFFIX) |
642 |
- unset(TBB_DEFAULT_SEARCH_DIR) |
643 |
+find_library(TBB_LIBRARY_RELEASE |
644 |
+ NAMES ${TBB_LIBRARY_NAMES} |
645 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
646 |
+find_library(TBB_LIBRARY_DEBUG |
647 |
+ NAMES ${TBB_LIBRARY_NAMES_DEBUG} |
648 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
649 |
+make_library_set(TBB_LIBRARY) |
650 |
|
651 |
- if(TBB_DEBUG) |
652 |
- message(STATUS " TBB_FOUND = ${TBB_FOUND}") |
653 |
- message(STATUS " TBB_INCLUDE_DIRS = ${TBB_INCLUDE_DIRS}") |
654 |
- message(STATUS " TBB_DEFINITIONS = ${TBB_DEFINITIONS}") |
655 |
- message(STATUS " TBB_LIBRARIES = ${TBB_LIBRARIES}") |
656 |
- message(STATUS " TBB_DEFINITIONS_DEBUG = ${TBB_DEFINITIONS_DEBUG}") |
657 |
- message(STATUS " TBB_LIBRARIES_DEBUG = ${TBB_LIBRARIES_DEBUG}") |
658 |
- message(STATUS " TBB_DEFINITIONS_RELEASE = ${TBB_DEFINITIONS_RELEASE}") |
659 |
- message(STATUS " TBB_LIBRARIES_RELEASE = ${TBB_LIBRARIES_RELEASE}") |
660 |
+findpkg_finish(TBB tbb) |
661 |
+ |
662 |
+#if we haven't found TBB no point on going any further |
663 |
+if (NOT TBB_FOUND) |
664 |
+ return() |
665 |
+endif () |
666 |
+ |
667 |
+#============================================================================= |
668 |
+# Look for TBB's malloc package |
669 |
+set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc) |
670 |
+get_debug_names(TBB_MALLOC_LIBRARY_NAMES) |
671 |
+ |
672 |
+find_path(TBB_MALLOC_INCLUDE_DIR |
673 |
+ NAMES tbb/tbb.h |
674 |
+ PATHS ${TBB_INC_SEARCH_PATH}) |
675 |
+ |
676 |
+find_library(TBB_MALLOC_LIBRARY_RELEASE |
677 |
+ NAMES ${TBB_MALLOC_LIBRARY_NAMES} |
678 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
679 |
+find_library(TBB_MALLOC_LIBRARY_DEBUG |
680 |
+ NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG} |
681 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
682 |
+make_library_set(TBB_MALLOC_LIBRARY) |
683 |
+ |
684 |
+findpkg_finish(TBB_MALLOC tbbmalloc) |
685 |
+ |
686 |
+#============================================================================= |
687 |
+# Look for TBB's malloc proxy package |
688 |
+set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy) |
689 |
+get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES) |
690 |
+ |
691 |
+find_path(TBB_MALLOC_PROXY_INCLUDE_DIR |
692 |
+ NAMES tbb/tbbmalloc_proxy.h |
693 |
+ PATHS ${TBB_INC_SEARCH_PATH}) |
694 |
+ |
695 |
+find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE |
696 |
+ NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES} |
697 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
698 |
+find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG |
699 |
+ NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG} |
700 |
+ PATHS ${TBB_LIB_SEARCH_PATH}) |
701 |
+make_library_set(TBB_MALLOC_PROXY_LIBRARY) |
702 |
+ |
703 |
+findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy) |
704 |
+ |
705 |
+ |
706 |
+#============================================================================= |
707 |
+#parse all the version numbers from tbb |
708 |
+if(NOT TBB_VERSION) |
709 |
+ if (EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h") |
710 |
+ file(STRINGS |
711 |
+ "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h" |
712 |
+ TBB_VERSION_CONTENTS |
713 |
+ REGEX "VERSION") |
714 |
+ else() |
715 |
+ #only read the start of the file |
716 |
+ file(STRINGS |
717 |
+ "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h" |
718 |
+ TBB_VERSION_CONTENTS |
719 |
+ REGEX "VERSION") |
720 |
endif() |
721 |
+ |
722 |
+ string(REGEX REPLACE |
723 |
+ ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" |
724 |
+ TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}") |
725 |
+ |
726 |
+ string(REGEX REPLACE |
727 |
+ ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" |
728 |
+ TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}") |
729 |
+ |
730 |
+ string(REGEX REPLACE |
731 |
+ ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" |
732 |
+ TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}") |
733 |
+ |
734 |
+ string(REGEX REPLACE |
735 |
+ ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1" |
736 |
+ TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}") |
737 |
|
738 |
endif() |