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