|
| 1 | +#https://github.com/facebook/hhvm/blob/c45055fc3cc6f4db445e0f5efd979f693f65bd8a/CMake/FindTBB.cmake |
| 2 | +# Locate Intel Threading Building Blocks include paths and libraries |
| 3 | +# TBB can be found at http://www.threadingbuildingblocks.org/ |
| 4 | +# Written by Hannes Hofmann, hannes.hofmann _at_ informatik.uni-erlangen.de |
| 5 | +# Adapted by Gino van den Bergen gino _at_ dtecta.com |
| 6 | + |
| 7 | +# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. |
| 8 | +# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" |
| 9 | +# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found |
| 10 | +# in the TBB installation directory (TBB_INSTALL_DIR). |
| 11 | +# |
| 12 | +# For backwards compatibility, you may explicitly set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. |
| 13 | +# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] |
| 14 | +# which architecture to use |
| 15 | +# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 |
| 16 | +# which compiler to use (detected automatically on Windows) |
| 17 | + |
| 18 | +# This module respects |
| 19 | +# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} |
| 20 | + |
| 21 | +# This module defines |
| 22 | +# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. |
| 23 | +# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc |
| 24 | +# TBB_INSTALL_DIR, the base TBB install directory |
| 25 | +# TBB_LIBRARIES, the libraries to link against to use TBB. |
| 26 | +# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. |
| 27 | +# TBB_FOUND, If false, don't try to use TBB. |
| 28 | + |
| 29 | +# lets try in the obvious places first |
| 30 | +find_path(TEST_TBB_INCLUDE_DIR |
| 31 | + tbb/task_scheduler_init.h |
| 32 | +) |
| 33 | +find_library(TEST_TBB_LIBRARY tbb) |
| 34 | + |
| 35 | +if (TEST_TBB_INCLUDE_DIR) |
| 36 | + if(TEST_TBB_LIBRARY) |
| 37 | + set(TBB_OBVIOUS_PLACE "YES") |
| 38 | + endif() |
| 39 | +endif() |
| 40 | + |
| 41 | + |
| 42 | +if (WIN32) |
| 43 | + # has em64t/vc8 em64t/vc9 |
| 44 | + # has ia32/vc7.1 ia32/vc8 ia32/vc9 |
| 45 | + set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") |
| 46 | + set(_TBB_LIB_NAME "tbb") |
| 47 | + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") |
| 48 | + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") |
| 49 | + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") |
| 50 | + if (MSVC71) |
| 51 | + set (_TBB_COMPILER "vc7.1") |
| 52 | + endif(MSVC71) |
| 53 | + if (MSVC80) |
| 54 | + set(_TBB_COMPILER "vc8") |
| 55 | + endif(MSVC80) |
| 56 | + if (MSVC90) |
| 57 | + set(_TBB_COMPILER "vc9") |
| 58 | + endif(MSVC90) |
| 59 | + if (MSVC10) |
| 60 | + set(_TBB_COMPILER "vc10") |
| 61 | + endif(MSVC10) |
| 62 | + if (MSVC11) |
| 63 | + set(_TBB_COMPILER "vc11") |
| 64 | + endif(MSVC11) |
| 65 | + if (MSVC12) |
| 66 | + set(_TBB_COMPILER "vc12") |
| 67 | + endif(MSVC12) |
| 68 | + if (NOT _TBB_COMPILER) |
| 69 | + message("ERROR: TBB supports only VC 7.1, 8, 9, 10, 11, and 12 compilers on Windows platforms.") |
| 70 | + endif (NOT _TBB_COMPILER) |
| 71 | + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) |
| 72 | +endif (WIN32) |
| 73 | + |
| 74 | +if (UNIX) |
| 75 | + if (APPLE) |
| 76 | + # MAC |
| 77 | + set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") |
| 78 | + # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug |
| 79 | + set(_TBB_LIB_NAME "tbb") |
| 80 | + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") |
| 81 | + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") |
| 82 | + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") |
| 83 | + # has only one flavor: ia32/cc4.0.1_os10.4.9 |
| 84 | + set(_TBB_COMPILER "cc4.0.1_os10.4.9") |
| 85 | + set(_TBB_ARCHITECTURE "ia32") |
| 86 | + else (APPLE) |
| 87 | + # LINUX |
| 88 | + set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") |
| 89 | + set(_TBB_LIB_NAME "tbb") |
| 90 | + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") |
| 91 | + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") |
| 92 | + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") |
| 93 | + # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 |
| 94 | + # has ia32/* |
| 95 | + # has itanium/* |
| 96 | + set(_TBB_COMPILER ${TBB_COMPILER}) |
| 97 | + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) |
| 98 | + endif (APPLE) |
| 99 | +endif (UNIX) |
| 100 | + |
| 101 | +if (CMAKE_SYSTEM MATCHES "SunOS.*") |
| 102 | +# SUN |
| 103 | +# not yet supported |
| 104 | +# has em64t/cc3.4.3_kernel5.10 |
| 105 | +# has ia32/* |
| 106 | +endif (CMAKE_SYSTEM MATCHES "SunOS.*") |
| 107 | + |
| 108 | + |
| 109 | +#-- Clear the public variables |
| 110 | +set (TBB_FOUND "NO") |
| 111 | + |
| 112 | + |
| 113 | +#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} |
| 114 | +# first: use CMake variable TBB_INSTALL_DIR |
| 115 | +if (TBB_INSTALL_DIR) |
| 116 | + set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) |
| 117 | +endif (TBB_INSTALL_DIR) |
| 118 | +# second: use environment variable |
| 119 | +if (NOT _TBB_INSTALL_DIR) |
| 120 | + if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") |
| 121 | + set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) |
| 122 | + endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") |
| 123 | + # Intel recommends setting TBB21_INSTALL_DIR |
| 124 | + if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") |
| 125 | + set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) |
| 126 | + endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") |
| 127 | +endif (NOT _TBB_INSTALL_DIR) |
| 128 | +# third: try to find path automatically |
| 129 | +if (NOT _TBB_INSTALL_DIR) |
| 130 | + if (_TBB_DEFAULT_INSTALL_DIR) |
| 131 | + set (_TBB_INSTALL_DIR $ENV{_TBB_DEFAULT_INSTALL_DIR}) |
| 132 | + endif (_TBB_DEFAULT_INSTALL_DIR) |
| 133 | +endif (NOT _TBB_INSTALL_DIR) |
| 134 | +# sanity check |
| 135 | + |
| 136 | +if (TBB_OBVIOUS_PLACE) |
| 137 | + set (TBB_FOUND "YES") |
| 138 | + set (TBB_LIBRARIES ${TEST_TBB_LIBRARY} ${TBB_LIBRARIES}) |
| 139 | + set (TBB_INCLUDE_DIRS ${TEST_TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) |
| 140 | + mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES) |
| 141 | + message(STATUS "Found Intel TBB") |
| 142 | +elseif (NOT _TBB_INSTALL_DIR) |
| 143 | + message (FATAL_ERROR "ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") |
| 144 | +else (TBB_OBVIOUS_PLACE) |
| 145 | + # finally: set the cached CMake variable TBB_INSTALL_DIR |
| 146 | + if (NOT TBB_INSTALL_DIR) |
| 147 | + set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") |
| 148 | + mark_as_advanced(TBB_INSTALL_DIR) |
| 149 | + endif (NOT TBB_INSTALL_DIR) |
| 150 | + |
| 151 | + |
| 152 | + #-- Look for include directory and set ${TBB_INCLUDE_DIR} |
| 153 | + set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) |
| 154 | + find_path(TBB_INCLUDE_DIR |
| 155 | + tbb/task_scheduler_init.h |
| 156 | + PATHS ${TBB_INC_SEARCH_DIR} |
| 157 | + ) |
| 158 | + mark_as_advanced(TBB_INCLUDE_DIR) |
| 159 | + |
| 160 | + |
| 161 | + #-- Look for libraries |
| 162 | + # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] |
| 163 | + if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") |
| 164 | + set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib") |
| 165 | + else (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") |
| 166 | + # Undeprecated to allow for Windows use. |
| 167 | + set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}") |
| 168 | + endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") |
| 169 | + |
| 170 | + find_library(TBB_LIBRARY ${_TBB_LIB_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH) |
| 171 | + find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH) |
| 172 | + mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) |
| 173 | + |
| 174 | + #-- Look for debug libraries |
| 175 | + find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH) |
| 176 | + find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH) |
| 177 | + mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) |
| 178 | + |
| 179 | + |
| 180 | + if (TBB_INCLUDE_DIR) |
| 181 | + if (TBB_LIBRARY) |
| 182 | + set (TBB_FOUND "YES") |
| 183 | + if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) |
| 184 | + set(TBB_LIBRARIES optimized ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES} debug ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) |
| 185 | + else() |
| 186 | + set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) |
| 187 | + set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) |
| 188 | + mark_as_advanced(TBB_DEBUG_LIBRARIES) |
| 189 | + endif() |
| 190 | + set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) |
| 191 | + set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) |
| 192 | + mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES) |
| 193 | + message(STATUS "Found Intel TBB") |
| 194 | + endif (TBB_LIBRARY) |
| 195 | + endif (TBB_INCLUDE_DIR) |
| 196 | + |
| 197 | + if (NOT TBB_FOUND) |
| 198 | + message(FATAL_ERROR "ERROR: Intel TBB NOT found!") |
| 199 | + message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") |
| 200 | + # do only throw fatal, if this pkg is REQUIRED |
| 201 | + if (TBB_FIND_REQUIRED) |
| 202 | + message(FATAL_ERROR "Could NOT find TBB library.") |
| 203 | + endif (TBB_FIND_REQUIRED) |
| 204 | + endif (NOT TBB_FOUND) |
| 205 | + |
| 206 | +endif (TBB_OBVIOUS_PLACE) |
| 207 | + |
| 208 | +if (TBB_FOUND) |
| 209 | + set(TBB_INTERFACE_VERSION 0) |
| 210 | + |
| 211 | + FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) |
| 212 | + STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") |
| 213 | + |
| 214 | + set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") |
| 215 | +endif() |
0 commit comments