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