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 TBB_LIB_SEARCH_PATH
0255         ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release
0256         ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug
0257     )
0258 endif()
0259 
0260 # For Windows, let's assume that the user might be using the precompiled
0261 # TBB packages from the main website. These use a rather awkward directory
0262 # structure (at least for automatically finding the right files) depending
0263 # on platform and compiler, but we'll do our best to accommodate it.
0264 # Not adding the same effort for the precompiled linux builds, though. Those
0265 # have different versions for CC compiler versions and linux kernels which
0266 # will never adequately match the user's setup, so there is no feasible way
0267 # to detect the "best" version to use. The user will have to manually
0268 # select the right files. (Chances are the distributions are shipping their
0269 # custom version of tbb, anyway, so the problem is probably nonexistent.)
0270 if(WIN32 AND MSVC)
0271     set(COMPILER_PREFIX "vc7.1")
0272     if(MSVC_VERSION EQUAL 1400)
0273         set(COMPILER_PREFIX "vc8")
0274     elseif(MSVC_VERSION EQUAL 1500)
0275         set(COMPILER_PREFIX "vc9")
0276     elseif(MSVC_VERSION EQUAL 1600)
0277         set(COMPILER_PREFIX "vc10")
0278     elseif(MSVC_VERSION EQUAL 1700)
0279         set(COMPILER_PREFIX "vc11")
0280     elseif(MSVC_VERSION EQUAL 1800)
0281         set(COMPILER_PREFIX "vc12")
0282     elseif(MSVC_VERSION GREATER_EQUAL 1900)
0283         set(COMPILER_PREFIX "vc14")
0284     endif()
0285 
0286     # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path
0287     foreach(dir IN LISTS TBB_PREFIX_PATH)
0288         if(CMAKE_CL_64)
0289             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib)
0290             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX})
0291             list(
0292                 APPEND TBB_LIB_SEARCH_PATH
0293                 ${dir}/intel64/${COMPILER_PREFIX}/lib
0294             )
0295             list(
0296                 APPEND TBB_LIB_SEARCH_PATH
0297                 ${dir}/lib/intel64/${COMPILER_PREFIX}
0298             )
0299         else()
0300             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib)
0301             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX})
0302         endif()
0303     endforeach()
0304 endif()
0305 
0306 # For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9)
0307 # and above and AppleClang
0308 if(
0309     CMAKE_SYSTEM_NAME STREQUAL "Darwin"
0310     AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0
0311 )
0312     set(USE_LIBCXX OFF)
0313     cmake_policy(GET CMP0025 POLICY_VAR)
0314 
0315     if(POLICY_VAR STREQUAL "NEW")
0316         if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0317             set(USE_LIBCXX ON)
0318         endif()
0319     else()
0320         if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
0321             set(USE_LIBCXX ON)
0322         endif()
0323     endif()
0324 
0325     if(USE_LIBCXX)
0326         foreach(dir IN LISTS TBB_PREFIX_PATH)
0327             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib)
0328         endforeach()
0329     endif()
0330 endif()
0331 
0332 # check compiler ABI
0333 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0334     set(COMPILER_PREFIX)
0335     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
0336         list(APPEND COMPILER_PREFIX "gcc4.8")
0337     endif()
0338     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
0339         list(APPEND COMPILER_PREFIX "gcc4.7")
0340     endif()
0341     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
0342         list(APPEND COMPILER_PREFIX "gcc4.4")
0343     endif()
0344     list(APPEND COMPILER_PREFIX "gcc4.1")
0345 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
0346     set(COMPILER_PREFIX)
0347     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess
0348         list(APPEND COMPILER_PREFIX "gcc4.8")
0349     endif()
0350     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
0351         list(APPEND COMPILER_PREFIX "gcc4.7")
0352     endif()
0353     list(APPEND COMPILER_PREFIX "gcc4.4")
0354 else() # Assume compatibility with 4.4 for other compilers
0355     list(APPEND COMPILER_PREFIX "gcc4.4")
0356 endif()
0357 
0358 # if platform architecture is explicitly specified
0359 set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM})
0360 if(TBB_ARCH_PLATFORM)
0361     foreach(dir IN LISTS TBB_PREFIX_PATH)
0362         list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib)
0363         list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM})
0364     endforeach()
0365 endif()
0366 
0367 foreach(dir IN LISTS TBB_PREFIX_PATH)
0368     foreach(prefix IN LISTS COMPILER_PREFIX)
0369         if(CMAKE_SIZEOF_VOID_P EQUAL 8)
0370             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64)
0371             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix})
0372             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib)
0373             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib)
0374         else()
0375             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32)
0376             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix})
0377             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib)
0378             list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib)
0379         endif()
0380     endforeach()
0381 endforeach()
0382 
0383 # add general search paths
0384 foreach(dir IN LISTS TBB_PREFIX_PATH)
0385     list(
0386         APPEND TBB_LIB_SEARCH_PATH
0387         ${dir}/lib
0388         ${dir}/Lib
0389         ${dir}/lib/tbb
0390         ${dir}/Libs
0391     )
0392     list(
0393         APPEND TBB_INC_SEARCH_PATH
0394         ${dir}/include
0395         ${dir}/Include
0396         ${dir}/include/tbb
0397     )
0398 endforeach()
0399 
0400 set(TBB_LIBRARY_NAMES tbb)
0401 get_debug_names(TBB_LIBRARY_NAMES)
0402 
0403 find_path(TBB_INCLUDE_DIR NAMES tbb/tbb.h PATHS ${TBB_INC_SEARCH_PATH})
0404 
0405 find_library(
0406     TBB_LIBRARY_RELEASE
0407     NAMES ${TBB_LIBRARY_NAMES}
0408     PATHS ${TBB_LIB_SEARCH_PATH}
0409 )
0410 find_library(
0411     TBB_LIBRARY_DEBUG
0412     NAMES ${TBB_LIBRARY_NAMES_DEBUG}
0413     PATHS ${TBB_LIB_SEARCH_PATH}
0414 )
0415 make_library_set(TBB_LIBRARY)
0416 
0417 findpkg_finish(TBB tbb)
0418 
0419 #if we haven't found TBB no point on going any further
0420 if(NOT TBB_FOUND)
0421     return()
0422 endif()
0423 
0424 #=============================================================================
0425 # Look for TBB's malloc package
0426 set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc)
0427 get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
0428 
0429 find_path(TBB_MALLOC_INCLUDE_DIR NAMES tbb/tbb.h PATHS ${TBB_INC_SEARCH_PATH})
0430 
0431 find_library(
0432     TBB_MALLOC_LIBRARY_RELEASE
0433     NAMES ${TBB_MALLOC_LIBRARY_NAMES}
0434     PATHS ${TBB_LIB_SEARCH_PATH}
0435 )
0436 find_library(
0437     TBB_MALLOC_LIBRARY_DEBUG
0438     NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
0439     PATHS ${TBB_LIB_SEARCH_PATH}
0440 )
0441 make_library_set(TBB_MALLOC_LIBRARY)
0442 
0443 findpkg_finish(TBB_MALLOC tbbmalloc)
0444 
0445 #=============================================================================
0446 # Look for TBB's malloc proxy package
0447 set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy)
0448 get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
0449 
0450 find_path(
0451     TBB_MALLOC_PROXY_INCLUDE_DIR
0452     NAMES tbb/tbbmalloc_proxy.h
0453     PATHS ${TBB_INC_SEARCH_PATH}
0454 )
0455 
0456 find_library(
0457     TBB_MALLOC_PROXY_LIBRARY_RELEASE
0458     NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
0459     PATHS ${TBB_LIB_SEARCH_PATH}
0460 )
0461 find_library(
0462     TBB_MALLOC_PROXY_LIBRARY_DEBUG
0463     NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
0464     PATHS ${TBB_LIB_SEARCH_PATH}
0465 )
0466 make_library_set(TBB_MALLOC_PROXY_LIBRARY)
0467 
0468 findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)
0469 
0470 #=============================================================================
0471 #parse all the version numbers from tbb
0472 if(NOT TBB_VERSION)
0473     if(EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h")
0474         file(
0475             STRINGS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h"
0476             TBB_VERSION_CONTENTS
0477             REGEX "VERSION"
0478         )
0479     else()
0480         #only read the start of the file
0481         file(
0482             STRINGS "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h"
0483             TBB_VERSION_CONTENTS
0484             REGEX "VERSION"
0485         )
0486     endif()
0487 
0488     string(
0489         REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*"
0490         "\\1"
0491         TBB_VERSION_MAJOR
0492         "${TBB_VERSION_CONTENTS}"
0493     )
0494 
0495     string(
0496         REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*"
0497         "\\1"
0498         TBB_VERSION_MINOR
0499         "${TBB_VERSION_CONTENTS}"
0500     )
0501 
0502     string(
0503         REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*"
0504         "\\1"
0505         TBB_INTERFACE_VERSION
0506         "${TBB_VERSION_CONTENTS}"
0507     )
0508 
0509     string(
0510         REGEX REPLACE ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*"
0511         "\\1"
0512         TBB_COMPATIBLE_INTERFACE_VERSION
0513         "${TBB_VERSION_CONTENTS}"
0514     )
0515 endif()