Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/cmake/Modules/FindTBB.cmake

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 # - Find ThreadingBuildingBlocks include dirs and libraries
  2 # Use this module by invoking find_package with the form:
  3 #  find_package(TBB
  4 #    [REQUIRED]             # Fail with error if TBB is not found
  5 #    )                      #
  6 # Once done, this will define
  7 #
  8 #  TBB_FOUND - system has TBB
  9 #  TBB_INCLUDE_DIRS - the TBB include directories
 10 #  TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or
 11 #                  malloc proxy
 12 #  TBB::tbb - imported target for the TBB library
 13 #
 14 #  TBB_VERSION_MAJOR - Major Product Version Number
 15 #  TBB_VERSION_MINOR - Minor Product Version Number
 16 #  TBB_INTERFACE_VERSION - Engineering Focused Version Number
 17 #  TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version
 18 #                                     still supported. This uses the engineering
 19 #                                     focused interface version numbers.
 20 #
 21 #  TBB_MALLOC_FOUND - system has TBB malloc library
 22 #  TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories
 23 #  TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined
 24 #  TBB::malloc - imported target for the TBB malloc library
 25 #
 26 #  TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library
 27 #  TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories
 28 #  TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined
 29 #  TBB::malloc_proxy - imported target for the TBB malloc proxy library
 30 #
 31 #
 32 # This module reads hints about search locations from variables:
 33 #  ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds
 34 #  ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation
 35 #  ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb
 36 #                         libraries. Should be specified with ENV TBB_ROOT
 37 #                         and optionally...
 38 #  ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build
 39 #
 40 #
 41 # Modified by Robert Maynard from the original OGRE source
 42 #
 43 #-------------------------------------------------------------------
 44 # This file is part of the CMake build system for OGRE
 45 #     (Object-oriented Graphics Rendering Engine)
 46 # For the latest info, see http://www.ogre3d.org/
 47 #
 48 # The contents of this file are placed in the public domain. Feel
 49 # free to make use of it in any way you like.
 50 #-------------------------------------------------------------------
 51 #
 52 #=============================================================================
 53 # Copyright 2010-2012 Kitware, Inc.
 54 # Copyright 2012      Rolf Eike Beer <eike@sf-mail.de>
 55 #
 56 # Distributed under the OSI-approved BSD License (the "License");
 57 # see accompanying file COPYING-CMAKE-SCRIPTS for details.
 58 #
 59 # This software is distributed WITHOUT ANY WARRANTY; without even the
 60 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 61 # See the License for more information.
 62 #=============================================================================
 63 
 64 #=============================================================================
 65 #  FindTBB helper functions and macros
 66 #
 67 
 68 # Use TBBConfig.cmake if possible.
 69 
 70 set(_tbb_find_quiet)
 71 if (TBB_FIND_QUIETLY)
 72   set(_tbb_find_quiet QUIET)
 73 endif ()
 74 set(_tbb_find_components)
 75 set(_tbb_find_optional_components)
 76 foreach (_tbb_find_component IN LISTS TBB_FIND_COMPONENTS)
 77   if (TBB_FIND_REQUIRED_${_tbb_find_component})
 78     list(APPEND _tbb_find_components "${_tbb_find_component}")
 79   else ()
 80     list(APPEND _tbb_find_optional_components "${_tbb_find_component}")
 81   endif ()
 82 endforeach ()
 83 unset(_tbb_find_component)
 84 find_package(TBB CONFIG ${_tbb_find_quiet}
 85   COMPONENTS ${_tbb_find_components}
 86   OPTIONAL_COMPONENTS ${_tbb_find_optional_components})
 87 unset(_tbb_find_quiet)
 88 unset(_tbb_find_components)
 89 unset(_tbb_find_optional_components)
 90 if (TBB_FOUND)
 91   return ()
 92 endif ()
 93 
 94 #====================================================
 95 # Fix the library path in case it is a linker script
 96 #====================================================
 97 function(tbb_extract_real_library library real_library)
 98   if(NOT UNIX OR NOT EXISTS ${library})
 99     set(${real_library} "${library}" PARENT_SCOPE)
100     return()
101   endif()
102 
103   #Read in the first 4 bytes and see if they are the ELF magic number
104   set(_elf_magic "7f454c46")
105   file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX)
106   if(_hex_data STREQUAL _elf_magic)
107     #we have opened a elf binary so this is what
108     #we should link to
109     set(${real_library} "${library}" PARENT_SCOPE)
110     return()
111   endif()
112 
113   file(READ ${library} _data OFFSET 0 LIMIT 1024)
114   if("${_data}" MATCHES "INPUT \\(([^(]+)\\)")
115     #extract out the .so name from REGEX MATCH command
116     set(_proper_so_name "${CMAKE_MATCH_1}")
117 
118     #construct path to the real .so which is presumed to be in the same directory
119     #as the input file
120     get_filename_component(_so_dir "${library}" DIRECTORY)
121     set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE)
122   else()
123     #unable to determine what this library is so just hope everything works
124     #and pass it unmodified.
125     set(${real_library} "${library}" PARENT_SCOPE)
126   endif()
127 endfunction()
128 
129 #===============================================
130 # Do the final processing for the package find.
131 #===============================================
132 macro(findpkg_finish PREFIX TARGET_NAME)
133   if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
134     set(${PREFIX}_FOUND TRUE)
135     set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
136     set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
137   else ()
138     if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY)
139       message(FATAL_ERROR "Required library ${PREFIX} not found.")
140     endif ()
141   endif ()
142 
143   if (NOT TARGET "TBB::${TARGET_NAME}")
144     if (${PREFIX}_LIBRARY_RELEASE)
145       tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release)
146     endif ()
147     if (${PREFIX}_LIBRARY_DEBUG)
148       tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug)
149     endif ()
150     add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED)
151     set_target_properties(TBB::${TARGET_NAME} PROPERTIES
152       INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}")
153     if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE)
154       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
155         IMPORTED_LOCATION "${real_release}"
156         IMPORTED_LOCATION_DEBUG "${real_debug}"
157         IMPORTED_LOCATION_RELEASE "${real_release}")
158     elseif (${PREFIX}_LIBRARY_RELEASE)
159       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
160         IMPORTED_LOCATION "${real_release}")
161     elseif (${PREFIX}_LIBRARY_DEBUG)
162       set_target_properties(TBB::${TARGET_NAME} PROPERTIES
163         IMPORTED_LOCATION "${real_debug}")
164     endif ()
165   endif ()
166 
167   #mark the following variables as internal variables
168   mark_as_advanced(${PREFIX}_INCLUDE_DIR
169                    ${PREFIX}_LIBRARY
170                    ${PREFIX}_LIBRARY_DEBUG
171                    ${PREFIX}_LIBRARY_RELEASE)
172 endmacro()
173 
174 #===============================================
175 # Generate debug names from given release names
176 #===============================================
177 macro(get_debug_names PREFIX)
178   foreach(i ${${PREFIX}})
179     set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
180   endforeach()
181 endmacro()
182 
183 #===============================================
184 # See if we have env vars to help us find tbb
185 #===============================================
186 macro(getenv_path VAR)
187    set(ENV_${VAR} $ENV{${VAR}})
188    # replace won't work if var is blank
189    if (ENV_${VAR})
190      string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
191    endif ()
192 endmacro()
193 
194 #===============================================
195 # Couple a set of release AND debug libraries
196 #===============================================
197 macro(make_library_set PREFIX)
198   if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG)
199     set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG})
200   elseif (${PREFIX}_RELEASE)
201     set(${PREFIX} ${${PREFIX}_RELEASE})
202   elseif (${PREFIX}_DEBUG)
203     set(${PREFIX} ${${PREFIX}_DEBUG})
204   endif ()
205 endmacro()
206 
207 
208 #=============================================================================
209 #  Now to actually find TBB
210 #
211 
212 # Get path, convert backslashes as ${ENV_${var}}
213 getenv_path(TBB_ROOT)
214 
215 # initialize search paths
216 set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT})
217 set(TBB_INC_SEARCH_PATH "")
218 set(TBB_LIB_SEARCH_PATH "")
219 
220 
221 # If user built from sources
222 set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX})
223 if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT)
224   getenv_path(TBB_BUILD_DIR)
225   if (NOT ENV_TBB_BUILD_DIR)
226     set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build)
227   endif ()
228 
229   # include directory under ${ENV_TBB_ROOT}/include
230   list(APPEND TBB_LIB_SEARCH_PATH
231     ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
232     ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug)
233 endif ()
234 
235 
236 # For Windows, let's assume that the user might be using the precompiled
237 # TBB packages from the main website. These use a rather awkward directory
238 # structure (at least for automatically finding the right files) depending
239 # on platform and compiler, but we'll do our best to accommodate it.
240 # Not adding the same effort for the precompiled linux builds, though. Those
241 # have different versions for CC compiler versions and linux kernels which
242 # will never adequately match the user's setup, so there is no feasible way
243 # to detect the "best" version to use. The user will have to manually
244 # select the right files. (Chances are the distributions are shipping their
245 # custom version of tbb, anyway, so the problem is probably nonexistent.)
246 if (WIN32 AND MSVC)
247   set(COMPILER_PREFIX "vc7.1")
248   if (MSVC_VERSION EQUAL 1400)
249     set(COMPILER_PREFIX "vc8")
250   elseif(MSVC_VERSION EQUAL 1500)
251     set(COMPILER_PREFIX "vc9")
252   elseif(MSVC_VERSION EQUAL 1600)
253     set(COMPILER_PREFIX "vc10")
254   elseif(MSVC_VERSION EQUAL 1700)
255     set(COMPILER_PREFIX "vc11")
256   elseif(MSVC_VERSION EQUAL 1800)
257     set(COMPILER_PREFIX "vc12")
258   elseif(MSVC_VERSION GREATER_EQUAL 1900)
259     set(COMPILER_PREFIX "vc14")
260   endif ()
261 
262   # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
263   foreach (dir IN LISTS TBB_PREFIX_PATH)
264     if (CMAKE_CL_64)
265       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
266       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
267       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib)
268       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX})
269     else ()
270       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
271       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
272     endif ()
273   endforeach ()
274 endif ()
275 
276 # For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
277 # and above and AppleClang
278 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
279     NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0)
280   set (USE_LIBCXX OFF)
281   cmake_policy(GET CMP0025 POLICY_VAR)
282 
283   if (POLICY_VAR STREQUAL "NEW")
284     if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
285       set (USE_LIBCXX ON)
286     endif ()
287   else ()
288     if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
289       set (USE_LIBCXX ON)
290     endif ()
291   endif ()
292 
293   if (USE_LIBCXX)
294     foreach (dir IN LISTS TBB_PREFIX_PATH)
295       list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
296     endforeach ()
297   endif ()
298 endif ()
299 
300 # check compiler ABI
301 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
302   set(COMPILER_PREFIX)
303   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
304     list(APPEND COMPILER_PREFIX "gcc4.8")
305   endif()
306   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
307     list(APPEND COMPILER_PREFIX "gcc4.7")
308   endif()
309   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
310     list(APPEND COMPILER_PREFIX "gcc4.4")
311   endif()
312   list(APPEND COMPILER_PREFIX "gcc4.1")
313 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
314   set(COMPILER_PREFIX)
315   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
316     list(APPEND COMPILER_PREFIX "gcc4.8")
317   endif()
318   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
319     list(APPEND COMPILER_PREFIX "gcc4.7")
320   endif()
321   list(APPEND COMPILER_PREFIX "gcc4.4")
322 else() # Assume compatibility with 4.4 for other compilers
323   list(APPEND COMPILER_PREFIX "gcc4.4")
324 endif ()
325 
326 # if platform architecture is explicitly specified
327 set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
328 if (TBB_ARCH_PLATFORM)
329   foreach (dir IN LISTS TBB_PREFIX_PATH)
330     list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
331     list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
332   endforeach ()
333 endif ()
334 
335 foreach (dir IN LISTS TBB_PREFIX_PATH)
336   foreach (prefix IN LISTS COMPILER_PREFIX)
337     if (CMAKE_SIZEOF_VOID_P EQUAL 8)
338       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
339       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
340       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
341       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
342     else ()
343       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
344       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
345       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
346       list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
347     endif ()
348   endforeach()
349 endforeach ()
350 
351 # add general search paths
352 foreach (dir IN LISTS TBB_PREFIX_PATH)
353   list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb
354     ${dir}/Libs)
355   list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include
356     ${dir}/include/tbb)
357 endforeach ()
358 
359 set(TBB_LIBRARY_NAMES tbb)
360 get_debug_names(TBB_LIBRARY_NAMES)
361 
362 
363 find_path(TBB_INCLUDE_DIR
364           NAMES tbb/tbb.h
365           PATHS ${TBB_INC_SEARCH_PATH})
366 
367 find_library(TBB_LIBRARY_RELEASE
368              NAMES ${TBB_LIBRARY_NAMES}
369              PATHS ${TBB_LIB_SEARCH_PATH})
370 find_library(TBB_LIBRARY_DEBUG
371              NAMES ${TBB_LIBRARY_NAMES_DEBUG}
372              PATHS ${TBB_LIB_SEARCH_PATH})
373 make_library_set(TBB_LIBRARY)
374 
375 findpkg_finish(TBB tbb)
376 
377 #if we haven't found TBB no point on going any further
378 if (NOT TBB_FOUND)
379   return()
380 endif ()
381 
382 #=============================================================================
383 # Look for TBB's malloc package
384 set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
385 get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
386 
387 find_path(TBB_MALLOC_INCLUDE_DIR
388           NAMES tbb/tbb.h
389           PATHS ${TBB_INC_SEARCH_PATH})
390 
391 find_library(TBB_MALLOC_LIBRARY_RELEASE
392              NAMES ${TBB_MALLOC_LIBRARY_NAMES}
393              PATHS ${TBB_LIB_SEARCH_PATH})
394 find_library(TBB_MALLOC_LIBRARY_DEBUG
395              NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
396              PATHS ${TBB_LIB_SEARCH_PATH})
397 make_library_set(TBB_MALLOC_LIBRARY)
398 
399 findpkg_finish(TBB_MALLOC tbbmalloc)
400 
401 #=============================================================================
402 # Look for TBB's malloc proxy package
403 set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
404 get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
405 
406 find_path(TBB_MALLOC_PROXY_INCLUDE_DIR
407           NAMES tbb/tbbmalloc_proxy.h
408           PATHS ${TBB_INC_SEARCH_PATH})
409 
410 find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE
411              NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
412              PATHS ${TBB_LIB_SEARCH_PATH})
413 find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG
414              NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
415              PATHS ${TBB_LIB_SEARCH_PATH})
416 make_library_set(TBB_MALLOC_PROXY_LIBRARY)
417 
418 findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
419 
420 
421 #=============================================================================
422 #parse all the version numbers from tbb
423 if(NOT TBB_VERSION)
424   if (EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h")
425     file(STRINGS
426       "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h"
427       TBB_VERSION_CONTENTS
428       REGEX "VERSION")
429   else()
430     #only read the start of the file
431     file(STRINGS
432       "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
433       TBB_VERSION_CONTENTS
434       REGEX "VERSION")
435   endif()
436 
437   string(REGEX REPLACE
438     ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
439     TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}")
440 
441   string(REGEX REPLACE
442     ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
443     TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}")
444 
445   string(REGEX REPLACE
446         ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
447         TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
448 
449   string(REGEX REPLACE
450         ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1"
451         TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
452 
453   set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
454 
455 endif()
456 
457 include(FindPackageHandleStandardArgs)
458 find_package_handle_standard_args(TBB
459   REQUIRED_VARS TBB_INCLUDE_DIR TBB_LIBRARY
460   VERSION_VAR TBB_VERSION)