0026993: Configuration, CMake - use the abstraction level of VTK instead CSF_VTK...
[occt.git] / adm / cmake / occt_macros.cmake
CommitLineData
e713baee 1##
2
3if(OCCT_MACROS_ALREADY_INCLUDED)
4 return()
5endif()
6set(OCCT_MACROS_ALREADY_INCLUDED 1)
7
8
19286d7c 9macro (OCCT_CHECK_AND_UNSET VARNAME)
10 if (DEFINED ${VARNAME})
11 unset (${VARNAME} CACHE)
12 endif()
13endmacro()
14
15macro (OCCT_CHECK_AND_UNSET_GROUP VARNAME)
16 OCCT_CHECK_AND_UNSET ("${VARNAME}_DIR")
17
18 OCCT_CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
19
20 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
21 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY_DIR")
22
23 if (WIN32)
24 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL")
25 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL_DIR")
26 endif()
27endmacro()
28
19286d7c 29# COMPILER_BITNESS variable
30macro (OCCT_MAKE_COMPILER_BITNESS)
31 math (EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
32endmacro()
33
34# OS_WITH_BIT
35macro (OCCT_MAKE_OS_WITH_BITNESS)
36
37 OCCT_MAKE_COMPILER_BITNESS()
38
39 if (WIN32)
40 set (OS_WITH_BIT "win${COMPILER_BITNESS}")
41 elseif(APPLE)
42 set (OS_WITH_BIT "mac${COMPILER_BITNESS}")
43 else()
44 set (OS_WITH_BIT "lin${COMPILER_BITNESS}")
45 endif()
46endmacro()
47
48# COMPILER variable
49macro (OCCT_MAKE_COMPILER_SHORT_NAME)
50 if (MSVC)
51 if (MSVC70)
52 set (COMPILER vc7)
53 elseif (MSVC80)
54 set (COMPILER vc8)
55 elseif (MSVC90)
56 set (COMPILER vc9)
57 elseif (MSVC10)
58 set (COMPILER vc10)
59 elseif (MSVC11)
60 set (COMPILER vc11)
61 elseif (MSVC12)
62 set (COMPILER vc12)
63cf1bb6 63 elseif (MSVC14)
64 set (COMPILER vc14)
19286d7c 65 endif()
66 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
67 set (COMPILER gcc)
68 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
69 set (COMPILER gxx)
70 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
71 set (COMPILER clang)
72 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
73 set (COMPILER icc)
74 else()
75 set (COMPILER ${CMAKE_GENERATOR})
76 string (REGEX REPLACE " " "" COMPILER ${COMPILER})
77 endif()
78endmacro()
79
80function (SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
81 file (GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
82
83 foreach (ITEM ${SUB_ITEMS})
84 if (IS_DIRECTORY "${ITEM}")
85 get_filename_component (ITEM_NAME "${ITEM}" NAME)
86 list (APPEND LOCAL_RESULT "${ITEM_NAME}")
87 endif()
88 endforeach()
89 set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
90endfunction()
91
f2e9c853 92function (OCCT_ORIGIN_AND_PATCHED_FILES RELATIVE_PATH SEARCH_TEMPLATE RESULT)
93
94 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}")
95 file (GLOB FOUND_FILES "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
96 endif()
97
98 file (GLOB ORIGIN_FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
99 foreach (ORIGIN_FILE ${ORIGIN_FILES})
100 # check for existence of patched version of current file
e713baee 101 if (NOT APPLY_OCCT_PATCH_DIR OR NOT EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}")
102 list (APPEND FOUND_FILES ${ORIGIN_FILE})
103 else()
f2e9c853 104 get_filename_component (ORIGIN_FILE_NAME "${ORIGIN_FILE}" NAME)
e713baee 105 if (NOT EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}/${ORIGIN_FILE_NAME}")
106 list (APPEND FOUND_FILES ${ORIGIN_FILE})
f2e9c853 107 endif()
108 endif()
f2e9c853 109 endforeach()
110
111 set (${RESULT} ${FOUND_FILES} PARENT_SCOPE)
112endfunction()
113
19286d7c 114function (FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
115 OCCT_MAKE_COMPILER_SHORT_NAME()
116 OCCT_MAKE_COMPILER_BITNESS()
117
118 string (TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME)
119
d3ff0ff2 120 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*${COMPILER}.*${COMPILER_BITNESS}")
121 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
122 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER_BITNESS}")
123 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+")
124 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*")
19286d7c 125
126 SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
127
128 foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
129 if (LOCAL_RESULT)
130 BREAK()
131 endif()
132
133 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
134 string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
135
136 string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
137 if (DUMMY_VAR)
138 list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
139 endif()
140 endforeach()
141 endforeach()
142
143 if (LOCAL_RESULT)
e713baee 144 list (GET LOCAL_RESULT -1 DUMMY)
19286d7c 145 set (${RESULT} ${DUMMY} PARENT_SCOPE)
146 endif()
147endfunction()
148
149macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
316d77d9 150 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
151 if (IS_DIRECTORY "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
19286d7c 152 # first of all, install original files
153 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
154
155 # secondly, rewrite original files with patched ones
316d77d9 156 install (DIRECTORY "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 157 else()
316d77d9 158 install (FILES "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 159 endif()
160 else()
161 if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
162 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
163 else()
164 install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
165 endif()
166 endif()
167endmacro()
168
316d77d9 169macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE BUILD_NAME INSTALL_NAME DESTINATION_PATH)
170 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
171 configure_file("${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 172 else()
316d77d9 173 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 174 endif()
175
316d77d9 176 install(FILES "${OCCT_BINARY_DIR}/${BUILD_NAME}" DESTINATION "${DESTINATION_PATH}" RENAME ${INSTALL_NAME})
19286d7c 177endmacro()
178
f2e9c853 179macro (COLLECT_AND_INSTALL_OCCT_HEADER_FILES ROOT_TARGET_OCCT_DIR OCCT_BUILD_TOOLKITS)
d94d80e5 180 set (OCCT_USED_PACKAGES)
94829f84 181
f2e9c853 182 # consider patched header.in template
183 set (TEMPLATE_HEADER_PATH "${CMAKE_SOURCE_DIR}/adm/templates/header.in")
184 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/header.in")
185 set (TEMPLATE_HEADER_PATH "${APPLY_OCCT_PATCH_DIR}/adm/templates/header.in")
186 endif()
187
188 set (ROOT_OCCT_DIR ${CMAKE_SOURCE_DIR})
189
316d77d9 190 foreach (OCCT_USED_TOOLKIT ${OCCT_BUILD_TOOLKITS})
94829f84 191 # append all required package folders
d94d80e5 192 set (OCCT_TOOLKIT_PACKAGES)
f2e9c853 193 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
d94d80e5 194 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
f2e9c853 195 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
d94d80e5 196 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
94829f84 197 endif()
198
d94d80e5 199 list (APPEND OCCT_USED_PACKAGES ${OCCT_TOOLKIT_PACKAGES})
94829f84 200 endforeach()
201
d94d80e5 202 list (REMOVE_DUPLICATES OCCT_USED_PACKAGES)
f2e9c853 203
d94d80e5 204 set (OCCT_HEADER_FILES_COMPLETE)
205 set (OCCT_HEADER_FILE_NAMES_NOT_IN_FILES)
206 set (OCCT_HEADER_FILE_WITH_PROPER_NAMES)
e713baee 207
208 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 209 message (STATUS "Info: \(${CURRENT_TIME}\) Compare FILES with files in package directories...")
e713baee 210
d94d80e5 211 foreach (OCCT_PACKAGE ${OCCT_USED_PACKAGES})
e713baee 212 if (EXISTS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES")
213 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
f2e9c853 214
e713baee 215 list (LENGTH OCCT_ALL_FILE_NAMES ALL_FILES_NB)
216 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" )
d94d80e5 217
e713baee 218 # emit warnings if there is unprocessed headers
219 file (GLOB OCCT_ALL_FILES_IN_DIR "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/*.*")
220 foreach (OCCT_FILE_IN_DIR ${OCCT_ALL_FILES_IN_DIR})
221 get_filename_component (OCCT_FILE_IN_DIR_NAME ${OCCT_FILE_IN_DIR} NAME)
d94d80e5 222
e713baee 223 set (OCCT_FILE_IN_DIR_STATUS OFF)
d94d80e5 224
e713baee 225 if (${ALL_FILES_NB} LESS 0)
d94d80e5 226 break()
227 endif()
d94d80e5 228
e713baee 229 foreach (FILE_INDEX RANGE ${ALL_FILES_NB})
230 list (GET OCCT_ALL_FILE_NAMES ${FILE_INDEX} OCCT_FILE_NAME)
231
232 if ("${OCCT_FILE_IN_DIR_NAME}" STREQUAL "${OCCT_FILE_NAME}")
233 set (OCCT_FILE_IN_DIR_STATUS ON)
234
235 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
236 if (IS_HEADER_FOUND)
237 list (APPEND OCCT_HEADER_FILES_COMPLETE ${OCCT_FILE_IN_DIR})
238
239 # collect header files with name that does not contain its package one
240 string (FIND "${OCCT_FILE_NAME}" "${OCCT_PACKAGE}_" FOUND_INDEX)
241 if (NOT ${FOUND_INDEX} EQUAL 0)
242 list (APPEND OCCT_HEADER_FILE_WITH_PROPER_NAMES "${OCCT_FILE_NAME}")
243 endif()
244 endif()
245
246 # remove found element from list
247 list (REMOVE_AT OCCT_ALL_FILE_NAMES ${FILE_INDEX})
248 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" ) # decrement number
249
250 break()
251 endif()
252 endforeach()
253
254 if (NOT OCCT_FILE_IN_DIR_STATUS)
a6874708 255 message (STATUS "Warning. File ${OCCT_FILE_IN_DIR} is not listed in ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES")
e713baee 256
257 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
258 if (IS_HEADER_FOUND)
259 list (APPEND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${OCCT_FILE_NAME})
260 endif()
d94d80e5 261 endif()
e713baee 262 endforeach()
263 else()
264 message (WARNING "FILES has not been found in ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}")
265 endif()
d94d80e5 266 endforeach()
267
268 # create new file including found header
e713baee 269 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 270 message (STATUS "Info: \(${CURRENT_TIME}\) Create header-links in inc folder...")
e713baee 271
d94d80e5 272 foreach (OCCT_HEADER_FILE ${OCCT_HEADER_FILES_COMPLETE})
273 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
274 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/inc/${HEADER_FILE_NAME}" @ONLY)
275 endforeach()
276
277 install (FILES ${OCCT_HEADER_FILES_COMPLETE} DESTINATION "${INSTALL_DIR}/inc")
278
279 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 280 message (STATUS "Info: \(${CURRENT_TIME}\) Checking headers in inc folder...")
d94d80e5 281
282 file (GLOB OCCT_HEADER_FILES_OLD "${ROOT_TARGET_OCCT_DIR}/inc/*")
283 foreach (OCCT_HEADER_FILE_OLD ${OCCT_HEADER_FILES_OLD})
284 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE_OLD} NAME)
285 string (REGEX MATCH "^[a-zA-Z0-9]+" PACKAGE_NAME "${HEADER_FILE_NAME}")
286
287 list (FIND OCCT_USED_PACKAGES ${PACKAGE_NAME} IS_HEADER_FOUND)
288 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
289 if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/${PACKAGE_NAME}/${HEADER_FILE_NAME}")
290 message (STATUS "Warning. ${OCCT_HEADER_FILE_OLD} is not presented in the sources and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
291 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
292 else()
293 list (FIND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${PACKAGE_NAME} IS_HEADER_FOUND)
294 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
295 message (STATUS "Warning. ${OCCT_HEADER_FILE_OLD} is presented in the sources but not involved in FILES and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
296 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
297 endif()
298 endif()
299 else()
300 set (IS_HEADER_FOUND -1)
301 if (NOT "${OCCT_HEADER_FILE_WITH_PROPER_NAMES}" STREQUAL "")
302 list (FIND OCCT_HEADER_FILE_WITH_PROPER_NAMES ${HEADER_FILE_NAME} IS_HEADER_FOUND)
303 endif()
304
305 if (${IS_HEADER_FOUND} EQUAL -1)
306 message (STATUS "Warning. \(${PACKAGE_NAME}\) ${OCCT_HEADER_FILE_OLD} is not used and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
307 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
308 endif()
f2e9c853 309 endif()
94829f84 310 endforeach()
311endmacro()
312
19286d7c 313macro (OCCT_COPY_FILE_OR_DIR BEING_COPIED_OBJECT DESTINATION_PATH)
314 # first of all, copy original files
f2e9c853 315 if (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}")
316 file (COPY "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
317 endif()
19286d7c 318
316d77d9 319 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_COPIED_OBJECT}")
19286d7c 320 # secondly, rewrite original files with patched ones
316d77d9 321 file (COPY "${APPLY_OCCT_PATCH_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 322 endif()
323endmacro()
324
325macro (OCCT_CONFIGURE BEING_CONGIRUGED_FILE FINAL_NAME)
316d77d9 326 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
327 configure_file("${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
19286d7c 328 else()
329 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
330 endif()
331endmacro()
332
f2e9c853 333macro (OCCT_ADD_SUBDIRECTORY BEING_ADDED_DIRECTORY)
334 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
335 add_subdirectory(${APPLY_OCCT_PATCH_DIR}/${BEING_ADDED_DIRECTORY})
336 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
337 add_subdirectory (${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY})
338 else()
339 message (STATUS "${BEING_ADDED_DIRECTORY} directory is not included")
340 endif()
341endmacro()
342
19286d7c 343function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
344 set (${USE_PRODUCT} OFF PARENT_SCOPE)
345
316d77d9 346 if (NOT BUILD_TOOLKITS)
19286d7c 347 message(STATUS "Warning: the list of being used toolkits is empty")
348 else()
316d77d9 349 foreach (USED_TOOLKIT ${BUILD_TOOLKITS})
350 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
351 file (READ "${APPLY_OCCT_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
19286d7c 352 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
353 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
354 endif()
355
356 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
357
358 if (DOES_FILE_CONTAIN)
359 set (${USE_PRODUCT} ON PARENT_SCOPE)
360 break()
361 endif()
362 endforeach()
363 endif()
364endfunction()
365
366function (FILE_TO_LIST FILE_NAME FILE_CONTENT)
367 set (LOCAL_FILE_CONTENT)
316d77d9 368 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${FILE_NAME}")
369 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
19286d7c 370 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${FILE_NAME}")
371 file (STRINGS "${CMAKE_SOURCE_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
372 endif()
373
374 set (${FILE_CONTENT} ${LOCAL_FILE_CONTENT} PARENT_SCOPE)
375endfunction()
376
377# Function to determine if TOOLKIT is OCCT toolkit
378function (IS_OCCT_TOOLKIT TOOLKIT_NAME MODULES IS_TOOLKIT_FOUND)
379 set (${IS_TOOLKIT_FOUND} OFF PARENT_SCOPE)
380 foreach (MODULE ${${MODULES}})
381 set (TOOLKITS ${${MODULE}_TOOLKITS})
382 list (FIND TOOLKITS ${TOOLKIT_NAME} FOUND)
383
384 if (NOT ${FOUND} EQUAL -1)
385 set (${IS_TOOLKIT_FOUND} ON PARENT_SCOPE)
386 endif()
387 endforeach(MODULE)
388endfunction()
389
390# TOOLKIT_DEPS is defined with dependencies from file src/TOOLKIT_NAME/EXTERNLIB.
391# CSF_ variables are ignored
392function (OCCT_TOOLKIT_DEP TOOLKIT_NAME TOOLKIT_DEPS)
393 FILE_TO_LIST ("src/${TOOLKIT_NAME}/EXTERNLIB" FILE_CONTENT)
394
395 #list (APPEND LOCAL_TOOLKIT_DEPS ${TOOLKIT_NAME})
396 set (LOCAL_TOOLKIT_DEPS)
397 foreach (FILE_CONTENT_LINE ${FILE_CONTENT})
398 string (REGEX MATCH "^TK" TK_FOUND ${FILE_CONTENT_LINE})
399 if ("${FILE_CONTENT_LINE}" STREQUAL "DRAWEXE" OR NOT "${TK_FOUND}" STREQUAL "")
400 list (APPEND LOCAL_TOOLKIT_DEPS ${FILE_CONTENT_LINE})
401 endif()
402 endforeach()
403
404 set (${TOOLKIT_DEPS} ${LOCAL_TOOLKIT_DEPS} PARENT_SCOPE)
405endfunction()
406
407# TOOLKIT_FULL_DEPS is defined with complete dependencies (all levels)
408function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS)
409 # first level dependencies are stored in LOCAL_TOOLKIT_FULL_DEPS
410 OCCT_TOOLKIT_DEP (${TOOLKIT_NAME} LOCAL_TOOLKIT_FULL_DEPS)
411
412 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
413 set (LIST_INDEX 0)
414 while (LIST_INDEX LESS LIST_LENGTH)
415 list (GET LOCAL_TOOLKIT_FULL_DEPS ${LIST_INDEX} CURRENT_TOOLKIT)
416 OCCT_TOOLKIT_DEP (${CURRENT_TOOLKIT} CURRENT_TOOLKIT_DEPS)
417
418 # append toolkits are not contained
419 foreach (CURRENT_TOOLKIT_DEP ${CURRENT_TOOLKIT_DEPS})
420 set (CURRENT_TOOLKIT_DEP_FOUND OFF)
421 foreach (LOCAL_TOOLKIT_FULL_DEP ${LOCAL_TOOLKIT_FULL_DEPS})
422 if ("${CURRENT_TOOLKIT_DEP}" STREQUAL "${LOCAL_TOOLKIT_FULL_DEP}")
423 set (CURRENT_TOOLKIT_DEP_FOUND ON)
424 break()
425 endif()
426 endforeach()
427 if ("${CURRENT_TOOLKIT_DEP_FOUND}" STREQUAL "OFF")
428 list (APPEND LOCAL_TOOLKIT_FULL_DEPS ${CURRENT_TOOLKIT_DEP})
429 endif()
430 endforeach()
431
432 # increment the list index
433 MATH(EXPR LIST_INDEX "${LIST_INDEX}+1")
434
435 # calculate new length
436 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
437 endwhile()
438
439 set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE)
440endfunction()
441
442# Function to get list of modules and toolkits from file adm/MODULES.
443# Creates list <$MODULE_LIST> to store list of MODULES and
444# <NAME_OF_MODULE>_TOOLKITS foreach module to store its toolkits.
445function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST)
446 FILE_TO_LIST ("adm/MODULES" FILE_CONTENT)
447
448 foreach (CONTENT_LINE ${FILE_CONTENT})
449 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
450 list (GET CONTENT_LINE 0 MODULE_NAME)
451 list (REMOVE_AT CONTENT_LINE 0)
452 list (APPEND ${MODULE_LIST} ${MODULE_NAME})
453 # (!) REMOVE THE LINE BELOW (implicit variables)
454 set (${MODULE_NAME}_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE)
455 endforeach()
456
457 set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE)
458endfunction()
459
adc33035 460# Returns OCCT version string from file Standard_Version.hxx (if available)
461function (OCCT_VERSION OCCT_VERSION_VAR)
462 set (OCC_VERSION_COMPLETE "7.1.0")
463 set (OCC_VERSION_DEVELOPMENT "")
464
465 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}")
466
467 set (STANDARD_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/Standard/Standard_Version.hxx")
468 if (EXISTS "${STANDARD_VERSION_FILE}")
469 foreach (SOUGHT_VERSION OCC_VERSION_COMPLETE OCC_VERSION_DEVELOPMENT)
470 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
471 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*\"([^ ]+)\".*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
472 endforeach()
473
474 if (NOT "${OCC_VERSION_DEVELOPMENT}" STREQUAL "")
475 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}")
476 else()
477 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}")
478 endif()
479 endif()
480
481 set (${OCCT_VERSION_VAR} "${OCCT_VERSION_LOCALVAR}" PARENT_SCOPE)
482endfunction()
483
e713baee 484macro (CHECK_PATH_FOR_CONSISTENCY THE_ROOT_PATH_NAME THE_BEING_CHECKED_PATH_NAME THE_VAR_TYPE THE_MESSAGE_OF_BEING_CHECKED_PATH)
485
486 set (THE_ROOT_PATH "${${THE_ROOT_PATH_NAME}}")
487 set (THE_BEING_CHECKED_PATH "${${THE_BEING_CHECKED_PATH_NAME}}")
488
489 if (THE_BEING_CHECKED_PATH OR EXISTS "${THE_BEING_CHECKED_PATH}")
490 get_filename_component (THE_ROOT_PATH_ABS "${THE_ROOT_PATH}" ABSOLUTE)
491 get_filename_component (THE_BEING_CHECKED_PATH_ABS "${THE_BEING_CHECKED_PATH}" ABSOLUTE)
492
493 string (REGEX MATCH "${THE_ROOT_PATH_ABS}" DOES_PATH_CONTAIN "${THE_BEING_CHECKED_PATH_ABS}")
494
495 if (NOT DOES_PATH_CONTAIN) # if cmake found the being checked path at different place from THE_ROOT_PATH_ABS
496 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
497 endif()
498 else()
499 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
500 endif()
501
502endmacro()