You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
14 KiB

2 months ago
  1. # FindTBB.cmake can be found at https://code.google.com/p/findtbb/
  2. # Written by Hannes Hofmann <hannes.hofmann _at_ informatik.uni-erlangen.de>
  3. # Improvements by Gino van den Bergen <gino _at_ dtecta.com>,
  4. # Florian Uhlig <F.Uhlig _at_ gsi.de>,
  5. # Jiri Marsik <jiri.marsik89 _at_ gmail.com>
  6. # The MIT License
  7. #
  8. # Copyright (c) 2011 Hannes Hofmann
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining a copy
  11. # of this software and associated documentation files (the "Software"), to deal
  12. # in the Software without restriction, including without limitation the rights
  13. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. # copies of the Software, and to permit persons to whom the Software is
  15. # furnished to do so, subject to the following conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be included in
  18. # all copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. # THE SOFTWARE.
  27. # GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler.
  28. # e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21"
  29. # TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found
  30. # in the TBB installation directory (TBB_INSTALL_DIR).
  31. #
  32. # GvdB: Mac OS X distribution places libraries directly in lib directory.
  33. #
  34. # For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER.
  35. # TBB_ARCHITECTURE [ ia32 | em64t | itanium ]
  36. # which architecture to use
  37. # TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9
  38. # which compiler to use (detected automatically on Windows)
  39. # This module respects
  40. # TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR}
  41. # This module defines
  42. # TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc.
  43. # TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc
  44. # TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug
  45. # TBB_INSTALL_DIR, the base TBB install directory
  46. # TBB_LIBRARIES, the libraries to link against to use TBB.
  47. # TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols.
  48. # TBB_FOUND, If false, don't try to use TBB.
  49. # TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h
  50. if (WIN32)
  51. # has em64t/vc8 em64t/vc9
  52. # has ia32/vc7.1 ia32/vc8 ia32/vc9
  53. set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" "C:/Program Files (x86)/Intel/Composer XE 2013/tbb")
  54. set(_TBB_LIB_NAME "tbb")
  55. set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
  56. set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
  57. set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
  58. if (MSVC71)
  59. set (_TBB_COMPILER "vc7.1")
  60. endif(MSVC71)
  61. if (MSVC80)
  62. set(_TBB_COMPILER "vc8")
  63. endif(MSVC80)
  64. if (MSVC90)
  65. set(_TBB_COMPILER "vc9")
  66. endif(MSVC90)
  67. if(MSVC10)
  68. set(_TBB_COMPILER "vc10")
  69. endif(MSVC10)
  70. if(MSVC11)
  71. set(_TBB_COMPILER "vc11")
  72. endif(MSVC11)
  73. if(MSVC12)
  74. set(_TBB_COMPILER "vc12")
  75. endif(MSVC12)
  76. # Todo: add other Windows compilers such as ICL.
  77. set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
  78. endif (WIN32)
  79. if (UNIX)
  80. if (APPLE)
  81. # MAC
  82. set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions")
  83. # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug
  84. set(_TBB_LIB_NAME "tbb")
  85. set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
  86. set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
  87. set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
  88. # default flavor on apple: ia32/cc4.0.1_os10.4.9
  89. # Jiri: There is no reason to presume there is only one flavor and
  90. # that user's setting of variables should be ignored.
  91. if(NOT TBB_COMPILER)
  92. set(_TBB_COMPILER "cc4.0.1_os10.4.9")
  93. elseif (NOT TBB_COMPILER)
  94. set(_TBB_COMPILER ${TBB_COMPILER})
  95. endif(NOT TBB_COMPILER)
  96. if(NOT TBB_ARCHITECTURE)
  97. set(_TBB_ARCHITECTURE "ia32")
  98. elseif(NOT TBB_ARCHITECTURE)
  99. set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
  100. endif(NOT TBB_ARCHITECTURE)
  101. else (APPLE)
  102. # LINUX
  103. set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include")
  104. set(_TBB_LIB_NAME "tbb")
  105. set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
  106. set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
  107. set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
  108. # 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
  109. # has ia32/*
  110. # has itanium/*
  111. set(_TBB_COMPILER ${TBB_COMPILER})
  112. set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
  113. endif (APPLE)
  114. endif (UNIX)
  115. if (CMAKE_SYSTEM MATCHES "SunOS.*")
  116. # SUN
  117. # not yet supported
  118. # has em64t/cc3.4.3_kernel5.10
  119. # has ia32/*
  120. endif (CMAKE_SYSTEM MATCHES "SunOS.*")
  121. #-- Clear the public variables
  122. set (TBB_FOUND "NO")
  123. #-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR}
  124. # first: use CMake variable TBB_INSTALL_DIR
  125. if (TBB_INSTALL_DIR)
  126. set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR})
  127. endif (TBB_INSTALL_DIR)
  128. # second: use environment variable
  129. if (NOT _TBB_INSTALL_DIR)
  130. if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
  131. set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR})
  132. endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
  133. # Intel recommends setting TBB21_INSTALL_DIR
  134. if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
  135. set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR})
  136. endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
  137. if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "")
  138. set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR})
  139. endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "")
  140. if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "")
  141. set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR})
  142. endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "")
  143. endif (NOT _TBB_INSTALL_DIR)
  144. # third: try to find path automatically
  145. if (NOT _TBB_INSTALL_DIR)
  146. if (_TBB_DEFAULT_INSTALL_DIR)
  147. set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR})
  148. endif (_TBB_DEFAULT_INSTALL_DIR)
  149. endif (NOT _TBB_INSTALL_DIR)
  150. # sanity check
  151. if (NOT _TBB_INSTALL_DIR)
  152. message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}")
  153. else (NOT _TBB_INSTALL_DIR)
  154. # finally: set the cached CMake variable TBB_INSTALL_DIR
  155. if (NOT TBB_INSTALL_DIR)
  156. mark_as_advanced(TBB_INSTALL_DIR)
  157. endif (NOT TBB_INSTALL_DIR)
  158. #-- A macro to rewrite the paths of the library. This is necessary, because
  159. # find_library() always found the em64t/vc9 version of the TBB libs
  160. macro(TBB_CORRECT_LIB_DIR var_name)
  161. # if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
  162. string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
  163. # endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t")
  164. string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}})
  165. string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  166. string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  167. string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  168. string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  169. string(REPLACE vc11 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  170. string(REPLACE vc12 "${_TBB_COMPILER}" ${var_name} ${${var_name}})
  171. endmacro(TBB_CORRECT_LIB_DIR var_content)
  172. #-- Look for include directory and set ${TBB_INCLUDE_DIR}
  173. set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include)
  174. # Jiri: tbbvars now sets the CPATH environment variable to the directory
  175. # containing the headers.
  176. find_path(TBB_INCLUDE_DIR tbb/tbb_stddef.h PATHS "${TBB_INC_SEARCH_DIR}" ENV CPATH)
  177. mark_as_advanced(TBB_INCLUDE_DIR)
  178. #-- Look for libraries
  179. include(CheckSymbolExists)
  180. # Check if we are on Windows
  181. CHECK_SYMBOL_EXISTS("_WIN32" "" FINDTBB_HAVE_WIN32)
  182. CHECK_SYMBOL_EXISTS("_WIN64" "" FINDTBB_HAVE_WIN64)
  183. if(FINDTBB_HAVE_WIN64)
  184. # this is a build on 64bit Windows
  185. set(_TBB_ARCHITECTURE "intel64")
  186. set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}" ${_TBB_LIBRARY_DIR})
  187. elseif(FINDTBB_HAVE_WIN32)
  188. # this is a build on 32bit Windows
  189. set(_TBB_ARCHITECTURE "ia32")
  190. set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}" ${_TBB_LIBRARY_DIR})
  191. endif()
  192. # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh]
  193. if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
  194. set (_TBB_LIBRARY_DIR
  195. ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM}
  196. ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib
  197. )
  198. endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
  199. # Jiri: This block isn't mutually exclusive with the previous one
  200. # (hence no else), instead I test if the user really specified
  201. # the variables in question.
  202. if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL ""))
  203. # HH: deprecated
  204. message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).")
  205. # Jiri: It doesn't hurt to look in more places, so I store the hints from
  206. # ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER
  207. # variables and search them both.
  208. set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR})
  209. endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL ""))
  210. # GvdB: Mac OS X distribution places libraries directly in lib directory.
  211. if (USE_LIBCXX OR LINK_LIBCXXABI)
  212. message(STATUS "FindTBB - Detected libc++ usage, linking to TBB with libc++!")
  213. list(APPEND _TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/libc++")
  214. else()
  215. list(APPEND _TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib")
  216. endif()
  217. message(STATUS "Searching for TBB: TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR}, _TBB_COMPILER = ${_TBB_COMPILER} and _TBB_ARCHITECTURE = ${_TBB_ARCHITECTURE}")
  218. # Jiri: No reason not to check the default paths. From recent versions,
  219. # tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH
  220. # variables, which now point to the directories of the lib files.
  221. # It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS
  222. # argument instead of the implicit PATHS as it isn't hard-coded
  223. # but computed by system introspection. Searching the LIBRARY_PATH
  224. # and LD_LIBRARY_PATH environment variables is now even more important
  225. # that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates
  226. # the use of TBB built from sources.
  227. find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR}
  228. PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH)
  229. find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR}
  230. PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH)
  231. #Extract path from TBB_LIBRARY name
  232. get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH)
  233. #TBB_CORRECT_LIB_DIR(TBB_LIBRARY)
  234. #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY)
  235. mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY)
  236. #-- Look for debug libraries
  237. # Jiri: Changed the same way as for the release libraries.
  238. find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR}
  239. PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH)
  240. find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR}
  241. PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH)
  242. # Jiri: Self-built TBB stores the debug libraries in a separate directory.
  243. # Extract path from TBB_LIBRARY_DEBUG name
  244. get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH)
  245. #TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG)
  246. #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG)
  247. mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG)
  248. if (TBB_INCLUDE_DIR)
  249. if (TBB_LIBRARY)
  250. set (TBB_FOUND ON)
  251. set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES})
  252. set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES})
  253. set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
  254. set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE)
  255. # Jiri: Self-built TBB stores the debug libraries in a separate directory.
  256. set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE)
  257. mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES)
  258. message(STATUS "Found Intel TBB")
  259. endif (TBB_LIBRARY)
  260. endif (TBB_INCLUDE_DIR)
  261. if (NOT TBB_FOUND)
  262. message("ERROR: Intel TBB NOT found!")
  263. message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}")
  264. # do only throw fatal, if this pkg is REQUIRED
  265. if (TBB_FIND_REQUIRED)
  266. message(FATAL_ERROR "Could NOT find TBB library.")
  267. endif (TBB_FIND_REQUIRED)
  268. endif (NOT TBB_FOUND)
  269. endif (NOT _TBB_INSTALL_DIR)
  270. if (TBB_FOUND)
  271. set(TBB_INTERFACE_VERSION 0)
  272. FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS)
  273. STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}")
  274. STRING(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" TBB_VERSION_MAJOR "${_TBB_VERSION_CONTENTS}")
  275. STRING(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" TBB_VERSION_MINOR "${_TBB_VERSION_CONTENTS}")
  276. set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}")
  277. set(TBB_VERSION_MAJOR "${TBB_VERSION_MAJOR}")
  278. set(TBB_VERSION_MINOR "${TBB_VERSION_MINOR}")
  279. endif (TBB_FOUND)