0027063: BRepGProps raises exception on edge with no curves
[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
109aa56e 94 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}")
95 file (GLOB FOUND_FILES "${BUILD_PATCH}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
f2e9c853 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
109aa56e 101 if (NOT BUILD_PATCH OR NOT EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}")
e713baee 102 list (APPEND FOUND_FILES ${ORIGIN_FILE})
103 else()
f2e9c853 104 get_filename_component (ORIGIN_FILE_NAME "${ORIGIN_FILE}" NAME)
109aa56e 105 if (NOT EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}/${ORIGIN_FILE_NAME}")
e713baee 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)
109aa56e 150 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}")
151 if (IS_DIRECTORY "${BUILD_PATCH}/${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
109aa56e 156 install (DIRECTORY "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 157 else()
109aa56e 158 install (FILES "${BUILD_PATCH}/${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)
109aa56e 170 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
171 configure_file("${BUILD_PATCH}/${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")
109aa56e 184 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/header.in")
185 set (TEMPLATE_HEADER_PATH "${BUILD_PATCH}/adm/templates/header.in")
f2e9c853 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)
109aa56e 193 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
194 file (STRINGS "${BUILD_PATCH}/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})
f1d057b7 212 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES")
213 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
214 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES")
e713baee 215 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
f1d057b7 216 else()
217 message (WARNING "FILES has not been found in ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}")
218 continue()
219 endif()
f2e9c853 220
f1d057b7 221 list (LENGTH OCCT_ALL_FILE_NAMES ALL_FILES_NB)
222 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" )
d94d80e5 223
f1d057b7 224 # emit warnings if there is unprocessed headers
225 file (GLOB OCCT_ALL_FILES_IN_DIR "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/*.*")
226 file (GLOB OCCT_ALL_FILES_IN_PATCH_DIR "${BUILD_PATCH}/src/${OCCT_PACKAGE}/*.*")
d94d80e5 227
f1d057b7 228 # use patched header files
229 foreach (OCCT_FILE_IN_PATCH_DIR ${OCCT_ALL_FILES_IN_PATCH_DIR})
230 get_filename_component (OCCT_FILE_IN_PATCH_DIR_NAME ${OCCT_FILE_IN_PATCH_DIR} NAME)
231 list (REMOVE_ITEM OCCT_ALL_FILES_IN_DIR "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${OCCT_FILE_IN_PATCH_DIR_NAME}")
232 list (APPEND OCCT_ALL_FILES_IN_DIR "${OCCT_FILE_IN_PATCH_DIR}")
233 endforeach()
e713baee 234
f1d057b7 235 foreach (OCCT_FILE_IN_DIR ${OCCT_ALL_FILES_IN_DIR})
236 get_filename_component (OCCT_FILE_IN_DIR_NAME ${OCCT_FILE_IN_DIR} NAME)
e713baee 237
f1d057b7 238 set (OCCT_FILE_IN_DIR_STATUS OFF)
e713baee 239
f1d057b7 240 if (${ALL_FILES_NB} LESS 0)
241 break()
242 endif()
e713baee 243
f1d057b7 244 foreach (FILE_INDEX RANGE ${ALL_FILES_NB})
245 list (GET OCCT_ALL_FILE_NAMES ${FILE_INDEX} OCCT_FILE_NAME)
e713baee 246
f1d057b7 247 if ("${OCCT_FILE_IN_DIR_NAME}" STREQUAL "${OCCT_FILE_NAME}")
248 set (OCCT_FILE_IN_DIR_STATUS ON)
e713baee 249
e713baee 250 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
251 if (IS_HEADER_FOUND)
f1d057b7 252 list (APPEND OCCT_HEADER_FILES_COMPLETE ${OCCT_FILE_IN_DIR})
253
254 # collect header files with name that does not contain its package one
255 string (FIND "${OCCT_FILE_NAME}" "${OCCT_PACKAGE}_" FOUND_INDEX)
256 if (NOT ${FOUND_INDEX} EQUAL 0)
257 list (APPEND OCCT_HEADER_FILE_WITH_PROPER_NAMES "${OCCT_FILE_NAME}")
258 endif()
e713baee 259 endif()
f1d057b7 260
261 # remove found element from list
262 list (REMOVE_AT OCCT_ALL_FILE_NAMES ${FILE_INDEX})
263 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" ) # decrement number
264
265 break()
d94d80e5 266 endif()
e713baee 267 endforeach()
f1d057b7 268
269 if (NOT OCCT_FILE_IN_DIR_STATUS)
270 message (STATUS "Warning. File ${OCCT_FILE_IN_DIR} is not listed in ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES")
271
272 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
273 if (IS_HEADER_FOUND)
274 list (APPEND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${OCCT_FILE_NAME})
275 endif()
276 endif()
277 endforeach()
d94d80e5 278 endforeach()
279
280 # create new file including found header
e713baee 281 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 282 message (STATUS "Info: \(${CURRENT_TIME}\) Create header-links in inc folder...")
e713baee 283
d94d80e5 284 foreach (OCCT_HEADER_FILE ${OCCT_HEADER_FILES_COMPLETE})
285 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
286 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/inc/${HEADER_FILE_NAME}" @ONLY)
287 endforeach()
288
096ef695 289 install (FILES ${OCCT_HEADER_FILES_COMPLETE} DESTINATION "${INSTALL_INCLUDE_DIR}")
d94d80e5 290
291 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 292 message (STATUS "Info: \(${CURRENT_TIME}\) Checking headers in inc folder...")
d94d80e5 293
294 file (GLOB OCCT_HEADER_FILES_OLD "${ROOT_TARGET_OCCT_DIR}/inc/*")
295 foreach (OCCT_HEADER_FILE_OLD ${OCCT_HEADER_FILES_OLD})
296 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE_OLD} NAME)
297 string (REGEX MATCH "^[a-zA-Z0-9]+" PACKAGE_NAME "${HEADER_FILE_NAME}")
298
299 list (FIND OCCT_USED_PACKAGES ${PACKAGE_NAME} IS_HEADER_FOUND)
300 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
301 if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/${PACKAGE_NAME}/${HEADER_FILE_NAME}")
302 message (STATUS "Warning. ${OCCT_HEADER_FILE_OLD} is not presented in the sources and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
303 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
304 else()
305 list (FIND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${PACKAGE_NAME} IS_HEADER_FOUND)
306 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
307 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")
308 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
309 endif()
310 endif()
311 else()
312 set (IS_HEADER_FOUND -1)
313 if (NOT "${OCCT_HEADER_FILE_WITH_PROPER_NAMES}" STREQUAL "")
314 list (FIND OCCT_HEADER_FILE_WITH_PROPER_NAMES ${HEADER_FILE_NAME} IS_HEADER_FOUND)
315 endif()
316
317 if (${IS_HEADER_FOUND} EQUAL -1)
318 message (STATUS "Warning. \(${PACKAGE_NAME}\) ${OCCT_HEADER_FILE_OLD} is not used and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
319 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
320 endif()
f2e9c853 321 endif()
94829f84 322 endforeach()
323endmacro()
324
19286d7c 325macro (OCCT_COPY_FILE_OR_DIR BEING_COPIED_OBJECT DESTINATION_PATH)
326 # first of all, copy original files
f2e9c853 327 if (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}")
328 file (COPY "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
329 endif()
19286d7c 330
109aa56e 331 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_COPIED_OBJECT}")
19286d7c 332 # secondly, rewrite original files with patched ones
109aa56e 333 file (COPY "${BUILD_PATCH}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 334 endif()
335endmacro()
336
337macro (OCCT_CONFIGURE BEING_CONGIRUGED_FILE FINAL_NAME)
109aa56e 338 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
339 configure_file("${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
19286d7c 340 else()
341 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
342 endif()
343endmacro()
344
f2e9c853 345macro (OCCT_ADD_SUBDIRECTORY BEING_ADDED_DIRECTORY)
109aa56e 346 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
347 add_subdirectory(${BUILD_PATCH}/${BEING_ADDED_DIRECTORY})
f2e9c853 348 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
349 add_subdirectory (${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY})
350 else()
351 message (STATUS "${BEING_ADDED_DIRECTORY} directory is not included")
352 endif()
353endmacro()
354
19286d7c 355function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
356 set (${USE_PRODUCT} OFF PARENT_SCOPE)
357
316d77d9 358 if (NOT BUILD_TOOLKITS)
19286d7c 359 message(STATUS "Warning: the list of being used toolkits is empty")
360 else()
316d77d9 361 foreach (USED_TOOLKIT ${BUILD_TOOLKITS})
109aa56e 362 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB")
363 file (READ "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
19286d7c 364 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
365 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
366 endif()
367
368 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
369
370 if (DOES_FILE_CONTAIN)
371 set (${USE_PRODUCT} ON PARENT_SCOPE)
372 break()
373 endif()
374 endforeach()
375 endif()
376endfunction()
377
378function (FILE_TO_LIST FILE_NAME FILE_CONTENT)
379 set (LOCAL_FILE_CONTENT)
109aa56e 380 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${FILE_NAME}")
381 file (STRINGS "${BUILD_PATCH}/${FILE_NAME}" LOCAL_FILE_CONTENT)
19286d7c 382 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${FILE_NAME}")
383 file (STRINGS "${CMAKE_SOURCE_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
384 endif()
385
386 set (${FILE_CONTENT} ${LOCAL_FILE_CONTENT} PARENT_SCOPE)
387endfunction()
388
389# Function to determine if TOOLKIT is OCCT toolkit
390function (IS_OCCT_TOOLKIT TOOLKIT_NAME MODULES IS_TOOLKIT_FOUND)
391 set (${IS_TOOLKIT_FOUND} OFF PARENT_SCOPE)
392 foreach (MODULE ${${MODULES}})
393 set (TOOLKITS ${${MODULE}_TOOLKITS})
394 list (FIND TOOLKITS ${TOOLKIT_NAME} FOUND)
395
396 if (NOT ${FOUND} EQUAL -1)
397 set (${IS_TOOLKIT_FOUND} ON PARENT_SCOPE)
398 endif()
399 endforeach(MODULE)
400endfunction()
401
402# TOOLKIT_DEPS is defined with dependencies from file src/TOOLKIT_NAME/EXTERNLIB.
403# CSF_ variables are ignored
404function (OCCT_TOOLKIT_DEP TOOLKIT_NAME TOOLKIT_DEPS)
405 FILE_TO_LIST ("src/${TOOLKIT_NAME}/EXTERNLIB" FILE_CONTENT)
406
407 #list (APPEND LOCAL_TOOLKIT_DEPS ${TOOLKIT_NAME})
408 set (LOCAL_TOOLKIT_DEPS)
409 foreach (FILE_CONTENT_LINE ${FILE_CONTENT})
410 string (REGEX MATCH "^TK" TK_FOUND ${FILE_CONTENT_LINE})
411 if ("${FILE_CONTENT_LINE}" STREQUAL "DRAWEXE" OR NOT "${TK_FOUND}" STREQUAL "")
412 list (APPEND LOCAL_TOOLKIT_DEPS ${FILE_CONTENT_LINE})
413 endif()
414 endforeach()
415
416 set (${TOOLKIT_DEPS} ${LOCAL_TOOLKIT_DEPS} PARENT_SCOPE)
417endfunction()
418
419# TOOLKIT_FULL_DEPS is defined with complete dependencies (all levels)
420function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS)
421 # first level dependencies are stored in LOCAL_TOOLKIT_FULL_DEPS
422 OCCT_TOOLKIT_DEP (${TOOLKIT_NAME} LOCAL_TOOLKIT_FULL_DEPS)
423
424 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
425 set (LIST_INDEX 0)
426 while (LIST_INDEX LESS LIST_LENGTH)
427 list (GET LOCAL_TOOLKIT_FULL_DEPS ${LIST_INDEX} CURRENT_TOOLKIT)
428 OCCT_TOOLKIT_DEP (${CURRENT_TOOLKIT} CURRENT_TOOLKIT_DEPS)
429
430 # append toolkits are not contained
431 foreach (CURRENT_TOOLKIT_DEP ${CURRENT_TOOLKIT_DEPS})
432 set (CURRENT_TOOLKIT_DEP_FOUND OFF)
433 foreach (LOCAL_TOOLKIT_FULL_DEP ${LOCAL_TOOLKIT_FULL_DEPS})
434 if ("${CURRENT_TOOLKIT_DEP}" STREQUAL "${LOCAL_TOOLKIT_FULL_DEP}")
435 set (CURRENT_TOOLKIT_DEP_FOUND ON)
436 break()
437 endif()
438 endforeach()
439 if ("${CURRENT_TOOLKIT_DEP_FOUND}" STREQUAL "OFF")
440 list (APPEND LOCAL_TOOLKIT_FULL_DEPS ${CURRENT_TOOLKIT_DEP})
441 endif()
442 endforeach()
443
444 # increment the list index
445 MATH(EXPR LIST_INDEX "${LIST_INDEX}+1")
446
447 # calculate new length
448 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
449 endwhile()
450
451 set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE)
452endfunction()
453
454# Function to get list of modules and toolkits from file adm/MODULES.
455# Creates list <$MODULE_LIST> to store list of MODULES and
456# <NAME_OF_MODULE>_TOOLKITS foreach module to store its toolkits.
457function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST)
458 FILE_TO_LIST ("adm/MODULES" FILE_CONTENT)
459
460 foreach (CONTENT_LINE ${FILE_CONTENT})
461 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
462 list (GET CONTENT_LINE 0 MODULE_NAME)
463 list (REMOVE_AT CONTENT_LINE 0)
464 list (APPEND ${MODULE_LIST} ${MODULE_NAME})
465 # (!) REMOVE THE LINE BELOW (implicit variables)
466 set (${MODULE_NAME}_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE)
467 endforeach()
468
469 set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE)
470endfunction()
471
096ef695 472# Returns OCC version string from file Standard_Version.hxx (if available)
473function (OCC_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT)
adc33035 474
096ef695 475 set (OCC_VERSION_MAJOR 7)
476 set (OCC_VERSION_MINOR 0)
477 set (OCC_VERSION_MAINTENANCE 0)
478 set (OCC_VERSION_DEVELOPMENT dev)
479 set (OCC_VERSION_COMPLETE "7.0.0")
480
adc33035 481 set (STANDARD_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/Standard/Standard_Version.hxx")
096ef695 482 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
483 set (STANDARD_VERSION_FILE "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
484 endif()
485
adc33035 486 if (EXISTS "${STANDARD_VERSION_FILE}")
096ef695 487 foreach (SOUGHT_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE)
adc33035 488 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
096ef695 489 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*([^ ]+).*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
adc33035 490 endforeach()
491
096ef695 492 foreach (SOUGHT_VERSION OCC_VERSION_DEVELOPMENT OCC_VERSION_COMPLETE)
493 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
494 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*\"([^ ]+)\".*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
495 endforeach()
496 endif()
497
498 set (OCC_VERSION_MAJOR "${OCC_VERSION_MAJOR}" PARENT_SCOPE)
499 set (OCC_VERSION_MINOR "${OCC_VERSION_MINOR}" PARENT_SCOPE)
500 set (OCC_VERSION_MAINTENANCE "${OCC_VERSION_MAINTENANCE}" PARENT_SCOPE)
501 set (OCC_VERSION_DEVELOPMENT "${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
502
503 if (OCC_VERSION_DEVELOPMENT AND OCC_VERSION_COMPLETE)
504 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
505 else()
506 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}" PARENT_SCOPE)
adc33035 507 endif()
adc33035 508endfunction()
509
e713baee 510macro (CHECK_PATH_FOR_CONSISTENCY THE_ROOT_PATH_NAME THE_BEING_CHECKED_PATH_NAME THE_VAR_TYPE THE_MESSAGE_OF_BEING_CHECKED_PATH)
511
512 set (THE_ROOT_PATH "${${THE_ROOT_PATH_NAME}}")
513 set (THE_BEING_CHECKED_PATH "${${THE_BEING_CHECKED_PATH_NAME}}")
514
515 if (THE_BEING_CHECKED_PATH OR EXISTS "${THE_BEING_CHECKED_PATH}")
516 get_filename_component (THE_ROOT_PATH_ABS "${THE_ROOT_PATH}" ABSOLUTE)
517 get_filename_component (THE_BEING_CHECKED_PATH_ABS "${THE_BEING_CHECKED_PATH}" ABSOLUTE)
518
519 string (REGEX MATCH "${THE_ROOT_PATH_ABS}" DOES_PATH_CONTAIN "${THE_BEING_CHECKED_PATH_ABS}")
520
521 if (NOT DOES_PATH_CONTAIN) # if cmake found the being checked path at different place from THE_ROOT_PATH_ABS
522 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
523 endif()
524 else()
525 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
526 endif()
527
528endmacro()