0026460: Implicit cast to TopoDS_Shape compilation error due to ambiguous conversion
[occt.git] / adm / cmake / tbb.cmake
CommitLineData
9f33b387 1# tbb
2
9f33b387 3if (NOT DEFINED INSTALL_TBB)
4 set (INSTALL_TBB OFF CACHE BOOL "Is tbb required to be copied into install directory")
5endif()
6
7# tbb directory
8if (NOT DEFINED 3RDPARTY_TBB_DIR)
9 set (3RDPARTY_TBB_DIR "" CACHE PATH "The directory containing tbb")
10endif()
11
12# tbb include directory
13if (NOT DEFINED 3RDPARTY_TBB_INCLUDE_DIR)
14 set (3RDPARTY_TBB_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of the tbb")
15endif()
16
17# tbb library file (with absolute path)
18if (NOT DEFINED 3RDPARTY_TBB_LIBRARY OR NOT 3RDPARTY_TBB_LIBRARY_DIR)
19 set (3RDPARTY_TBB_LIBRARY "" CACHE FILEPATH "tbb library" FORCE)
20endif()
21
22# tbb library directory
23if (NOT DEFINED 3RDPARTY_TBB_LIBRARY_DIR)
24 set (3RDPARTY_TBB_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tbb library")
25endif()
26
27# tbb malloc library file (with absolute path)
28if (NOT DEFINED 3RDPARTY_TBBMALLOC_LIBRARY OR NOT 3RDPARTY_TBBMALLOC_LIBRARY_DIR)
29 set (3RDPARTY_TBBMALLOC_LIBRARY "" CACHE FILEPATH "tbb malloc library" FORCE)
30endif()
31
32# tbb malloc library directory
33if (NOT DEFINED 3RDPARTY_TBBMALLOC_LIBRARY_DIR)
34 set (3RDPARTY_TBBMALLOC_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tbb malloc library")
35endif()
36
37# tbb shared library (with absolute path)
38if (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()
42endif()
43
44# tbb shared library directory
45if (WIN32 AND NOT DEFINED 3RDPARTY_TBB_DLL_DIR)
46 set (3RDPARTY_TBB_DLL_DIR "" CACHE FILEPATH "The directory containing tbb shared library")
47endif()
48
49# tbb malloc shared library (with absolute path)
50if (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()
54endif()
55
56# tbb malloc shared library directory
19286d7c 57if (WIN32 AND NOT DEFINED 3RDPARTY_TBBMALLOC_DLL_DIR)
9f33b387 58 set (3RDPARTY_TBBMALLOC_DLL_DIR "" CACHE FILEPATH "The directory containing tbb malloc shared library")
59endif()
60
fa0cbe55 61# include occt macros. compiler_bitness, os_wiht_bit, compiler
19286d7c 62OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
9f33b387 63
64# search for product directory inside 3RDPARTY_DIR directory
65if (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()
71endif()
72
73OCCT_MAKE_COMPILER_BITNESS()
74
75if (${COMPILER_BITNESS} STREQUAL 32)
76 set (TBB_ARCH_NAME ia32)
77else()
78 set (TBB_ARCH_NAME intel64)
79endif()
80
81# search for include directory in defined 3rdparty directory
82if (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)
19286d7c 84 find_path (3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include" NO_DEFAULT_PATH)
9f33b387 85 find_path (3RDPARTY_TBB_INCLUDE_DIR tbb/tbb.h PATHS "${3RDPARTY_TBB_DIR}/include")
86endif()
87
88if (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)
90endif()
91
92OCCT_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
9f33b387 101# search for tbb and tbb malloc library in defined 3rdparty directory
102foreach (LIBRARY_NAME TBB TBBMALLOC)
19286d7c 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()
9f33b387 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
fa0cbe55 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)
9f33b387 131
132 # second search if previous one do not find anything
133 find_library (3RDPARTY_${LIBRARY_NAME}_LIBRARY ${LIBRARY_NAME})
9f33b387 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)
9f33b387 138 endif()
19286d7c 139 set (3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR "${3RDPARTY_${LIBRARY_NAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${LIBRARY_NAME} library" FORCE)
9f33b387 140
141 # search for dll in defined 3rdparty directory (just for win case)
142 if (WIN32)
143 set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
19286d7c 144
9f33b387 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
fa0cbe55 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)
9f33b387 161
162 # second search if previous one do not find anything
163 find_library (3RDPARTY_${LIBRARY_NAME}_DLL ${LIBRARY_NAME})
9f33b387 164 endif()
19286d7c 165
9f33b387 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
171endforeach() # end tbb / tbbmalloc
172
173# include found paths to common variables
174if (3RDPARTY_TBB_INCLUDE_DIR AND EXISTS "${3RDPARTY_TBB_INCLUDE_DIR}")
175 list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_TBB_INCLUDE_DIR}")
176else()
177 list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TBB_INCLUDE_DIR)
178endif()
179
180foreach (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)
94829f84 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()
9f33b387 191 list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBRARY_NAME}_DLL_DIR)
192 endif()
193 endif()
194endforeach()
195
196# install tbb
197if (INSTALL_TBB)
198 OCCT_MAKE_OS_WITH_BITNESS()
199 OCCT_MAKE_COMPILER_SHORT_NAME()
200
201 if (WIN32)
fa0cbe55 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")
9f33b387 211 else()
19286d7c 212 get_filename_component(TBBLIB ${3RDPARTY_TBB_LIBRARY} NAME)
213 get_filename_component(TBBMALLOCLIB ${3RDPARTY_TBBMALLOC_LIBRARY} NAME)
fa0cbe55 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)
9f33b387 240 endif()
0a66e59d 241
242 set (USED_3RDPARTY_TBB_DIR "")
243else()
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()
9f33b387 250endif()
251
252mark_as_advanced (3RDPARTY_TBB_LIBRARY 3RDPARTY_TBBMALLOC_LIBRARY 3RDPARTY_TBB_DLL 3RDPARTY_TBBMALLOC_DLL)