0029560: Jenkins - Control of license statements and non-ascii characters in integrat...
[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
4b3541c6 29macro (OCCT_CHECK_AND_UNSET_INSTALL_DIR_SUBDIRS)
30 OCCT_CHECK_AND_UNSET (INSTALL_DIR_BIN)
31 OCCT_CHECK_AND_UNSET (INSTALL_DIR_SCRIPT)
32 OCCT_CHECK_AND_UNSET (INSTALL_DIR_LIB)
33 OCCT_CHECK_AND_UNSET (INSTALL_DIR_INCLUDE)
34 OCCT_CHECK_AND_UNSET (INSTALL_DIR_RESOURCE)
35 OCCT_CHECK_AND_UNSET (INSTALL_DIR_DATA)
36 OCCT_CHECK_AND_UNSET (INSTALL_DIR_SAMPLES)
37 OCCT_CHECK_AND_UNSET (INSTALL_DIR_TESTS)
38 OCCT_CHECK_AND_UNSET (INSTALL_DIR_DOC)
39endmacro()
40
19286d7c 41# COMPILER_BITNESS variable
42macro (OCCT_MAKE_COMPILER_BITNESS)
43 math (EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
44endmacro()
45
46# OS_WITH_BIT
47macro (OCCT_MAKE_OS_WITH_BITNESS)
48
49 OCCT_MAKE_COMPILER_BITNESS()
50
51 if (WIN32)
52 set (OS_WITH_BIT "win${COMPILER_BITNESS}")
53 elseif(APPLE)
54 set (OS_WITH_BIT "mac${COMPILER_BITNESS}")
55 else()
56 set (OS_WITH_BIT "lin${COMPILER_BITNESS}")
57 endif()
58endmacro()
59
60# COMPILER variable
61macro (OCCT_MAKE_COMPILER_SHORT_NAME)
62 if (MSVC)
1167d6cc 63 if ((MSVC_VERSION EQUAL 1300) OR (MSVC_VERSION EQUAL 1310))
19286d7c 64 set (COMPILER vc7)
1167d6cc 65 elseif (MSVC_VERSION EQUAL 1400)
19286d7c 66 set (COMPILER vc8)
1167d6cc 67 elseif (MSVC_VERSION EQUAL 1500)
19286d7c 68 set (COMPILER vc9)
1167d6cc 69 elseif (MSVC_VERSION EQUAL 1600)
19286d7c 70 set (COMPILER vc10)
1167d6cc 71 elseif (MSVC_VERSION EQUAL 1700)
19286d7c 72 set (COMPILER vc11)
1167d6cc 73 elseif (MSVC_VERSION EQUAL 1800)
19286d7c 74 set (COMPILER vc12)
1167d6cc 75 elseif (MSVC_VERSION EQUAL 1900)
63cf1bb6 76 set (COMPILER vc14)
1167d6cc 77 elseif ((MSVC_VERSION GREATER 1900) AND (MSVC_VERSION LESS 2000))
d6cda17a 78 # Since Visual Studio 15 (2017), its version diverged from version of
79 # compiler which is 14.1; as that compiler uses the same run-time as 14.0,
80 # we keep its id as "vc14" to be compatibille
81 set (COMPILER vc14)
1167d6cc 82 else()
83 message (FATAL_ERROR "Unrecognized MSVC_VERSION")
19286d7c 84 endif()
85 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
86 set (COMPILER gcc)
87 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
88 set (COMPILER gxx)
89 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
90 set (COMPILER clang)
91 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
92 set (COMPILER icc)
93 else()
94 set (COMPILER ${CMAKE_GENERATOR})
95 string (REGEX REPLACE " " "" COMPILER ${COMPILER})
96 endif()
97endmacro()
98
99function (SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
100 file (GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
101
102 foreach (ITEM ${SUB_ITEMS})
103 if (IS_DIRECTORY "${ITEM}")
104 get_filename_component (ITEM_NAME "${ITEM}" NAME)
105 list (APPEND LOCAL_RESULT "${ITEM_NAME}")
106 endif()
107 endforeach()
108 set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
109endfunction()
110
14bbbdcb 111function (FIND_SUBDIRECTORY ROOT_DIRECTORY DIRECTORY_SUFFIX SUBDIRECTORY_NAME)
112 #message("Trying to find directory with suffix ${DIRECTORY_SUFFIX} in ${ROOT_DIRECTORY}")
113 SUBDIRECTORY_NAMES ("${ROOT_DIRECTORY}" SUBDIR_NAME_LIST)
114 #message("Subdirectories: ${SUBDIR_NAME_LIST}")
115
116 #set(${SUBDIRECTORY_NAME} "${SUBDIR_NAME_LIST}" PARENT_SCOPE)
117
118 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
119 #message("Subdir: ${SUBDIR_NAME}, ${DIRECTORY_SUFFIX}")
120 # REGEX failed if the directory name contains '++' combination, so we replace it
4f4b8935 121 string(REPLACE "+" "\\+" SUBDIR_NAME_ESCAPED ${SUBDIR_NAME})
14bbbdcb 122 string (REGEX MATCH "${SUBDIR_NAME_ESCAPED}" DOES_PATH_CONTAIN "${DIRECTORY_SUFFIX}")
123 if (DOES_PATH_CONTAIN)
124 set(${SUBDIRECTORY_NAME} "${ROOT_DIRECTORY}/${SUBDIR_NAME}" PARENT_SCOPE)
125 #message("Subdirectory is found: ${SUBDIRECTORY_NAME}")
126 BREAK()
127 else()
128 #message("Check directory: ${ROOT_DIRECTORY}/${SUBDIR_NAME}")
129 FIND_SUBDIRECTORY ("${ROOT_DIRECTORY}/${SUBDIR_NAME}" "${DIRECTORY_SUFFIX}" SUBDIR_REC_NAME)
130 if (NOT "${SUBDIR_REC_NAME}" STREQUAL "")
131 set(${SUBDIRECTORY_NAME} "${SUBDIR_REC_NAME}" PARENT_SCOPE)
132 #message("Subdirectory is found: ${SUBDIRECTORY_NAME}")
133 BREAK()
134 endif()
135 endif()
136 endforeach()
137endfunction()
138
f2e9c853 139function (OCCT_ORIGIN_AND_PATCHED_FILES RELATIVE_PATH SEARCH_TEMPLATE RESULT)
140
109aa56e 141 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}")
142 file (GLOB FOUND_FILES "${BUILD_PATCH}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
f2e9c853 143 endif()
144
145 file (GLOB ORIGIN_FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
146 foreach (ORIGIN_FILE ${ORIGIN_FILES})
147 # check for existence of patched version of current file
109aa56e 148 if (NOT BUILD_PATCH OR NOT EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}")
e713baee 149 list (APPEND FOUND_FILES ${ORIGIN_FILE})
150 else()
f2e9c853 151 get_filename_component (ORIGIN_FILE_NAME "${ORIGIN_FILE}" NAME)
109aa56e 152 if (NOT EXISTS "${BUILD_PATCH}/${RELATIVE_PATH}/${ORIGIN_FILE_NAME}")
e713baee 153 list (APPEND FOUND_FILES ${ORIGIN_FILE})
f2e9c853 154 endif()
155 endif()
f2e9c853 156 endforeach()
157
158 set (${RESULT} ${FOUND_FILES} PARENT_SCOPE)
159endfunction()
160
19286d7c 161function (FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
162 OCCT_MAKE_COMPILER_SHORT_NAME()
163 OCCT_MAKE_COMPILER_BITNESS()
164
165 string (TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME)
166
d3ff0ff2 167 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*${COMPILER}.*${COMPILER_BITNESS}")
168 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
169 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER_BITNESS}")
78934a4f 170 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*.*${COMPILER_BITNESS}")
d3ff0ff2 171 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+")
172 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*")
19286d7c 173
174 SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
175
176 foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
177 if (LOCAL_RESULT)
178 BREAK()
179 endif()
180
181 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
182 string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
183
184 string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
185 if (DUMMY_VAR)
186 list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
187 endif()
188 endforeach()
189 endforeach()
190
191 if (LOCAL_RESULT)
e713baee 192 list (GET LOCAL_RESULT -1 DUMMY)
19286d7c 193 set (${RESULT} ${DUMMY} PARENT_SCOPE)
194 endif()
195endfunction()
196
197macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
109aa56e 198 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}")
199 if (IS_DIRECTORY "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}")
19286d7c 200 # first of all, install original files
201 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
202
203 # secondly, rewrite original files with patched ones
109aa56e 204 install (DIRECTORY "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 205 else()
109aa56e 206 install (FILES "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 207 endif()
208 else()
209 if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
210 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
211 else()
212 install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
213 endif()
214 endif()
215endmacro()
216
316d77d9 217macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE BUILD_NAME INSTALL_NAME DESTINATION_PATH)
109aa56e 218 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
219 configure_file("${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 220 else()
316d77d9 221 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 222 endif()
223
316d77d9 224 install(FILES "${OCCT_BINARY_DIR}/${BUILD_NAME}" DESTINATION "${DESTINATION_PATH}" RENAME ${INSTALL_NAME})
19286d7c 225endmacro()
226
14bbbdcb 227macro (COLLECT_AND_INSTALL_OCCT_HEADER_FILES ROOT_TARGET_OCCT_DIR OCCT_BUILD_TOOLKITS OCCT_COLLECT_SOURCE_DIR OCCT_INSTALL_DIR_PREFIX)
d94d80e5 228 set (OCCT_USED_PACKAGES)
94829f84 229
f2e9c853 230 # consider patched header.in template
231 set (TEMPLATE_HEADER_PATH "${CMAKE_SOURCE_DIR}/adm/templates/header.in")
109aa56e 232 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/header.in")
233 set (TEMPLATE_HEADER_PATH "${BUILD_PATCH}/adm/templates/header.in")
f2e9c853 234 endif()
235
236 set (ROOT_OCCT_DIR ${CMAKE_SOURCE_DIR})
237
316d77d9 238 foreach (OCCT_USED_TOOLKIT ${OCCT_BUILD_TOOLKITS})
94829f84 239 # append all required package folders
d94d80e5 240 set (OCCT_TOOLKIT_PACKAGES)
109aa56e 241 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
242 file (STRINGS "${BUILD_PATCH}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
14bbbdcb 243 elseif (EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_USED_TOOLKIT}/PACKAGES")
244 file (STRINGS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
94829f84 245 endif()
246
d94d80e5 247 list (APPEND OCCT_USED_PACKAGES ${OCCT_TOOLKIT_PACKAGES})
94829f84 248 endforeach()
249
d94d80e5 250 list (REMOVE_DUPLICATES OCCT_USED_PACKAGES)
f2e9c853 251
d94d80e5 252 set (OCCT_HEADER_FILES_COMPLETE)
253 set (OCCT_HEADER_FILE_NAMES_NOT_IN_FILES)
254 set (OCCT_HEADER_FILE_WITH_PROPER_NAMES)
e713baee 255
256 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 257 message (STATUS "Info: \(${CURRENT_TIME}\) Compare FILES with files in package directories...")
e713baee 258
d94d80e5 259 foreach (OCCT_PACKAGE ${OCCT_USED_PACKAGES})
f1d057b7 260 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES")
261 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
14bbbdcb 262 elseif (EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES")
263 file (STRINGS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
f1d057b7 264 else()
14bbbdcb 265 message (WARNING "FILES has not been found in ${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}")
f1d057b7 266 continue()
267 endif()
f2e9c853 268
f1d057b7 269 list (LENGTH OCCT_ALL_FILE_NAMES ALL_FILES_NB)
270 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" )
d94d80e5 271
f1d057b7 272 # emit warnings if there is unprocessed headers
14bbbdcb 273 file (GLOB OCCT_ALL_FILES_IN_DIR "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/*.*")
f1d057b7 274 file (GLOB OCCT_ALL_FILES_IN_PATCH_DIR "${BUILD_PATCH}/src/${OCCT_PACKAGE}/*.*")
d94d80e5 275
f1d057b7 276 # use patched header files
277 foreach (OCCT_FILE_IN_PATCH_DIR ${OCCT_ALL_FILES_IN_PATCH_DIR})
278 get_filename_component (OCCT_FILE_IN_PATCH_DIR_NAME ${OCCT_FILE_IN_PATCH_DIR} NAME)
14bbbdcb 279 list (REMOVE_ITEM OCCT_ALL_FILES_IN_DIR "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/${OCCT_FILE_IN_PATCH_DIR_NAME}")
f1d057b7 280 list (APPEND OCCT_ALL_FILES_IN_DIR "${OCCT_FILE_IN_PATCH_DIR}")
281 endforeach()
e713baee 282
f1d057b7 283 foreach (OCCT_FILE_IN_DIR ${OCCT_ALL_FILES_IN_DIR})
284 get_filename_component (OCCT_FILE_IN_DIR_NAME ${OCCT_FILE_IN_DIR} NAME)
e713baee 285
f1d057b7 286 set (OCCT_FILE_IN_DIR_STATUS OFF)
e713baee 287
f1d057b7 288 if (${ALL_FILES_NB} LESS 0)
289 break()
290 endif()
e713baee 291
f1d057b7 292 foreach (FILE_INDEX RANGE ${ALL_FILES_NB})
293 list (GET OCCT_ALL_FILE_NAMES ${FILE_INDEX} OCCT_FILE_NAME)
e713baee 294
ee5befae 295 string (REGEX REPLACE "[^:]+:+" "" OCCT_FILE_NAME "${OCCT_FILE_NAME}")
296
f1d057b7 297 if ("${OCCT_FILE_IN_DIR_NAME}" STREQUAL "${OCCT_FILE_NAME}")
298 set (OCCT_FILE_IN_DIR_STATUS ON)
e713baee 299
e713baee 300 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
301 if (IS_HEADER_FOUND)
f1d057b7 302 list (APPEND OCCT_HEADER_FILES_COMPLETE ${OCCT_FILE_IN_DIR})
303
304 # collect header files with name that does not contain its package one
305 string (FIND "${OCCT_FILE_NAME}" "${OCCT_PACKAGE}_" FOUND_INDEX)
306 if (NOT ${FOUND_INDEX} EQUAL 0)
307 list (APPEND OCCT_HEADER_FILE_WITH_PROPER_NAMES "${OCCT_FILE_NAME}")
308 endif()
e713baee 309 endif()
f1d057b7 310
311 # remove found element from list
312 list (REMOVE_AT OCCT_ALL_FILE_NAMES ${FILE_INDEX})
313 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" ) # decrement number
314
315 break()
d94d80e5 316 endif()
e713baee 317 endforeach()
f1d057b7 318
319 if (NOT OCCT_FILE_IN_DIR_STATUS)
14bbbdcb 320 message (STATUS "Warning. File ${OCCT_FILE_IN_DIR} is not listed in ${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES")
f1d057b7 321
322 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
323 if (IS_HEADER_FOUND)
324 list (APPEND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${OCCT_FILE_NAME})
325 endif()
326 endif()
327 endforeach()
d94d80e5 328 endforeach()
329
330 # create new file including found header
e713baee 331 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 332 message (STATUS "Info: \(${CURRENT_TIME}\) Create header-links in inc folder...")
e713baee 333
d94d80e5 334 foreach (OCCT_HEADER_FILE ${OCCT_HEADER_FILES_COMPLETE})
335 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
ee5befae 336 set (OCCT_HEADER_FILE_CONTENT "#include \"${OCCT_HEADER_FILE}\"")
14bbbdcb 337 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/${OCCT_INSTALL_DIR_PREFIX}/${HEADER_FILE_NAME}" @ONLY)
d94d80e5 338 endforeach()
339
14bbbdcb 340 install (FILES ${OCCT_HEADER_FILES_COMPLETE} DESTINATION "${INSTALL_DIR}/${OCCT_INSTALL_DIR_PREFIX}")
d94d80e5 341
342 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 343 message (STATUS "Info: \(${CURRENT_TIME}\) Checking headers in inc folder...")
d94d80e5 344
0cb512c0 345 file (GLOB OCCT_HEADER_FILES_OLD "${ROOT_TARGET_OCCT_DIR}/${OCCT_INSTALL_DIR_PREFIX}/*")
d94d80e5 346 foreach (OCCT_HEADER_FILE_OLD ${OCCT_HEADER_FILES_OLD})
347 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE_OLD} NAME)
348 string (REGEX MATCH "^[a-zA-Z0-9]+" PACKAGE_NAME "${HEADER_FILE_NAME}")
349
350 list (FIND OCCT_USED_PACKAGES ${PACKAGE_NAME} IS_HEADER_FOUND)
351 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
14bbbdcb 352 if (NOT EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${PACKAGE_NAME}/${HEADER_FILE_NAME}")
d94d80e5 353 message (STATUS "Warning. ${OCCT_HEADER_FILE_OLD} is not presented in the sources and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
354 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
355 else()
356 list (FIND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${PACKAGE_NAME} IS_HEADER_FOUND)
357 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
358 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")
359 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
360 endif()
361 endif()
362 else()
363 set (IS_HEADER_FOUND -1)
364 if (NOT "${OCCT_HEADER_FILE_WITH_PROPER_NAMES}" STREQUAL "")
365 list (FIND OCCT_HEADER_FILE_WITH_PROPER_NAMES ${HEADER_FILE_NAME} IS_HEADER_FOUND)
366 endif()
367
368 if (${IS_HEADER_FOUND} EQUAL -1)
369 message (STATUS "Warning. \(${PACKAGE_NAME}\) ${OCCT_HEADER_FILE_OLD} is not used and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
370 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
371 endif()
f2e9c853 372 endif()
94829f84 373 endforeach()
374endmacro()
375
19286d7c 376macro (OCCT_COPY_FILE_OR_DIR BEING_COPIED_OBJECT DESTINATION_PATH)
377 # first of all, copy original files
f2e9c853 378 if (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}")
379 file (COPY "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
380 endif()
19286d7c 381
109aa56e 382 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_COPIED_OBJECT}")
19286d7c 383 # secondly, rewrite original files with patched ones
109aa56e 384 file (COPY "${BUILD_PATCH}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 385 endif()
386endmacro()
387
388macro (OCCT_CONFIGURE BEING_CONGIRUGED_FILE FINAL_NAME)
109aa56e 389 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
390 configure_file("${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
19286d7c 391 else()
392 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
393 endif()
394endmacro()
395
f2e9c853 396macro (OCCT_ADD_SUBDIRECTORY BEING_ADDED_DIRECTORY)
109aa56e 397 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
398 add_subdirectory(${BUILD_PATCH}/${BEING_ADDED_DIRECTORY})
f2e9c853 399 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
400 add_subdirectory (${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY})
401 else()
402 message (STATUS "${BEING_ADDED_DIRECTORY} directory is not included")
403 endif()
404endmacro()
405
19286d7c 406function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
407 set (${USE_PRODUCT} OFF PARENT_SCOPE)
408
316d77d9 409 if (NOT BUILD_TOOLKITS)
19286d7c 410 message(STATUS "Warning: the list of being used toolkits is empty")
411 else()
316d77d9 412 foreach (USED_TOOLKIT ${BUILD_TOOLKITS})
109aa56e 413 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB")
414 file (READ "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
19286d7c 415 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
416 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
417 endif()
418
419 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
420
421 if (DOES_FILE_CONTAIN)
422 set (${USE_PRODUCT} ON PARENT_SCOPE)
423 break()
424 endif()
425 endforeach()
426 endif()
427endfunction()
428
429function (FILE_TO_LIST FILE_NAME FILE_CONTENT)
430 set (LOCAL_FILE_CONTENT)
109aa56e 431 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${FILE_NAME}")
432 file (STRINGS "${BUILD_PATCH}/${FILE_NAME}" LOCAL_FILE_CONTENT)
19286d7c 433 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${FILE_NAME}")
434 file (STRINGS "${CMAKE_SOURCE_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
435 endif()
436
437 set (${FILE_CONTENT} ${LOCAL_FILE_CONTENT} PARENT_SCOPE)
438endfunction()
439
440# Function to determine if TOOLKIT is OCCT toolkit
441function (IS_OCCT_TOOLKIT TOOLKIT_NAME MODULES IS_TOOLKIT_FOUND)
442 set (${IS_TOOLKIT_FOUND} OFF PARENT_SCOPE)
443 foreach (MODULE ${${MODULES}})
444 set (TOOLKITS ${${MODULE}_TOOLKITS})
445 list (FIND TOOLKITS ${TOOLKIT_NAME} FOUND)
446
447 if (NOT ${FOUND} EQUAL -1)
448 set (${IS_TOOLKIT_FOUND} ON PARENT_SCOPE)
449 endif()
450 endforeach(MODULE)
451endfunction()
452
453# TOOLKIT_DEPS is defined with dependencies from file src/TOOLKIT_NAME/EXTERNLIB.
454# CSF_ variables are ignored
455function (OCCT_TOOLKIT_DEP TOOLKIT_NAME TOOLKIT_DEPS)
456 FILE_TO_LIST ("src/${TOOLKIT_NAME}/EXTERNLIB" FILE_CONTENT)
457
458 #list (APPEND LOCAL_TOOLKIT_DEPS ${TOOLKIT_NAME})
459 set (LOCAL_TOOLKIT_DEPS)
460 foreach (FILE_CONTENT_LINE ${FILE_CONTENT})
461 string (REGEX MATCH "^TK" TK_FOUND ${FILE_CONTENT_LINE})
4fecc365 462 if ("x${FILE_CONTENT_LINE}" STREQUAL "xDRAWEXE" OR NOT "${TK_FOUND}" STREQUAL "")
19286d7c 463 list (APPEND LOCAL_TOOLKIT_DEPS ${FILE_CONTENT_LINE})
464 endif()
465 endforeach()
466
467 set (${TOOLKIT_DEPS} ${LOCAL_TOOLKIT_DEPS} PARENT_SCOPE)
468endfunction()
469
470# TOOLKIT_FULL_DEPS is defined with complete dependencies (all levels)
471function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS)
472 # first level dependencies are stored in LOCAL_TOOLKIT_FULL_DEPS
473 OCCT_TOOLKIT_DEP (${TOOLKIT_NAME} LOCAL_TOOLKIT_FULL_DEPS)
474
475 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
476 set (LIST_INDEX 0)
477 while (LIST_INDEX LESS LIST_LENGTH)
478 list (GET LOCAL_TOOLKIT_FULL_DEPS ${LIST_INDEX} CURRENT_TOOLKIT)
479 OCCT_TOOLKIT_DEP (${CURRENT_TOOLKIT} CURRENT_TOOLKIT_DEPS)
480
481 # append toolkits are not contained
482 foreach (CURRENT_TOOLKIT_DEP ${CURRENT_TOOLKIT_DEPS})
483 set (CURRENT_TOOLKIT_DEP_FOUND OFF)
484 foreach (LOCAL_TOOLKIT_FULL_DEP ${LOCAL_TOOLKIT_FULL_DEPS})
485 if ("${CURRENT_TOOLKIT_DEP}" STREQUAL "${LOCAL_TOOLKIT_FULL_DEP}")
486 set (CURRENT_TOOLKIT_DEP_FOUND ON)
487 break()
488 endif()
489 endforeach()
490 if ("${CURRENT_TOOLKIT_DEP_FOUND}" STREQUAL "OFF")
491 list (APPEND LOCAL_TOOLKIT_FULL_DEPS ${CURRENT_TOOLKIT_DEP})
492 endif()
493 endforeach()
494
495 # increment the list index
496 MATH(EXPR LIST_INDEX "${LIST_INDEX}+1")
497
498 # calculate new length
499 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
500 endwhile()
501
502 set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE)
503endfunction()
504
505# Function to get list of modules and toolkits from file adm/MODULES.
506# Creates list <$MODULE_LIST> to store list of MODULES and
507# <NAME_OF_MODULE>_TOOLKITS foreach module to store its toolkits.
508function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST)
509 FILE_TO_LIST ("adm/MODULES" FILE_CONTENT)
510
511 foreach (CONTENT_LINE ${FILE_CONTENT})
512 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
513 list (GET CONTENT_LINE 0 MODULE_NAME)
514 list (REMOVE_AT CONTENT_LINE 0)
515 list (APPEND ${MODULE_LIST} ${MODULE_NAME})
516 # (!) REMOVE THE LINE BELOW (implicit variables)
517 set (${MODULE_NAME}_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE)
518 endforeach()
519
520 set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE)
521endfunction()
522
14bbbdcb 523# Function to get list of tools and toolkits from file adm/TOOLS.
524# Creates list <$TOOL_LIST> to store list of TOOLS and
525# <NAME_OF_TOOL>_TOOLKITS foreach tool to store its toolkits.
526function (OCCT_TOOLS_AND_TOOLKITS TOOL_LIST)
527 FILE_TO_LIST ("adm/TOOLS" FILE_CONTENT)
528
529 foreach (CONTENT_LINE ${FILE_CONTENT})
530 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
531 list (GET CONTENT_LINE 0 TOOL_NAME)
532 list (REMOVE_AT CONTENT_LINE 0)
533 list (APPEND ${TOOL_LIST} ${TOOL_NAME})
534 # (!) REMOVE THE LINE BELOW (implicit variables)
535 set (${TOOL_NAME}_TOOL_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE)
536 endforeach()
537
538 set (${TOOL_LIST} ${${TOOL_LIST}} PARENT_SCOPE)
539endfunction()
540
096ef695 541# Returns OCC version string from file Standard_Version.hxx (if available)
542function (OCC_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT)
adc33035 543
096ef695 544 set (OCC_VERSION_MAJOR 7)
545 set (OCC_VERSION_MINOR 0)
546 set (OCC_VERSION_MAINTENANCE 0)
547 set (OCC_VERSION_DEVELOPMENT dev)
548 set (OCC_VERSION_COMPLETE "7.0.0")
549
adc33035 550 set (STANDARD_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/Standard/Standard_Version.hxx")
096ef695 551 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
552 set (STANDARD_VERSION_FILE "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
553 endif()
554
adc33035 555 if (EXISTS "${STANDARD_VERSION_FILE}")
096ef695 556 foreach (SOUGHT_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE)
adc33035 557 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
096ef695 558 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*([^ ]+).*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
adc33035 559 endforeach()
560
096ef695 561 foreach (SOUGHT_VERSION OCC_VERSION_DEVELOPMENT OCC_VERSION_COMPLETE)
562 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
563 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*\"([^ ]+)\".*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
564 endforeach()
565 endif()
566
567 set (OCC_VERSION_MAJOR "${OCC_VERSION_MAJOR}" PARENT_SCOPE)
568 set (OCC_VERSION_MINOR "${OCC_VERSION_MINOR}" PARENT_SCOPE)
569 set (OCC_VERSION_MAINTENANCE "${OCC_VERSION_MAINTENANCE}" PARENT_SCOPE)
570 set (OCC_VERSION_DEVELOPMENT "${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
571
572 if (OCC_VERSION_DEVELOPMENT AND OCC_VERSION_COMPLETE)
573 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
574 else()
575 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}" PARENT_SCOPE)
adc33035 576 endif()
adc33035 577endfunction()
578
e713baee 579macro (CHECK_PATH_FOR_CONSISTENCY THE_ROOT_PATH_NAME THE_BEING_CHECKED_PATH_NAME THE_VAR_TYPE THE_MESSAGE_OF_BEING_CHECKED_PATH)
580
581 set (THE_ROOT_PATH "${${THE_ROOT_PATH_NAME}}")
582 set (THE_BEING_CHECKED_PATH "${${THE_BEING_CHECKED_PATH_NAME}}")
583
584 if (THE_BEING_CHECKED_PATH OR EXISTS "${THE_BEING_CHECKED_PATH}")
585 get_filename_component (THE_ROOT_PATH_ABS "${THE_ROOT_PATH}" ABSOLUTE)
586 get_filename_component (THE_BEING_CHECKED_PATH_ABS "${THE_BEING_CHECKED_PATH}" ABSOLUTE)
587
588 string (REGEX MATCH "${THE_ROOT_PATH_ABS}" DOES_PATH_CONTAIN "${THE_BEING_CHECKED_PATH_ABS}")
589
590 if (NOT DOES_PATH_CONTAIN) # if cmake found the being checked path at different place from THE_ROOT_PATH_ABS
591 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
592 endif()
593 else()
594 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
595 endif()
596
597endmacro()
ada9ef40 598
599# Adds OCCT_INSTALL_BIN_LETTER variable ("" for Release, "d" for Debug and
600# "i" for RelWithDebInfo) in OpenCASCADETargets-*.cmake files during
601# installation process.
602# This and the following macros are used to overcome limitation of CMake
603# prior to version 3.3 not supporting per-configuration install paths
604# for install target files (see https://cmake.org/Bug/view.php?id=14317)
605macro (OCCT_UPDATE_TARGET_FILE)
606 if (NOT SINGLE_GENERATOR)
607 OCCT_INSERT_CODE_FOR_TARGET ()
608 endif()
609
610 install (CODE
611 "cmake_policy(PUSH)
612 cmake_policy(SET CMP0007 NEW)
613 string (TOLOWER \"\${CMAKE_INSTALL_CONFIG_NAME}\" CMAKE_INSTALL_CONFIG_NAME_LOWERCASE)
614 file (GLOB ALL_OCCT_TARGET_FILES \"${INSTALL_DIR}/${INSTALL_DIR_CMAKE}/OpenCASCADE*Targets-\${CMAKE_INSTALL_CONFIG_NAME_LOWERCASE}.cmake\")
615 foreach(TARGET_FILENAME \${ALL_OCCT_TARGET_FILES})
616 file (STRINGS \"\${TARGET_FILENAME}\" TARGET_FILE_CONTENT)
617 file (REMOVE \"\${TARGET_FILENAME}\")
618 foreach (line IN LISTS TARGET_FILE_CONTENT)
619 string (REGEX REPLACE \"[\\\\]?[\\\$]{OCCT_INSTALL_BIN_LETTER}\" \"\${OCCT_INSTALL_BIN_LETTER}\" line \"\${line}\")
620 file (APPEND \"\${TARGET_FILENAME}\" \"\${line}\\n\")
621 endforeach()
622 endforeach()
623 cmake_policy(POP)")
624endmacro()
625
626macro (OCCT_INSERT_CODE_FOR_TARGET)
627 install(CODE "if (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$\")
628 set (OCCT_INSTALL_BIN_LETTER \"\")
629 elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ww][Ii][Tt][Hh][Dd][Ee][Bb][Ii][Nn][Ff][Oo])$\")
630 set (OCCT_INSTALL_BIN_LETTER \"i\")
631 elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
632 set (OCCT_INSTALL_BIN_LETTER \"d\")
633 endif()")
634endmacro()
46bd680a 635
636macro (OCCT_UPDATE_DRAW_DEFAULT_FILE)
637 install(CODE "cmake_policy(PUSH)
638 cmake_policy(SET CMP0007 NEW)
639 set (DRAW_DEFAULT_FILE_NAME \"${INSTALL_DIR}/${INSTALL_DIR_RESOURCE}/DrawResources/DrawPlugin\")
640 file (STRINGS \"\${DRAW_DEFAULT_FILE_NAME}\" DRAW_DEFAULT_CONTENT)
641 file (REMOVE \"\${DRAW_DEFAULT_FILE_NAME}\")
642 foreach (line IN LISTS DRAW_DEFAULT_CONTENT)
643 string (REGEX MATCH \": TK\([a-zA-Z]+\)$\" IS_TK_LINE \"\${line}\")
644 string (REGEX REPLACE \": TK\([a-zA-Z]+\)$\" \": TK\${CMAKE_MATCH_1}${BUILD_SHARED_LIBRARY_NAME_POSTFIX}\" line \"\${line}\")
645 file (APPEND \"\${DRAW_DEFAULT_FILE_NAME}\" \"\${line}\\n\")
646 endforeach()
647 cmake_policy(POP)")
648endmacro()
649
650macro (OCCT_CREATE_SYMLINK_TO_FILE LIBRARY_NAME LINK_NAME)
651 if (NOT WIN32)
652 install (CODE "if (EXISTS \"${LIBRARY_NAME}\")
653 execute_process (COMMAND ln -s \"${LIBRARY_NAME}\" \"${LINK_NAME}\")
654 endif()
655 ")
656 endif()
657endmacro()