Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame^] | 1 | # The MIT License (MIT) |
| 2 | # |
| 3 | # Copyright (c) 2015 Justus Calvin |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to deal |
| 7 | # in the Software without restriction, including without limitation the rights |
| 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | # copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in all |
| 13 | # copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | |
| 23 | # |
| 24 | # FindTBB |
| 25 | # ------- |
| 26 | # |
| 27 | # Find TBB include directories and libraries. |
| 28 | # |
| 29 | # Usage: |
| 30 | # |
| 31 | # find_package(TBB [major[.minor]] [EXACT] |
| 32 | # [QUIET] [REQUIRED] |
| 33 | # [[COMPONENTS] [components...]] |
| 34 | # [OPTIONAL_COMPONENTS components...]) |
| 35 | # |
| 36 | # where the allowed components are tbbmalloc and tbb_preview. Users may modify |
| 37 | # the behavior of this module with the following variables: |
| 38 | # |
| 39 | # * TBB_ROOT_DIR - The base directory the of TBB installation. |
| 40 | # * TBB_INCLUDE_DIR - The directory that contains the TBB headers files. |
| 41 | # * TBB_LIBRARY - The directory that contains the TBB library files. |
| 42 | # * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library. |
| 43 | # These libraries, if specified, override the |
| 44 | # corresponding library search results, where <library> |
| 45 | # may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug, |
| 46 | # tbb_preview, or tbb_preview_debug. |
| 47 | # * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will |
| 48 | # be used instead of the release version. |
| 49 | # |
| 50 | # Users may modify the behavior of this module with the following environment |
| 51 | # variables: |
| 52 | # |
| 53 | # * TBB_INSTALL_DIR |
| 54 | # * TBBROOT |
| 55 | # * LIBRARY_PATH |
| 56 | # |
| 57 | # This module will set the following variables: |
| 58 | # |
| 59 | # * TBB_FOUND - Set to false, or undefined, if we haven’t found, or |
| 60 | # don’t want to use TBB. |
| 61 | # * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is |
| 62 | # not available. |
| 63 | # * TBB_VERSION - The full version string |
| 64 | # * TBB_VERSION_MAJOR - The major version |
| 65 | # * TBB_VERSION_MINOR - The minor version |
| 66 | # * TBB_INTERFACE_VERSION - The interface version number defined in |
| 67 | # tbb/tbb_stddef.h. |
| 68 | # * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of |
| 69 | # <library>, where <library> may be tbb, tbb_debug, |
| 70 | # tbbmalloc, tbbmalloc_debug, tbb_preview, or |
| 71 | # tbb_preview_debug. |
| 72 | # * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of |
| 73 | # <library>, where <library> may be tbb, tbb_debug, |
| 74 | # tbbmalloc, tbbmalloc_debug, tbb_preview, or |
| 75 | # tbb_preview_debug. |
| 76 | # |
| 77 | # The following varibles should be used to build and link with TBB: |
| 78 | # |
| 79 | # * TBB_INCLUDE_DIRS - The include directory for TBB. |
| 80 | # * TBB_LIBRARIES - The libraries to link against to use TBB. |
| 81 | # * TBB_DEFINITIONS - Definitions to use when compiling code that uses TBB. |
| 82 | |
| 83 | include(FindPackageHandleStandardArgs) |
| 84 | |
| 85 | if(NOT TBB_FOUND) |
| 86 | |
| 87 | ################################## |
| 88 | # Check the build type |
| 89 | ################################## |
| 90 | |
| 91 | if(NOT DEFINED TBB_USE_DEBUG_BUILD) |
| 92 | if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)") |
| 93 | set(TBB_USE_DEBUG_BUILD TRUE) |
| 94 | else() |
| 95 | set(TBB_USE_DEBUG_BUILD FALSE) |
| 96 | endif() |
| 97 | endif() |
| 98 | |
| 99 | ################################## |
| 100 | # Set the TBB search directories |
| 101 | ################################## |
| 102 | |
| 103 | # Define search paths based on user input and environment variables |
| 104 | set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT}) |
| 105 | |
| 106 | # Define the search directories based on the current platform |
| 107 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 108 | set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB" |
| 109 | "C:/Program Files (x86)/Intel/TBB") |
| 110 | |
| 111 | # Set the target architecture |
| 112 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 113 | set(TBB_ARCHITECTURE "intel64") |
| 114 | else() |
| 115 | set(TBB_ARCHITECTURE "ia32") |
| 116 | endif() |
| 117 | |
| 118 | # Set the TBB search library path search suffix based on the version of VC |
| 119 | if(WINDOWS_STORE) |
| 120 | set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui") |
| 121 | elseif(MSVC14) |
| 122 | set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14") |
| 123 | elseif(MSVC12) |
| 124 | set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12") |
| 125 | elseif(MSVC11) |
| 126 | set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11") |
| 127 | elseif(MSVC10) |
| 128 | set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10") |
| 129 | endif() |
| 130 | |
| 131 | # Add the library path search suffix for the VC independent version of TBB |
| 132 | list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt") |
| 133 | |
| 134 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 135 | # OS X |
| 136 | set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") |
| 137 | |
| 138 | # TODO: Check to see which C++ library is being used by the compiler. |
| 139 | if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0) |
| 140 | # The default C++ library on OS X 10.9 and later is libc++ |
| 141 | set(TBB_LIB_PATH_SUFFIX "lib/libc++") |
| 142 | else() |
| 143 | set(TBB_LIB_PATH_SUFFIX "lib") |
| 144 | endif() |
| 145 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 146 | # Linux |
| 147 | set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") |
| 148 | |
| 149 | # TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or |
| 150 | # <arch>/gcc4.1. For now, assume that the compiler is more recent than |
| 151 | # gcc 4.4.x or later. |
| 152 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") |
| 153 | set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4") |
| 154 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") |
| 155 | set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4") |
| 156 | endif() |
| 157 | endif() |
| 158 | |
| 159 | ################################## |
| 160 | # Find the TBB include dir |
| 161 | ################################## |
| 162 | |
| 163 | find_path(TBB_INCLUDE_DIRS tbb/tbb.h |
| 164 | HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR} |
| 165 | PATHS ${TBB_DEFAULT_SEARCH_DIR} |
| 166 | PATH_SUFFIXES include) |
| 167 | |
| 168 | ################################## |
| 169 | # Find TBB components |
| 170 | ################################## |
| 171 | |
| 172 | # Find each component |
| 173 | foreach(_comp tbb_preview tbbmalloc tbb) |
| 174 | # Search for the libraries |
| 175 | find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp} |
| 176 | HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} |
| 177 | PATHS ${TBB_DEFAULT_SEARCH_DIR} |
| 178 | PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) |
| 179 | |
| 180 | find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug |
| 181 | HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} |
| 182 | PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH |
| 183 | PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX}) |
| 184 | |
| 185 | |
| 186 | # Set the library to be used for the component |
| 187 | if(NOT TBB_${_comp}_LIBRARY) |
| 188 | if(TBB_USE_DEBUG_BUILD AND TBB_${_comp}_LIBRARY_DEBUG) |
| 189 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}") |
| 190 | elseif(TBB_${_comp}_LIBRARY_RELEASE) |
| 191 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_RELEASE}") |
| 192 | elseif(TBB_${_comp}_LIBRARY_DEBUG) |
| 193 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}") |
| 194 | endif() |
| 195 | endif() |
| 196 | |
| 197 | # Set the TBB library list and component found variables |
| 198 | if(TBB_${_comp}_LIBRARY) |
| 199 | list(APPEND TBB_LIBRARIES "${TBB_${_comp}_LIBRARY}") |
| 200 | set(TBB_${_comp}_FOUND TRUE) |
| 201 | else() |
| 202 | set(TBB_${_comp}_FOUND FALSE) |
| 203 | endif() |
| 204 | |
| 205 | mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE) |
| 206 | mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG) |
| 207 | mark_as_advanced(TBB_${_comp}_LIBRARY) |
| 208 | |
| 209 | endforeach() |
| 210 | |
| 211 | ################################## |
| 212 | # Set compile flags |
| 213 | ################################## |
| 214 | |
| 215 | if(TBB_tbb_LIBRARY MATCHES "debug") |
| 216 | set(TBB_DEFINITIONS "-DTBB_USE_DEBUG=1") |
| 217 | endif() |
| 218 | |
| 219 | ################################## |
| 220 | # Set version strings |
| 221 | ################################## |
| 222 | |
| 223 | if(TBB_INCLUDE_DIRS) |
| 224 | file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) |
| 225 | string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" |
| 226 | TBB_VERSION_MAJOR "${_tbb_version_file}") |
| 227 | string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" |
| 228 | TBB_VERSION_MINOR "${_tbb_version_file}") |
| 229 | string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" |
| 230 | TBB_INTERFACE_VERSION "${_tbb_version_file}") |
| 231 | set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}") |
| 232 | endif() |
| 233 | |
| 234 | find_package_handle_standard_args(TBB |
| 235 | REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES |
| 236 | HANDLE_COMPONENTS |
| 237 | VERSION_VAR TBB_VERSION) |
| 238 | |
| 239 | mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES) |
| 240 | |
| 241 | unset(TBB_ARCHITECTURE) |
| 242 | unset(TBB_LIB_PATH_SUFFIX) |
| 243 | unset(TBB_DEFAULT_SEARCH_DIR) |
| 244 | |
| 245 | endif() |