0026460: Implicit cast to TopoDS_Shape compilation error due to ambiguous conversion
[occt.git] / adm / cmake / tbb.cmake
1 # tbb
2
3 if (NOT DEFINED INSTALL_TBB)
4   set (INSTALL_TBB OFF CACHE BOOL "Is tbb required to be copied into install directory")
5 endif()
6
7 # tbb directory
8 if (NOT DEFINED 3RDPARTY_TBB_DIR)
9   set (3RDPARTY_TBB_DIR "" CACHE PATH "The directory containing tbb")
10 endif()
11
12 # tbb include directory
13 if (NOT DEFINED 3RDPARTY_TBB_INCLUDE_DIR)
14   set (3RDPARTY_TBB_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of the tbb")
15 endif()
16
17 # tbb library file (with absolute path)
18 if (NOT DEFINED 3RDPARTY_TBB_LIBRARY OR NOT 3RDPARTY_TBB_LIBRARY_DIR)
19   set (3RDPARTY_TBB_LIBRARY "" CACHE FILEPATH "tbb library" FORCE)
20 endif()
21
22 # tbb library directory
23 if (NOT DEFINED 3RDPARTY_TBB_LIBRARY_DIR)
24   set (3RDPARTY_TBB_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tbb library")
25 endif()
26
27 # tbb malloc library file (with absolute path)
28 if (NOT DEFINED 3RDPARTY_TBBMALLOC_LIBRARY OR NOT 3RDPARTY_TBBMALLOC_LIBRARY_DIR)
29   set (3RDPARTY_TBBMALLOC_LIBRARY "" CACHE FILEPATH "tbb malloc library" FORCE)
30 endif()
31
32 # tbb malloc library directory
33 if (NOT DEFINED 3RDPARTY_TBBMALLOC_LIBRARY_DIR)
34   set (3RDPARTY_TBBMALLOC_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tbb malloc library")
35 endif()
36
37 # tbb shared library (with absolute path)
38 if (WIN32)
39   if (NOT DEFINED 3RDPARTY_TBB_DLL OR NOT 3RDPARTY_TBB_DLL_DIR)
40     set (3RDPARTY_TBB_DLL "" CACHE FILEPATH "tbb shared library" FORCE)
41   endif()
42 endif()
43
44 # tbb shared library directory
45 if (WIN32 AND NOT DEFINED 3RDPARTY_TBB_DLL_DIR)
46   set (3RDPARTY_TBB_DLL_DIR "" CACHE FILEPATH "The directory containing tbb shared library")
47 endif()
48
49 # tbb malloc shared library (with absolute path)
50 if (WIN32)
51   if (NOT DEFINED 3RDPARTY_TBBMALLOC_DLL OR NOT 3RDPARTY_TBBMALLOC_DLL_DIR)
52     set (3RDPARTY_TBBMALLOC_DLL "" CACHE FILEPATH "tbb malloc shared library" FORCE)
53   endif()
54 endif()
55
56 # tbb malloc shared library directory
57 if (WIN32 AND NOT DEFINED 3RDPARTY_TBBMALLOC_DLL_DIR)
58   set (3RDPARTY_TBBMALLOC_DLL_DIR "" CACHE FILEPATH "The directory containing tbb malloc shared library")
59 endif()
60
61 # include occt macros. compiler_bitness, os_wiht_bit, compiler
62 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
63
64 # search for product directory inside 3RDPARTY_DIR directory
65 if (NOT 3RDPARTY_TBB_DIR AND 3RDPARTY_DIR)
66   FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" "TBB" TBB_DIR_NAME)
67   if (TBB_DIR_NAME)
68     message (STATUS "Info: TBB: ${TBB_DIR_NAME} folder is used")
69     set (3RDPARTY_TBB_DIR "${3RDPARTY_DIR}/${TBB_DIR_NAME}" CACHE PATH "The directory containing tbb" FORCE)
70   endif()
71 endif()
72
73 OCCT_MAKE_COMPILER_BITNESS()
74
75 if (${COMPILER_BITNESS} STREQUAL 32)
76   set (TBB_ARCH_NAME ia32)
77 else()
78   set (TBB_ARCH_NAME intel64)
79 endif()
80
81 # search for include directory in defined 3rdparty directory
82 if (NOT 3RDPARTY_TBB_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_TBB_INCLUDE_DIR}")
83   set (3RDPARTY_TBB_INCLUDE_DIR "3RDPARTY_TBB_INCLUDE_DIR-NOTFOUND" CACHE FILEPATH "The directory containing the headers of tbb" FORCE)
84   find_path (3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include" NO_DEFAULT_PATH)
85   find_path (3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include")
86 endif()
87
88 if (NOT 3RDPARTY_TBB_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_TBB_INCLUDE_DIR}")
89   set (3RDPARTY_TBB_INCLUDE_DIR "" CACHE FILEPATH "The directory containing the headers of tbb" FORCE)
90 endif()
91
92 OCCT_MAKE_COMPILER_SHORT_NAME()
93
94 # TBB_COMPILER_FOLER
95 #if (WIN32)
96   set (TBB_COMPILER_FOLER ${COMPILER})
97 #else()
98 #  set (TBB_COMPILER_FOLER ${COMPILER})
99 #endif()
100
101 # search for tbb and tbb malloc library in defined 3rdparty directory
102 foreach (LIBRARY_NAME TBB TBBMALLOC)
103   if (NOT WIN32)
104     file (GLOB TBB_SUBDIRS RELATIVE ${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/ ${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/*)
105     list (SORT TBB_SUBDIRS)
106     list (REVERSE TBB_SUBDIRS)
107     list (LENGTH TBB_SUBDIRS TBB_SUBDIRS_LENGTH)
108     set (TBB_SUBDIR_FIRST "")
109     if (${TBB_SUBDIRS_LENGTH})
110       list (GET TBB_SUBDIRS 0 TBB_SUBDIR_FIRST)
111       set (3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${TBB_SUBDIR_FIRST}")
112     endif()
113   endif()
114   if (NOT 3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR)
115     set (3RDPARTY_${LIBRARY_NAME}_LIBRARY "" CACHE FILEPATH "${LIBRARY_NAME} library" FORCE)
116   elseif (3RDPARTY_${LIBRARY_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBRARY_NAME}_LIBRARY}")
117     get_filename_component(3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR_TMP "${3RDPARTY_${LIBRARY_NAME}_LIBRARY}" PATH)
118     if (NOT "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}" STREQUAL "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR_TMP}")
119       set (3RDPARTY_${LIBRARY_NAME}_LIBRARY "" CACHE FILEPATH "${LIBRARY_NAME} library" FORCE)
120     endif()
121   endif()
122
123   if (NOT 3RDPARTY_${LIBRARY_NAME}_LIBRARY OR NOT EXISTS "${3RDPARTY_${LIBRARY_NAME}_LIBRARY}")
124     set (3RDPARTY_${LIBRARY_NAME}_LIBRARY "3RDPARTY_${LIBRARY_NAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to library of ${LIBRARY_NAME}" FORCE)
125
126     string (TOLOWER "${LIBRARY_NAME}" lower_LIBRARY_NAME)
127     find_library (3RDPARTY_${LIBRARY_NAME}_LIBRARY ${lower_LIBRARY_NAME} PATHS
128                                                                          "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}"
129                                                                          "${3RDPARTY_TBB_DIR}/lib/${TBB_ARCH_NAME}/${TBB_COMPILER_FOLER}"
130                                                                          NO_DEFAULT_PATH)
131
132       # second search if previous one do not find anything
133       find_library (3RDPARTY_${LIBRARY_NAME}_LIBRARY ${LIBRARY_NAME})
134   endif()
135
136   if (NOT 3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR OR NOT EXISTS "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}")
137     get_filename_component(3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${LIBRARY_NAME}_LIBRARY}" PATH)
138   endif()
139   set (3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${LIBRARY_NAME} library" FORCE)
140
141   # search for dll in defined 3rdparty directory (just for win case)
142   if (WIN32)
143     set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
144
145     if (NOT 3RDPARTY_${LIBRARY_NAME}_DLL_DIR)
146       set (3RDPARTY_${LIBRARY_NAME}_DLL "" CACHE FILEPATH "${LIBRARY_NAME} shared library" FORCE)
147     elseif (3RDPARTY_${LIBRARY_NAME}_DLL AND EXISTS "${3RDPARTY_${LIBRARY_NAME}_DLL}")
148       get_filename_component(3RDPARTY_${LIBRARY_NAME}_DLL_DIR_TMP "${3RDPARTY_${LIBRARY_NAME}_DLL}" PATH)
149       if (NOT "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR}" STREQUAL "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR_TMP}")
150         set (3RDPARTY_${LIBRARY_NAME}_DLL "" CACHE FILEPATH "${LIBRARY_NAME} shared library" FORCE)
151       endif()
152     endif()
153
154     if (NOT 3RDPARTY_${LIBRARY_NAME}_DLL OR NOT EXISTS "${3RDPARTY_${LIBRARY_NAME}_DLL}")
155       set (3RDPARTY_${LIBRARY_NAME}_DLL "3RDPARTY_${LIBRARY_NAME}_DLL-NOTFOUND" CACHE FILEPATH "Path to shared library of ${LIBRARY_NAME}" FORCE)
156
157       find_library (3RDPARTY_${LIBRARY_NAME}_DLL ${LIBRARY_NAME} PATHS
158                                                                  "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR}"
159                                                                  "${3RDPARTY_TBB_DIR}/bin/${TBB_ARCH_NAME}/${TBB_COMPILER_FOLER}"
160                                                                  NO_DEFAULT_PATH)
161
162         # second search if previous one do not find anything
163         find_library (3RDPARTY_${LIBRARY_NAME}_DLL ${LIBRARY_NAME})
164     endif()
165
166     if (NOT 3RDPARTY_${LIBRARY_NAME}_DLL_DIR OR NOT EXISTS "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR}")
167       get_filename_component(3RDPARTY_${LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${LIBRARY_NAME}_DLL}" PATH)
168       set (3RDPARTY_${LIBRARY_NAME}_DLL_DIR "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR}" CACHE FILEPATH "The directory containing ${LIBRARY_NAME} shared library" FORCE)
169     endif()
170   endif() # end dll search
171 endforeach() # end tbb / tbbmalloc
172
173 # include found paths to common variables
174 if (3RDPARTY_TBB_INCLUDE_DIR AND EXISTS "${3RDPARTY_TBB_INCLUDE_DIR}")
175   list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_TBB_INCLUDE_DIR}")
176 else()
177   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_INCLUDE_DIR)
178 endif()
179
180 foreach (LIBRARY_NAME TBB TBBMALLOC)
181   if (3RDPARTY_${LIBRARY_NAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBRARY_NAME}_LIBRARY}")
182     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}")
183   else()
184     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR)
185   endif()
186
187   if (WIN32)
188     if (3RDPARTY_${LIBRARY_NAME}_DLL OR EXISTS "${3RDPARTY_${LIBRARY_NAME}_DLL}")
189       list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_${LIBRARY_NAME}_DLL_DIR}")
190     else()
191       list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBRARY_NAME}_DLL_DIR)
192     endif()
193   endif()
194 endforeach()
195
196 # install tbb
197 if (INSTALL_TBB)
198   OCCT_MAKE_OS_WITH_BITNESS()
199   OCCT_MAKE_COMPILER_SHORT_NAME()
200
201   if (WIN32)
202     install (FILES ${3RDPARTY_TBB_DLL} ${3RDPARTY_TBBMALLOC_DLL}
203              CONFIGURATIONS Release
204              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
205     install (FILES ${3RDPARTY_TBB_DLL} ${3RDPARTY_TBBMALLOC_DLL}
206              CONFIGURATIONS RelWithDebInfo
207              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
208     install (FILES ${3RDPARTY_TBB_DLL} ${3RDPARTY_TBBMALLOC_DLL}
209              CONFIGURATIONS Debug
210              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
211   else()
212     get_filename_component(TBBLIB ${3RDPARTY_TBB_LIBRARY} NAME)
213     get_filename_component(TBBMALLOCLIB ${3RDPARTY_TBBMALLOC_LIBRARY} NAME)
214
215     install (FILES ${3RDPARTY_TBB_LIBRARY}.2
216              CONFIGURATIONS Release
217              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
218              RENAME ${TBBLIB}.2)
219     install (FILES ${3RDPARTY_TBB_LIBRARY}.2
220              CONFIGURATIONS RelWithDebInfo
221              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
222              RENAME ${TBBLIB}.2)
223     install (FILES ${3RDPARTY_TBB_LIBRARY}.2
224              CONFIGURATIONS Debug
225              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
226              RENAME ${TBBLIB}.2)
227
228     install (FILES ${3RDPARTY_TBBMALLOC_LIBRARY}.2
229              CONFIGURATIONS Release
230              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
231              RENAME ${TBBMALLOCLIB}.2)
232     install (FILES ${3RDPARTY_TBBMALLOC_LIBRARY}.2
233              CONFIGURATIONS RelWithDebInfo
234              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib"
235              RENAME ${TBBMALLOCLIB}.2)
236     install (FILES ${3RDPARTY_TBBMALLOC_LIBRARY}.2
237              CONFIGURATIONS Debug
238              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd"
239              RENAME ${TBBMALLOCLIB}.2)
240   endif()
241
242   set (USED_3RDPARTY_TBB_DIR "")
243 else()
244   # the library directory for using by the executable
245   if (WIN32)
246     set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_DLL_DIR})
247   else()
248     set (USED_3RDPARTY_TBB_DIR ${3RDPARTY_TBB_LIBRARY_DIR})
249   endif()
250 endif()
251
252 mark_as_advanced (3RDPARTY_TBB_LIBRARY 3RDPARTY_TBBMALLOC_LIBRARY 3RDPARTY_TBB_DLL 3RDPARTY_TBBMALLOC_DLL)