Remove Callconv
[hiphop-php.git] / CMake / FindTBB.cmake
blob244ac23c3d45713a1bd4a135e0e22187d87c5d07
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 task_scheduler_init.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     tbb/task_scheduler_init.h
32 find_library(TEST_TBB_LIBRARY tbb)
34 if (TEST_TBB_INCLUDE_DIR)
35   if(TEST_TBB_LIBRARY)
36     set(TBB_OBVIOUS_PLACE "YES")
37   endif()
38 endif()
41 if (WIN32)
42   # has em64t/vc8   em64t/vc9
43   # has ia32/vc7.1  ia32/vc8   ia32/vc9
44   set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB")
45   set(_TBB_LIB_NAME "tbb")
46   set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
47   set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
48   set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
49   if (MSVC71)
50     set (_TBB_COMPILER "vc7.1")
51   endif(MSVC71)
52   if (MSVC80)
53     set(_TBB_COMPILER "vc8")
54   endif(MSVC80)
55   if (MSVC90)
56     set(_TBB_COMPILER "vc9")
57   endif(MSVC90)
58   if (MSVC10)
59     set(_TBB_COMPILER "vc10")
60   endif(MSVC10)
61   if (MSVC11)
62     set(_TBB_COMPILER "vc11")
63   endif(MSVC11)
64   if (MSVC12)
65     set(_TBB_COMPILER "vc12")
66   endif(MSVC12)
67   if (NOT _TBB_COMPILER)
68     message("ERROR: TBB supports only VC 7.1, 8, 9, 10, 11, and 12 compilers on Windows platforms.")
69   endif (NOT _TBB_COMPILER)
70   set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
71 endif (WIN32)
73 if (UNIX)
74   if (APPLE)
75     # MAC
76     set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions")
77     # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug
78     set(_TBB_LIB_NAME "tbb")
79     set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
80     set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
81     set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
82     # has only one flavor: ia32/cc4.0.1_os10.4.9
83     set(_TBB_COMPILER "cc4.0.1_os10.4.9")
84     set(_TBB_ARCHITECTURE "ia32")
85   else (APPLE)
86     # LINUX
87     set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include")
88     set(_TBB_LIB_NAME "tbb")
89     set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
90     set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
91     set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
92     # 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
93     # has ia32/*
94     # has itanium/*
95     set(_TBB_COMPILER ${TBB_COMPILER})
96     set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})
97   endif (APPLE)
98 endif (UNIX)
100 if (CMAKE_SYSTEM MATCHES "SunOS.*")
101 # SUN
102 # not yet supported
103 # has em64t/cc3.4.3_kernel5.10
104 # has ia32/*
105 endif (CMAKE_SYSTEM MATCHES "SunOS.*")
108 #-- Clear the public variables
109 set (TBB_FOUND "NO")
112 #-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR}
113 # first: use CMake variable TBB_INSTALL_DIR
114 if (TBB_INSTALL_DIR)
115     set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR})
116 endif (TBB_INSTALL_DIR)
117 # second: use environment variable
118 if (NOT _TBB_INSTALL_DIR)
119   if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
120     set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR})
121   endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "")
122   # Intel recommends setting TBB21_INSTALL_DIR
123   if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
124     set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR})
125   endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "")
126 endif (NOT _TBB_INSTALL_DIR)
127 # third: try to find path automatically
128 if (NOT _TBB_INSTALL_DIR)
129   if (_TBB_DEFAULT_INSTALL_DIR)
130     set (_TBB_INSTALL_DIR $ENV{_TBB_DEFAULT_INSTALL_DIR})
131   endif (_TBB_DEFAULT_INSTALL_DIR)
132 endif (NOT _TBB_INSTALL_DIR)
133 # sanity check
135 if (TBB_OBVIOUS_PLACE)
136   set (TBB_FOUND "YES")
137   set (TBB_LIBRARIES ${TEST_TBB_LIBRARY} ${TBB_LIBRARIES})
138   set (TBB_INCLUDE_DIRS ${TEST_TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
139   mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
140   message(STATUS "Found Intel TBB")
141 elseif (NOT _TBB_INSTALL_DIR)
142   message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}")
143 else (TBB_OBVIOUS_PLACE)
144   # finally: set the cached CMake variable TBB_INSTALL_DIR
145   if (NOT TBB_INSTALL_DIR)
146     set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory")
147     mark_as_advanced(TBB_INSTALL_DIR)
148   endif (NOT TBB_INSTALL_DIR)
151   #-- Look for include directory and set ${TBB_INCLUDE_DIR}
152   set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include)
153   find_path(TBB_INCLUDE_DIR
154     tbb/task_scheduler_init.h
155     PATHS ${TBB_INC_SEARCH_DIR}
156   )
157   mark_as_advanced(TBB_INCLUDE_DIR)
160   #-- Look for libraries
161   # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh]
162   if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
163     set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib")
164   else (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
165     # Undeprecated to allow for Windows use. 
166     set (TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/lib/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}")
167   endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "")
169   find_library(TBB_LIBRARY        ${_TBB_LIB_NAME}        ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
170   find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
171   mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY)
173   #-- Look for debug libraries
174   find_library(TBB_LIBRARY_DEBUG        ${_TBB_LIB_DEBUG_NAME}        ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
175   find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} ${TBB_LIBRARY_DIR} NO_DEFAULT_PATH)
176   mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG)
179   if (TBB_INCLUDE_DIR)
180     if (TBB_LIBRARY)
181       set (TBB_FOUND "YES")
182       if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
183         set(TBB_LIBRARIES optimized ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES} debug ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES})
184       else()
185         set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES})
186         set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES})
187         mark_as_advanced(TBB_DEBUG_LIBRARIES)
188       endif()
189       set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE)
190       set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE)
191       mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES)
192       message(STATUS "Found Intel TBB")
193     endif (TBB_LIBRARY)
194   endif (TBB_INCLUDE_DIR)
196   if (NOT TBB_FOUND)
197     message("ERROR: Intel TBB NOT found!")
198     message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}")
199     # do only throw fatal, if this pkg is REQUIRED
200     if (TBB_FIND_REQUIRED)
201       message(FATAL_ERROR "Could NOT find TBB library.")
202     endif (TBB_FIND_REQUIRED)
203   endif (NOT TBB_FOUND)
205 endif (TBB_OBVIOUS_PLACE)
207 if (TBB_FOUND)
208   set(TBB_INTERFACE_VERSION 0)
210   FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS)
211   STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}")
213   set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}")
214 endif()