Back to home page

EIC code displayed by LXR

 
 

    


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 #  FindTBB helper functions and macros
0068 #
0069 
0070 # Use TBBConfig.cmake if possible.
0071 
0072 set(_tbb_find_quiet)
0073 if(TBB_FIND_QUIETLY)
0074     set(_tbb_find_quiet QUIET)
0075 endif()
0076 set(_tbb_find_components)
0077 set(_tbb_find_optional_components)
0078 foreach(_tbb_find_component IN LISTS TBB_FIND_COMPONENTS)
0079     if(TBB_FIND_REQUIRED_${_tbb_find_component})
0080         list(APPEND _tbb_find_components "${_tbb_find_component}")
0081     else()
0082         list(APPEND _tbb_find_optional_components "${_tbb_find_component}")
0083     endif()
0084 endforeach()
0085 unset(_tbb_find_component)
0086 find_package(
0087     TBB
0088     CONFIG
0089     ${_tbb_find_quiet}
0090     COMPONENTS ${_tbb_find_components}
0091     OPTIONAL_COMPONENTS ${_tbb_find_optional_components}
0092 )
0093 unset(_tbb_find_quiet)
0094 unset(_tbb_find_components)
0095 unset(_tbb_find_optional_components)
0096 if(TBB_FOUND)
0097     return()
0098 endif()
0099 
0100 #====================================================
0101 # Fix the library path in case it is a linker script
0102 #====================================================
0103 function(tbb_extract_real_library library real_library)
0104     if(NOT UNIX OR NOT EXISTS ${library})
0105         set(${real_library} "${library}" PARENT_SCOPE)
0106         return()
0107     endif()
0108 
0109     #Read in the first 4 bytes and see if they are the ELF magic number
0110     set(_elf_magic "7f454c46")
0111     file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX)
0112     if(_hex_data STREQUAL _elf_magic)
0113         #we have opened a elf binary so this is what
0114         #we should link to
0115         set(${real_library} "${library}" PARENT_SCOPE)
0116         return()
0117     endif()
0118 
0119     file(READ ${library} _data OFFSET 0 LIMIT 1024)
0120     if("${_data}" MATCHES "INPUT \\(([^(]+)\\)")
0121         #extract out the .so name from REGEX MATCH command
0122         set(_proper_so_name "${CMAKE_MATCH_1}")
0123 
0124         #construct path to the real .so which is presumed to be in the same directory
0125         #as the input file
0126         get_filename_component(_so_dir "${library}" DIRECTORY)
0127         set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE)
0128     else()
0129         #unable to determine what this library is so just hope everything works
0130         #and pass it unmodified.
0131         set(${real_library} "${library}" PARENT_SCOPE)
0132     endif()
0133 endfunction()
0134 
0135 #===============================================
0136 # Do the final processing for the package find.
0137 #===============================================
0138 macro(findpkg_finish PREFIX TARGET_NAME)
0139     if(${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
0140         set(${PREFIX}_FOUND TRUE)
0141         set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
0142         set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
0143     else()
0144         if(${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY)
0145             message(FATAL_ERROR "Required library ${PREFIX} not found.")
0146         endif()
0147     endif()
0148 
0149     if(NOT TARGET "TBB::${TARGET_NAME}")
0150         if(${PREFIX}_LIBRARY_RELEASE)
0151             tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release)
0152         endif()
0153         if(${PREFIX}_LIBRARY_DEBUG)
0154             tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug)
0155         endif()
0156         add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED)
0157         set_target_properties(
0158             TBB::${TARGET_NAME}
0159             PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}"
0160         )
0161         if(${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE)
0162             set_target_properties(
0163                 TBB::${TARGET_NAME}
0164                 PROPERTIES
0165                     IMPORTED_LOCATION "${real_release}"
0166                     IMPORTED_LOCATION_DEBUG "${real_debug}"
0167                     IMPORTED_LOCATION_RELEASE "${real_release}"
0168             )
0169         elseif(${PREFIX}_LIBRARY_RELEASE)
0170             set_target_properties(
0171                 TBB::${TARGET_NAME}
0172                 PROPERTIES IMPORTED_LOCATION "${real_release}"
0173             )
0174         elseif(${PREFIX}_LIBRARY_DEBUG)
0175             set_target_properties(
0176                 TBB::${TARGET_NAME}
0177                 PROPERTIES IMPORTED_LOCATION "${real_debug}"
0178             )
0179         endif()
0180     endif()
0181 
0182     #mark the following variables as internal variables
0183     mark_as_advanced(
0184         ${PREFIX}_INCLUDE_DIR
0185         ${PREFIX}_LIBRARY
0186         ${PREFIX}_LIBRARY_DEBUG
0187         ${PREFIX}_LIBRARY_RELEASE
0188     )
0189 endmacro()
0190 
0191 #===============================================
0192 # Generate debug names from given release names
0193 #===============================================
0194 macro(get_debug_names PREFIX)
0195     foreach(i ${${PREFIX}})
0196         set(${PREFIX}_DEBUG
0197             ${${PREFIX}_DEBUG}
0198             ${i}d
0199             ${i}D
0200             ${i}_d
0201             ${i}_D
0202             ${i}_debug
0203             ${i}
0204         )
0205     endforeach()
0206 endmacro()
0207 
0208 #===============================================
0209 # See if we have env vars to help us find tbb
0210 #===============================================
0211 macro(getenv_path VAR)
0212     set(ENV_${VAR} $ENV{${VAR}})
0213     # replace won't work if var is blank
0214     if(ENV_${VAR})
0215         string(REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}})
0216     endif()
0217 endmacro()
0218 
0219 #===============================================
0220 # Couple a set of release AND debug libraries
0221 #===============================================
0222 macro(make_library_set PREFIX)
0223     if(${PREFIX}_RELEASE AND ${PREFIX}_DEBUG)
0224         set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG})
0225     elseif(${PREFIX}_RELEASE)
0226         set(${PREFIX} ${${PREFIX}_RELEASE})
0227     elseif(${PREFIX}_DEBUG)
0228         set(${PREFIX} ${${PREFIX}_DEBUG})
0229     endif()
0230 endmacro()
0231 
0232 #=============================================================================
0233 #  Now to actually find TBB
0234 #
0235 
0236 # Get path, convert backslashes as ${ENV_${var}}
0237 getenv_path(TBB_ROOT)
0238 
0239 # initialize search paths
0240 set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT})
0241 set(TBB_INC_SEARCH_PATH "")
0242 set(TBB_LIB_SEARCH_PATH "")
0243 
0244 # If user built from sources
0245 set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX})
0246 if(TBB_BUILD_PREFIX AND ENV_TBB_ROOT)
0247     getenv_path(TBB_BUILD_DIR)
0248     if(NOT ENV_TBB_BUILD_DIR)
0249         set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build)
0250     endif()
0251 
0252     # include directory under ${ENV_TBB_ROOT}/include
0253     list(
0254         APPEND
0255         TBB_LIB_SEARCH_PATH
0256         ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
0257         ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug
0258     )
0259 endif()
0260 
0261 # For Windows, let's assume that the user might be using the precompiled
0262 # TBB packages from the main website. These use a rather awkward directory
0263 # structure (at least for automatically finding the right files) depending
0264 # on platform and compiler, but we'll do our best to accommodate it.
0265 # Not adding the same effort for the precompiled linux builds, though. Those
0266 # have different versions for CC compiler versions and linux kernels which
0267 # will never adequately match the user's setup, so there is no feasible way
0268 # to detect the "best" version to use. The user will have to manually
0269 # select the right files. (Chances are the distributions are shipping their
0270 # custom version of tbb, anyway, so the problem is probably nonexistent.)
0271 if(WIN32 AND MSVC)
0272     set(COMPILER_PREFIX "vc7.1")
0273     if(MSVC_VERSION EQUAL 1400)
0274         set(COMPILER_PREFIX "vc8")
0275     elseif(MSVC_VERSION EQUAL 1500)
0276         set(COMPILER_PREFIX "vc9")
0277     elseif(MSVC_VERSION EQUAL 1600)
0278         set(COMPILER_PREFIX "vc10")
0279     elseif(MSVC_VERSION EQUAL 1700)
0280         set(COMPILER_PREFIX "vc11")
0281     elseif(MSVC_VERSION EQUAL 1800)
0282         set(COMPILER_PREFIX "vc12")
0283     elseif(MSVC_VERSION GREATER_EQUAL 1900)
0284         set(COMPILER_PREFIX "vc14")
0285     endif()
0286 
0287     # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
0288     foreach(dir IN LISTS TBB_PREFIX_PATH)
0289         if(CMAKE_CL_64)
0290             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
0291             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
0292             list(
0293                 APPEND
0294                 TBB_LIB_SEARCH_PATH
0295                 ${dir}/intel64/${COMPILER_PREFIX}/lib
0296             )
0297             list(
0298                 APPEND
0299                 TBB_LIB_SEARCH_PATH
0300                 ${dir}/lib/intel64/${COMPILER_PREFIX}
0301             )
0302         else()
0303             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
0304             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
0305         endif()
0306     endforeach()
0307 endif()
0308 
0309 # For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
0310 # and above and AppleClang
0311 if(
0312     CMAKE_SYSTEM_NAME STREQUAL "Darwin"
0313     AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0
0314 )
0315     set(USE_LIBCXX OFF)
0316     cmake_policy(GET CMP0025 POLICY_VAR)
0317 
0318     if(POLICY_VAR STREQUAL "NEW")
0319         if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0320             set(USE_LIBCXX ON)
0321         endif()
0322     else()
0323         if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
0324             set(USE_LIBCXX ON)
0325         endif()
0326     endif()
0327 
0328     if(USE_LIBCXX)
0329         foreach(dir IN LISTS TBB_PREFIX_PATH)
0330             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
0331         endforeach()
0332     endif()
0333 endif()
0334 
0335 # check compiler ABI
0336 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0337     set(COMPILER_PREFIX)
0338     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
0339         list(APPEND COMPILER_PREFIX "gcc4.8")
0340     endif()
0341     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
0342         list(APPEND COMPILER_PREFIX "gcc4.7")
0343     endif()
0344     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
0345         list(APPEND COMPILER_PREFIX "gcc4.4")
0346     endif()
0347     list(APPEND COMPILER_PREFIX "gcc4.1")
0348 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0349     set(COMPILER_PREFIX)
0350     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
0351         list(APPEND COMPILER_PREFIX "gcc4.8")
0352     endif()
0353     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
0354         list(APPEND COMPILER_PREFIX "gcc4.7")
0355     endif()
0356     list(APPEND COMPILER_PREFIX "gcc4.4")
0357 else() # Assume compatibility with 4.4 for other compilers
0358     list(APPEND COMPILER_PREFIX "gcc4.4")
0359 endif()
0360 
0361 # if platform architecture is explicitly specified
0362 set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
0363 if(TBB_ARCH_PLATFORM)
0364     foreach(dir IN LISTS TBB_PREFIX_PATH)
0365         list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
0366         list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
0367     endforeach()
0368 endif()
0369 
0370 foreach(dir IN LISTS TBB_PREFIX_PATH)
0371     foreach(prefix IN LISTS COMPILER_PREFIX)
0372         if(CMAKE_SIZEOF_VOID_P EQUAL 8)
0373             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
0374             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
0375             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
0376             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
0377         else()
0378             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
0379             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
0380             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
0381             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
0382         endif()
0383     endforeach()
0384 endforeach()
0385 
0386 # add general search paths
0387 foreach(dir IN LISTS TBB_PREFIX_PATH)
0388     list(
0389         APPEND
0390         TBB_LIB_SEARCH_PATH
0391         ${dir}/lib
0392         ${dir}/Lib
0393         ${dir}/lib/tbb
0394         ${dir}/Libs
0395     )
0396     list(
0397         APPEND
0398         TBB_INC_SEARCH_PATH
0399         ${dir}/include
0400         ${dir}/Include
0401         ${dir}/include/tbb
0402     )
0403 endforeach()
0404 
0405 set(TBB_LIBRARY_NAMES tbb)
0406 get_debug_names(TBB_LIBRARY_NAMES)
0407 
0408 find_path(TBB_INCLUDE_DIR NAMES tbb/tbb.h PATHS ${TBB_INC_SEARCH_PATH})
0409 
0410 find_library(
0411     TBB_LIBRARY_RELEASE
0412     NAMES ${TBB_LIBRARY_NAMES}
0413     PATHS ${TBB_LIB_SEARCH_PATH}
0414 )
0415 find_library(
0416     TBB_LIBRARY_DEBUG
0417     NAMES ${TBB_LIBRARY_NAMES_DEBUG}
0418     PATHS ${TBB_LIB_SEARCH_PATH}
0419 )
0420 make_library_set(TBB_LIBRARY)
0421 
0422 findpkg_finish(TBB tbb)
0423 
0424 #if we haven't found TBB no point on going any further
0425 if(NOT TBB_FOUND)
0426     return()
0427 endif()
0428 
0429 #=============================================================================
0430 # Look for TBB's malloc package
0431 set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
0432 get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
0433 
0434 find_path(TBB_MALLOC_INCLUDE_DIR NAMES tbb/tbb.h PATHS ${TBB_INC_SEARCH_PATH})
0435 
0436 find_library(
0437     TBB_MALLOC_LIBRARY_RELEASE
0438     NAMES ${TBB_MALLOC_LIBRARY_NAMES}
0439     PATHS ${TBB_LIB_SEARCH_PATH}
0440 )
0441 find_library(
0442     TBB_MALLOC_LIBRARY_DEBUG
0443     NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
0444     PATHS ${TBB_LIB_SEARCH_PATH}
0445 )
0446 make_library_set(TBB_MALLOC_LIBRARY)
0447 
0448 findpkg_finish(TBB_MALLOC tbbmalloc)
0449 
0450 #=============================================================================
0451 # Look for TBB's malloc proxy package
0452 set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
0453 get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
0454 
0455 find_path(
0456     TBB_MALLOC_PROXY_INCLUDE_DIR
0457     NAMES tbb/tbbmalloc_proxy.h
0458     PATHS ${TBB_INC_SEARCH_PATH}
0459 )
0460 
0461 find_library(
0462     TBB_MALLOC_PROXY_LIBRARY_RELEASE
0463     NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
0464     PATHS ${TBB_LIB_SEARCH_PATH}
0465 )
0466 find_library(
0467     TBB_MALLOC_PROXY_LIBRARY_DEBUG
0468     NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
0469     PATHS ${TBB_LIB_SEARCH_PATH}
0470 )
0471 make_library_set(TBB_MALLOC_PROXY_LIBRARY)
0472 
0473 findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
0474 
0475 #=============================================================================
0476 #parse all the version numbers from tbb
0477 if(NOT TBB_VERSION)
0478     if(EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h")
0479         file(
0480             STRINGS
0481             "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h"
0482             TBB_VERSION_CONTENTS
0483             REGEX "VERSION"
0484         )
0485     else()
0486         #only read the start of the file
0487         file(
0488             STRINGS
0489             "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
0490             TBB_VERSION_CONTENTS
0491             REGEX "VERSION"
0492         )
0493     endif()
0494 
0495     string(
0496         REGEX REPLACE
0497         ".*#define TBB_VERSION_MAJOR ([0-9]+).*"
0498         "\\1"
0499         TBB_VERSION_MAJOR
0500         "${TBB_VERSION_CONTENTS}"
0501     )
0502 
0503     string(
0504         REGEX REPLACE
0505         ".*#define TBB_VERSION_MINOR ([0-9]+).*"
0506         "\\1"
0507         TBB_VERSION_MINOR
0508         "${TBB_VERSION_CONTENTS}"
0509     )
0510 
0511     string(
0512         REGEX REPLACE
0513         ".*#define TBB_INTERFACE_VERSION ([0-9]+).*"
0514         "\\1"
0515         TBB_INTERFACE_VERSION
0516         "${TBB_VERSION_CONTENTS}"
0517     )
0518 
0519     string(
0520         REGEX REPLACE
0521         ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*"
0522         "\\1"
0523         TBB_COMPATIBLE_INTERFACE_VERSION
0524         "${TBB_VERSION_CONTENTS}"
0525     )
0526 endif()