Warning, /acts/cmake/FindTBB.cmake is written in an unsupported language. File is not indexed.
0001 # - Find ThreadingBuildingBlocks include dirs and libraries
0002 # Use this module by invoking find_package with the form:
0003 # find_package(TBB
0004 # [REQUIRED] # Fail with error if TBB is not found
0005 # ) #
0006 # Once done, this will define
0007 #
0008 # TBB_FOUND - system has TBB
0009 # TBB_INCLUDE_DIRS - the TBB include directories
0010 # TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or
0011 # malloc proxy
0012 # TBB::tbb - imported target for the TBB library
0013 #
0014 # TBB_VERSION_MAJOR - Major Product Version Number
0015 # TBB_VERSION_MINOR - Minor Product Version Number
0016 # TBB_INTERFACE_VERSION - Engineering Focused Version Number
0017 # TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version
0018 # still supported. This uses the engineering
0019 # focused interface version numbers.
0020 #
0021 # TBB_MALLOC_FOUND - system has TBB malloc library
0022 # TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories
0023 # TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined
0024 # TBB::malloc - imported target for the TBB malloc library
0025 #
0026 # TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library
0027 # TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories
0028 # TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined
0029 # TBB::malloc_proxy - imported target for the TBB malloc proxy library
0030 #
0031 #
0032 # This module reads hints about search locations from variables:
0033 # ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds
0034 # ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation
0035 # ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb
0036 # libraries. Should be specified with ENV TBB_ROOT
0037 # and optionally...
0038 # ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build
0039 #
0040 #
0041 # Modified by Robert Maynard from the original OGRE source
0042 #
0043 #-------------------------------------------------------------------
0044 # This file is part of the CMake build system for OGRE
0045 # (Object-oriented Graphics Rendering Engine)
0046 # For the latest info, see http://www.ogre3d.org/
0047 #
0048 # The contents of this file are placed in the public domain. Feel
0049 # free to make use of it in any way you like.
0050 #-------------------------------------------------------------------
0051 #
0052 #=============================================================================
0053 # Copyright 2010-2012 Kitware, Inc.
0054 # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
0055 #
0056 # Distributed under the OSI-approved BSD License (the "License");
0057 # see accompanying file Copyright.txt for details.
0058 #
0059 # This software is distributed WITHOUT ANY WARRANTY; without even the
0060 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0061 # See the License for more information.
0062 #=============================================================================
0063 # (To distribute this file outside of CMake, substitute the full
0064 # License text for the above reference.)
0065
0066
0067 #=============================================================================
0068 # FindTBB helper functions and macros
0069 #
0070
0071 # Use TBBConfig.cmake if possible.
0072
0073 set(_tbb_find_quiet)
0074 if (TBB_FIND_QUIETLY)
0075 set(_tbb_find_quiet QUIET)
0076 endif ()
0077 set(_tbb_find_components)
0078 set(_tbb_find_optional_components)
0079 foreach (_tbb_find_component IN LISTS TBB_FIND_COMPONENTS)
0080 if (TBB_FIND_REQUIRED_${_tbb_find_component})
0081 list(APPEND _tbb_find_components "${_tbb_find_component}")
0082 else ()
0083 list(APPEND _tbb_find_optional_components "${_tbb_find_component}")
0084 endif ()
0085 endforeach ()
0086 unset(_tbb_find_component)
0087 find_package(TBB CONFIG ${_tbb_find_quiet}
0088 COMPONENTS ${_tbb_find_components}
0089 OPTIONAL_COMPONENTS ${_tbb_find_optional_components})
0090 unset(_tbb_find_quiet)
0091 unset(_tbb_find_components)
0092 unset(_tbb_find_optional_components)
0093 if (TBB_FOUND)
0094 return ()
0095 endif ()
0096
0097 #====================================================
0098 # Fix the library path in case it is a linker script
0099 #====================================================
0100 function(tbb_extract_real_library library real_library)
0101 if(NOT UNIX OR NOT EXISTS ${library})
0102 set(${real_library} "${library}" PARENT_SCOPE)
0103 return()
0104 endif()
0105
0106 #Read in the first 4 bytes and see if they are the ELF magic number
0107 set(_elf_magic "7f454c46")
0108 file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX)
0109 if(_hex_data STREQUAL _elf_magic)
0110 #we have opened a elf binary so this is what
0111 #we should link to
0112 set(${real_library} "${library}" PARENT_SCOPE)
0113 return()
0114 endif()
0115
0116 file(READ ${library} _data OFFSET 0 LIMIT 1024)
0117 if("${_data}" MATCHES "INPUT \\(([^(]+)\\)")
0118 #extract out the .so name from REGEX MATCH command
0119 set(_proper_so_name "${CMAKE_MATCH_1}")
0120
0121 #construct path to the real .so which is presumed to be in the same directory
0122 #as the input file
0123 get_filename_component(_so_dir "${library}" DIRECTORY)
0124 set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE)
0125 else()
0126 #unable to determine what this library is so just hope everything works
0127 #and pass it unmodified.
0128 set(${real_library} "${library}" PARENT_SCOPE)
0129 endif()
0130 endfunction()
0131
0132 #===============================================
0133 # Do the final processing for the package find.
0134 #===============================================
0135 macro(findpkg_finish PREFIX TARGET_NAME)
0136 if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
0137 set(${PREFIX}_FOUND TRUE)
0138 set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
0139 set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
0140 else ()
0141 if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY)
0142 message(FATAL_ERROR "Required library ${PREFIX} not found.")
0143 endif ()
0144 endif ()
0145
0146 if (NOT TARGET "TBB::${TARGET_NAME}")
0147 if (${PREFIX}_LIBRARY_RELEASE)
0148 tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release)
0149 endif ()
0150 if (${PREFIX}_LIBRARY_DEBUG)
0151 tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug)
0152 endif ()
0153 add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED)
0154 set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0155 INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}")
0156 if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE)
0157 set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0158 IMPORTED_LOCATION "${real_release}"
0159 IMPORTED_LOCATION_DEBUG "${real_debug}"
0160 IMPORTED_LOCATION_RELEASE "${real_release}")
0161 elseif (${PREFIX}_LIBRARY_RELEASE)
0162 set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0163 IMPORTED_LOCATION "${real_release}")
0164 elseif (${PREFIX}_LIBRARY_DEBUG)
0165 set_target_properties(TBB::${TARGET_NAME} PROPERTIES
0166 IMPORTED_LOCATION "${real_debug}")
0167 endif ()
0168 endif ()
0169
0170 #mark the following variables as internal variables
0171 mark_as_advanced(${PREFIX}_INCLUDE_DIR
0172 ${PREFIX}_LIBRARY
0173 ${PREFIX}_LIBRARY_DEBUG
0174 ${PREFIX}_LIBRARY_RELEASE)
0175 endmacro()
0176
0177 #===============================================
0178 # Generate debug names from given release names
0179 #===============================================
0180 macro(get_debug_names PREFIX)
0181 foreach(i ${${PREFIX}})
0182 set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
0183 endforeach()
0184 endmacro()
0185
0186 #===============================================
0187 # See if we have env vars to help us find tbb
0188 #===============================================
0189 macro(getenv_path VAR)
0190 set(ENV_${VAR} $ENV{${VAR}})
0191 # replace won't work if var is blank
0192 if (ENV_${VAR})
0193 string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
0194 endif ()
0195 endmacro()
0196
0197 #===============================================
0198 # Couple a set of release AND debug libraries
0199 #===============================================
0200 macro(make_library_set PREFIX)
0201 if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG)
0202 set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG})
0203 elseif (${PREFIX}_RELEASE)
0204 set(${PREFIX} ${${PREFIX}_RELEASE})
0205 elseif (${PREFIX}_DEBUG)
0206 set(${PREFIX} ${${PREFIX}_DEBUG})
0207 endif ()
0208 endmacro()
0209
0210
0211 #=============================================================================
0212 # Now to actually find TBB
0213 #
0214
0215 # Get path, convert backslashes as ${ENV_${var}}
0216 getenv_path(TBB_ROOT)
0217
0218 # initialize search paths
0219 set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT})
0220 set(TBB_INC_SEARCH_PATH "")
0221 set(TBB_LIB_SEARCH_PATH "")
0222
0223
0224 # If user built from sources
0225 set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX})
0226 if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT)
0227 getenv_path(TBB_BUILD_DIR)
0228 if (NOT ENV_TBB_BUILD_DIR)
0229 set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build)
0230 endif ()
0231
0232 # include directory under ${ENV_TBB_ROOT}/include
0233 list(APPEND TBB_LIB_SEARCH_PATH
0234 ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
0235 ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug)
0236 endif ()
0237
0238
0239 # For Windows, let's assume that the user might be using the precompiled
0240 # TBB packages from the main website. These use a rather awkward directory
0241 # structure (at least for automatically finding the right files) depending
0242 # on platform and compiler, but we'll do our best to accommodate it.
0243 # Not adding the same effort for the precompiled linux builds, though. Those
0244 # have different versions for CC compiler versions and linux kernels which
0245 # will never adequately match the user's setup, so there is no feasible way
0246 # to detect the "best" version to use. The user will have to manually
0247 # select the right files. (Chances are the distributions are shipping their
0248 # custom version of tbb, anyway, so the problem is probably nonexistent.)
0249 if (WIN32 AND MSVC)
0250 set(COMPILER_PREFIX "vc7.1")
0251 if (MSVC_VERSION EQUAL 1400)
0252 set(COMPILER_PREFIX "vc8")
0253 elseif(MSVC_VERSION EQUAL 1500)
0254 set(COMPILER_PREFIX "vc9")
0255 elseif(MSVC_VERSION EQUAL 1600)
0256 set(COMPILER_PREFIX "vc10")
0257 elseif(MSVC_VERSION EQUAL 1700)
0258 set(COMPILER_PREFIX "vc11")
0259 elseif(MSVC_VERSION EQUAL 1800)
0260 set(COMPILER_PREFIX "vc12")
0261 elseif(MSVC_VERSION GREATER_EQUAL 1900)
0262 set(COMPILER_PREFIX "vc14")
0263 endif ()
0264
0265 # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
0266 foreach (dir IN LISTS TBB_PREFIX_PATH)
0267 if (CMAKE_CL_64)
0268 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
0269 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
0270 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib)
0271 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX})
0272 else ()
0273 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
0274 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
0275 endif ()
0276 endforeach ()
0277 endif ()
0278
0279 # For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
0280 # and above and AppleClang
0281 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
0282 NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0)
0283 set (USE_LIBCXX OFF)
0284 cmake_policy(GET CMP0025 POLICY_VAR)
0285
0286 if (POLICY_VAR STREQUAL "NEW")
0287 if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0288 set (USE_LIBCXX ON)
0289 endif ()
0290 else ()
0291 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
0292 set (USE_LIBCXX ON)
0293 endif ()
0294 endif ()
0295
0296 if (USE_LIBCXX)
0297 foreach (dir IN LISTS TBB_PREFIX_PATH)
0298 list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
0299 endforeach ()
0300 endif ()
0301 endif ()
0302
0303 # check compiler ABI
0304 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0305 set(COMPILER_PREFIX)
0306 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
0307 list(APPEND COMPILER_PREFIX "gcc4.8")
0308 endif()
0309 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
0310 list(APPEND COMPILER_PREFIX "gcc4.7")
0311 endif()
0312 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
0313 list(APPEND COMPILER_PREFIX "gcc4.4")
0314 endif()
0315 list(APPEND COMPILER_PREFIX "gcc4.1")
0316 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0317 set(COMPILER_PREFIX)
0318 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
0319 list(APPEND COMPILER_PREFIX "gcc4.8")
0320 endif()
0321 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
0322 list(APPEND COMPILER_PREFIX "gcc4.7")
0323 endif()
0324 list(APPEND COMPILER_PREFIX "gcc4.4")
0325 else() # Assume compatibility with 4.4 for other compilers
0326 list(APPEND COMPILER_PREFIX "gcc4.4")
0327 endif ()
0328
0329 # if platform architecture is explicitly specified
0330 set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
0331 if (TBB_ARCH_PLATFORM)
0332 foreach (dir IN LISTS TBB_PREFIX_PATH)
0333 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
0334 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
0335 endforeach ()
0336 endif ()
0337
0338 foreach (dir IN LISTS TBB_PREFIX_PATH)
0339 foreach (prefix IN LISTS COMPILER_PREFIX)
0340 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
0341 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
0342 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
0343 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
0344 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
0345 else ()
0346 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
0347 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
0348 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
0349 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
0350 endif ()
0351 endforeach()
0352 endforeach ()
0353
0354 # add general search paths
0355 foreach (dir IN LISTS TBB_PREFIX_PATH)
0356 list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb
0357 ${dir}/Libs)
0358 list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include
0359 ${dir}/include/tbb)
0360 endforeach ()
0361
0362 set(TBB_LIBRARY_NAMES tbb)
0363 get_debug_names(TBB_LIBRARY_NAMES)
0364
0365
0366 find_path(TBB_INCLUDE_DIR
0367 NAMES tbb/tbb.h
0368 PATHS ${TBB_INC_SEARCH_PATH})
0369
0370 find_library(TBB_LIBRARY_RELEASE
0371 NAMES ${TBB_LIBRARY_NAMES}
0372 PATHS ${TBB_LIB_SEARCH_PATH})
0373 find_library(TBB_LIBRARY_DEBUG
0374 NAMES ${TBB_LIBRARY_NAMES_DEBUG}
0375 PATHS ${TBB_LIB_SEARCH_PATH})
0376 make_library_set(TBB_LIBRARY)
0377
0378 findpkg_finish(TBB tbb)
0379
0380 #if we haven't found TBB no point on going any further
0381 if (NOT TBB_FOUND)
0382 return()
0383 endif ()
0384
0385 #=============================================================================
0386 # Look for TBB's malloc package
0387 set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
0388 get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
0389
0390 find_path(TBB_MALLOC_INCLUDE_DIR
0391 NAMES tbb/tbb.h
0392 PATHS ${TBB_INC_SEARCH_PATH})
0393
0394 find_library(TBB_MALLOC_LIBRARY_RELEASE
0395 NAMES ${TBB_MALLOC_LIBRARY_NAMES}
0396 PATHS ${TBB_LIB_SEARCH_PATH})
0397 find_library(TBB_MALLOC_LIBRARY_DEBUG
0398 NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
0399 PATHS ${TBB_LIB_SEARCH_PATH})
0400 make_library_set(TBB_MALLOC_LIBRARY)
0401
0402 findpkg_finish(TBB_MALLOC tbbmalloc)
0403
0404 #=============================================================================
0405 # Look for TBB's malloc proxy package
0406 set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
0407 get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
0408
0409 find_path(TBB_MALLOC_PROXY_INCLUDE_DIR
0410 NAMES tbb/tbbmalloc_proxy.h
0411 PATHS ${TBB_INC_SEARCH_PATH})
0412
0413 find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE
0414 NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
0415 PATHS ${TBB_LIB_SEARCH_PATH})
0416 find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG
0417 NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
0418 PATHS ${TBB_LIB_SEARCH_PATH})
0419 make_library_set(TBB_MALLOC_PROXY_LIBRARY)
0420
0421 findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
0422
0423
0424 #=============================================================================
0425 #parse all the version numbers from tbb
0426 if(NOT TBB_VERSION)
0427 if (EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h")
0428 file(STRINGS
0429 "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h"
0430 TBB_VERSION_CONTENTS
0431 REGEX "VERSION")
0432 else()
0433 #only read the start of the file
0434 file(STRINGS
0435 "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
0436 TBB_VERSION_CONTENTS
0437 REGEX "VERSION")
0438 endif()
0439
0440 string(REGEX REPLACE
0441 ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
0442 TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}")
0443
0444 string(REGEX REPLACE
0445 ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
0446 TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}")
0447
0448 string(REGEX REPLACE
0449 ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
0450 TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
0451
0452 string(REGEX REPLACE
0453 ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1"
0454 TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}")
0455
0456 endif()