0030715: Configuration, CMake - error build with QTANGLE
[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)
5771d380 166 if ("${lower_PRODUCT_NAME}" STREQUAL "egl")
167 string (SUBSTRING "${lower_PRODUCT_NAME}" 1 -1 lower_PRODUCT_NAME)
168 list (APPEND SEARCH_TEMPLATES "[^gl]+${lower_PRODUCT_NAME}.*")
169 else()
170 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*${COMPILER}.*${COMPILER_BITNESS}")
171 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
172 list (APPEND SEARCH_TEMPLATES "^[a-zA-Z]*[0-9]*-${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
173 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+.*${COMPILER_BITNESS}")
174 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*.*${COMPILER_BITNESS}")
175 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*[0-9.]+")
176 list (APPEND SEARCH_TEMPLATES "^[^a-zA-Z]*${lower_PRODUCT_NAME}[^a-zA-Z]*")
177 endif()
19286d7c 178
179 SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
180
181 foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
182 if (LOCAL_RESULT)
183 BREAK()
184 endif()
185
186 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
187 string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
188
189 string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
190 if (DUMMY_VAR)
191 list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
192 endif()
193 endforeach()
194 endforeach()
195
196 if (LOCAL_RESULT)
e713baee 197 list (GET LOCAL_RESULT -1 DUMMY)
19286d7c 198 set (${RESULT} ${DUMMY} PARENT_SCOPE)
199 endif()
200endfunction()
201
202macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
109aa56e 203 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}")
204 if (IS_DIRECTORY "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}")
19286d7c 205 # first of all, install original files
206 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
207
208 # secondly, rewrite original files with patched ones
109aa56e 209 install (DIRECTORY "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 210 else()
109aa56e 211 install (FILES "${BUILD_PATCH}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 212 endif()
213 else()
214 if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
215 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
216 else()
217 install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
218 endif()
219 endif()
220endmacro()
221
316d77d9 222macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE BUILD_NAME INSTALL_NAME DESTINATION_PATH)
109aa56e 223 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
224 configure_file("${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 225 else()
316d77d9 226 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 227 endif()
228
316d77d9 229 install(FILES "${OCCT_BINARY_DIR}/${BUILD_NAME}" DESTINATION "${DESTINATION_PATH}" RENAME ${INSTALL_NAME})
19286d7c 230endmacro()
231
14bbbdcb 232macro (COLLECT_AND_INSTALL_OCCT_HEADER_FILES ROOT_TARGET_OCCT_DIR OCCT_BUILD_TOOLKITS OCCT_COLLECT_SOURCE_DIR OCCT_INSTALL_DIR_PREFIX)
d94d80e5 233 set (OCCT_USED_PACKAGES)
94829f84 234
f2e9c853 235 # consider patched header.in template
236 set (TEMPLATE_HEADER_PATH "${CMAKE_SOURCE_DIR}/adm/templates/header.in")
109aa56e 237 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/adm/templates/header.in")
238 set (TEMPLATE_HEADER_PATH "${BUILD_PATCH}/adm/templates/header.in")
f2e9c853 239 endif()
240
241 set (ROOT_OCCT_DIR ${CMAKE_SOURCE_DIR})
242
316d77d9 243 foreach (OCCT_USED_TOOLKIT ${OCCT_BUILD_TOOLKITS})
94829f84 244 # append all required package folders
d94d80e5 245 set (OCCT_TOOLKIT_PACKAGES)
109aa56e 246 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
247 file (STRINGS "${BUILD_PATCH}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
14bbbdcb 248 elseif (EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_USED_TOOLKIT}/PACKAGES")
249 file (STRINGS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_TOOLKIT_PACKAGES)
94829f84 250 endif()
251
d94d80e5 252 list (APPEND OCCT_USED_PACKAGES ${OCCT_TOOLKIT_PACKAGES})
94829f84 253 endforeach()
254
d94d80e5 255 list (REMOVE_DUPLICATES OCCT_USED_PACKAGES)
f2e9c853 256
d94d80e5 257 set (OCCT_HEADER_FILES_COMPLETE)
258 set (OCCT_HEADER_FILE_NAMES_NOT_IN_FILES)
259 set (OCCT_HEADER_FILE_WITH_PROPER_NAMES)
e713baee 260
261 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 262 message (STATUS "Info: \(${CURRENT_TIME}\) Compare FILES with files in package directories...")
e713baee 263
d94d80e5 264 foreach (OCCT_PACKAGE ${OCCT_USED_PACKAGES})
f1d057b7 265 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES")
266 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
14bbbdcb 267 elseif (EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES")
268 file (STRINGS "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES" OCCT_ALL_FILE_NAMES)
f1d057b7 269 else()
14bbbdcb 270 message (WARNING "FILES has not been found in ${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}")
f1d057b7 271 continue()
272 endif()
f2e9c853 273
f1d057b7 274 list (LENGTH OCCT_ALL_FILE_NAMES ALL_FILES_NB)
275 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" )
d94d80e5 276
f1d057b7 277 # emit warnings if there is unprocessed headers
14bbbdcb 278 file (GLOB OCCT_ALL_FILES_IN_DIR "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/*.*")
f1d057b7 279 file (GLOB OCCT_ALL_FILES_IN_PATCH_DIR "${BUILD_PATCH}/src/${OCCT_PACKAGE}/*.*")
d94d80e5 280
f1d057b7 281 # use patched header files
282 foreach (OCCT_FILE_IN_PATCH_DIR ${OCCT_ALL_FILES_IN_PATCH_DIR})
283 get_filename_component (OCCT_FILE_IN_PATCH_DIR_NAME ${OCCT_FILE_IN_PATCH_DIR} NAME)
14bbbdcb 284 list (REMOVE_ITEM OCCT_ALL_FILES_IN_DIR "${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/${OCCT_FILE_IN_PATCH_DIR_NAME}")
f1d057b7 285 list (APPEND OCCT_ALL_FILES_IN_DIR "${OCCT_FILE_IN_PATCH_DIR}")
286 endforeach()
e713baee 287
f1d057b7 288 foreach (OCCT_FILE_IN_DIR ${OCCT_ALL_FILES_IN_DIR})
289 get_filename_component (OCCT_FILE_IN_DIR_NAME ${OCCT_FILE_IN_DIR} NAME)
e713baee 290
f1d057b7 291 set (OCCT_FILE_IN_DIR_STATUS OFF)
e713baee 292
f1d057b7 293 if (${ALL_FILES_NB} LESS 0)
294 break()
295 endif()
e713baee 296
f1d057b7 297 foreach (FILE_INDEX RANGE ${ALL_FILES_NB})
298 list (GET OCCT_ALL_FILE_NAMES ${FILE_INDEX} OCCT_FILE_NAME)
e713baee 299
ee5befae 300 string (REGEX REPLACE "[^:]+:+" "" OCCT_FILE_NAME "${OCCT_FILE_NAME}")
301
f1d057b7 302 if ("${OCCT_FILE_IN_DIR_NAME}" STREQUAL "${OCCT_FILE_NAME}")
303 set (OCCT_FILE_IN_DIR_STATUS ON)
e713baee 304
e713baee 305 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
306 if (IS_HEADER_FOUND)
f1d057b7 307 list (APPEND OCCT_HEADER_FILES_COMPLETE ${OCCT_FILE_IN_DIR})
308
309 # collect header files with name that does not contain its package one
310 string (FIND "${OCCT_FILE_NAME}" "${OCCT_PACKAGE}_" FOUND_INDEX)
311 if (NOT ${FOUND_INDEX} EQUAL 0)
312 list (APPEND OCCT_HEADER_FILE_WITH_PROPER_NAMES "${OCCT_FILE_NAME}")
313 endif()
e713baee 314 endif()
f1d057b7 315
316 # remove found element from list
317 list (REMOVE_AT OCCT_ALL_FILE_NAMES ${FILE_INDEX})
318 math (EXPR ALL_FILES_NB "${ALL_FILES_NB} - 1" ) # decrement number
319
320 break()
d94d80e5 321 endif()
e713baee 322 endforeach()
f1d057b7 323
324 if (NOT OCCT_FILE_IN_DIR_STATUS)
14bbbdcb 325 message (STATUS "Warning. File ${OCCT_FILE_IN_DIR} is not listed in ${OCCT_COLLECT_SOURCE_DIR}/${OCCT_PACKAGE}/FILES")
f1d057b7 326
327 string (REGEX MATCH ".+\\.[hlg]xx|.+\\.h$" IS_HEADER_FOUND "${OCCT_FILE_NAME}")
328 if (IS_HEADER_FOUND)
329 list (APPEND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${OCCT_FILE_NAME})
330 endif()
331 endif()
332 endforeach()
d94d80e5 333 endforeach()
334
335 # create new file including found header
e713baee 336 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 337 message (STATUS "Info: \(${CURRENT_TIME}\) Create header-links in inc folder...")
e713baee 338
d94d80e5 339 foreach (OCCT_HEADER_FILE ${OCCT_HEADER_FILES_COMPLETE})
340 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
ee5befae 341 set (OCCT_HEADER_FILE_CONTENT "#include \"${OCCT_HEADER_FILE}\"")
14bbbdcb 342 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/${OCCT_INSTALL_DIR_PREFIX}/${HEADER_FILE_NAME}" @ONLY)
d94d80e5 343 endforeach()
344
14bbbdcb 345 install (FILES ${OCCT_HEADER_FILES_COMPLETE} DESTINATION "${INSTALL_DIR}/${OCCT_INSTALL_DIR_PREFIX}")
d94d80e5 346
347 string(TIMESTAMP CURRENT_TIME "%H:%M:%S")
a6874708 348 message (STATUS "Info: \(${CURRENT_TIME}\) Checking headers in inc folder...")
d94d80e5 349
0cb512c0 350 file (GLOB OCCT_HEADER_FILES_OLD "${ROOT_TARGET_OCCT_DIR}/${OCCT_INSTALL_DIR_PREFIX}/*")
d94d80e5 351 foreach (OCCT_HEADER_FILE_OLD ${OCCT_HEADER_FILES_OLD})
352 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE_OLD} NAME)
353 string (REGEX MATCH "^[a-zA-Z0-9]+" PACKAGE_NAME "${HEADER_FILE_NAME}")
354
355 list (FIND OCCT_USED_PACKAGES ${PACKAGE_NAME} IS_HEADER_FOUND)
356 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
14bbbdcb 357 if (NOT EXISTS "${OCCT_COLLECT_SOURCE_DIR}/${PACKAGE_NAME}/${HEADER_FILE_NAME}")
d94d80e5 358 message (STATUS "Warning. ${OCCT_HEADER_FILE_OLD} is not presented in the sources and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
359 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
360 else()
361 list (FIND OCCT_HEADER_FILE_NAMES_NOT_IN_FILES ${PACKAGE_NAME} IS_HEADER_FOUND)
362 if (NOT ${IS_HEADER_FOUND} EQUAL -1)
363 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")
364 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
365 endif()
366 endif()
367 else()
368 set (IS_HEADER_FOUND -1)
369 if (NOT "${OCCT_HEADER_FILE_WITH_PROPER_NAMES}" STREQUAL "")
370 list (FIND OCCT_HEADER_FILE_WITH_PROPER_NAMES ${HEADER_FILE_NAME} IS_HEADER_FOUND)
371 endif()
372
373 if (${IS_HEADER_FOUND} EQUAL -1)
374 message (STATUS "Warning. \(${PACKAGE_NAME}\) ${OCCT_HEADER_FILE_OLD} is not used and will be removed from ${ROOT_TARGET_OCCT_DIR}/inc")
375 file (REMOVE "${OCCT_HEADER_FILE_OLD}")
376 endif()
f2e9c853 377 endif()
94829f84 378 endforeach()
379endmacro()
380
19286d7c 381macro (OCCT_COPY_FILE_OR_DIR BEING_COPIED_OBJECT DESTINATION_PATH)
382 # first of all, copy original files
f2e9c853 383 if (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}")
384 file (COPY "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
385 endif()
19286d7c 386
109aa56e 387 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_COPIED_OBJECT}")
19286d7c 388 # secondly, rewrite original files with patched ones
109aa56e 389 file (COPY "${BUILD_PATCH}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 390 endif()
391endmacro()
392
393macro (OCCT_CONFIGURE BEING_CONGIRUGED_FILE FINAL_NAME)
109aa56e 394 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}")
395 configure_file("${BUILD_PATCH}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
19286d7c 396 else()
397 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
398 endif()
399endmacro()
400
f2e9c853 401macro (OCCT_ADD_SUBDIRECTORY BEING_ADDED_DIRECTORY)
109aa56e 402 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
403 add_subdirectory(${BUILD_PATCH}/${BEING_ADDED_DIRECTORY})
f2e9c853 404 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
405 add_subdirectory (${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY})
406 else()
407 message (STATUS "${BEING_ADDED_DIRECTORY} directory is not included")
408 endif()
409endmacro()
410
19286d7c 411function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
412 set (${USE_PRODUCT} OFF PARENT_SCOPE)
413
316d77d9 414 if (NOT BUILD_TOOLKITS)
19286d7c 415 message(STATUS "Warning: the list of being used toolkits is empty")
416 else()
316d77d9 417 foreach (USED_TOOLKIT ${BUILD_TOOLKITS})
109aa56e 418 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB")
419 file (READ "${BUILD_PATCH}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
19286d7c 420 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
421 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
422 endif()
423
424 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
425
426 if (DOES_FILE_CONTAIN)
427 set (${USE_PRODUCT} ON PARENT_SCOPE)
428 break()
429 endif()
430 endforeach()
431 endif()
432endfunction()
433
434function (FILE_TO_LIST FILE_NAME FILE_CONTENT)
435 set (LOCAL_FILE_CONTENT)
109aa56e 436 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${FILE_NAME}")
437 file (STRINGS "${BUILD_PATCH}/${FILE_NAME}" LOCAL_FILE_CONTENT)
19286d7c 438 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${FILE_NAME}")
439 file (STRINGS "${CMAKE_SOURCE_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
440 endif()
441
442 set (${FILE_CONTENT} ${LOCAL_FILE_CONTENT} PARENT_SCOPE)
443endfunction()
444
445# Function to determine if TOOLKIT is OCCT toolkit
446function (IS_OCCT_TOOLKIT TOOLKIT_NAME MODULES IS_TOOLKIT_FOUND)
447 set (${IS_TOOLKIT_FOUND} OFF PARENT_SCOPE)
448 foreach (MODULE ${${MODULES}})
449 set (TOOLKITS ${${MODULE}_TOOLKITS})
450 list (FIND TOOLKITS ${TOOLKIT_NAME} FOUND)
451
452 if (NOT ${FOUND} EQUAL -1)
453 set (${IS_TOOLKIT_FOUND} ON PARENT_SCOPE)
454 endif()
455 endforeach(MODULE)
456endfunction()
457
458# TOOLKIT_DEPS is defined with dependencies from file src/TOOLKIT_NAME/EXTERNLIB.
459# CSF_ variables are ignored
460function (OCCT_TOOLKIT_DEP TOOLKIT_NAME TOOLKIT_DEPS)
461 FILE_TO_LIST ("src/${TOOLKIT_NAME}/EXTERNLIB" FILE_CONTENT)
462
463 #list (APPEND LOCAL_TOOLKIT_DEPS ${TOOLKIT_NAME})
464 set (LOCAL_TOOLKIT_DEPS)
465 foreach (FILE_CONTENT_LINE ${FILE_CONTENT})
466 string (REGEX MATCH "^TK" TK_FOUND ${FILE_CONTENT_LINE})
4fecc365 467 if ("x${FILE_CONTENT_LINE}" STREQUAL "xDRAWEXE" OR NOT "${TK_FOUND}" STREQUAL "")
19286d7c 468 list (APPEND LOCAL_TOOLKIT_DEPS ${FILE_CONTENT_LINE})
469 endif()
470 endforeach()
471
472 set (${TOOLKIT_DEPS} ${LOCAL_TOOLKIT_DEPS} PARENT_SCOPE)
473endfunction()
474
475# TOOLKIT_FULL_DEPS is defined with complete dependencies (all levels)
476function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS)
477 # first level dependencies are stored in LOCAL_TOOLKIT_FULL_DEPS
478 OCCT_TOOLKIT_DEP (${TOOLKIT_NAME} LOCAL_TOOLKIT_FULL_DEPS)
479
480 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
481 set (LIST_INDEX 0)
482 while (LIST_INDEX LESS LIST_LENGTH)
483 list (GET LOCAL_TOOLKIT_FULL_DEPS ${LIST_INDEX} CURRENT_TOOLKIT)
484 OCCT_TOOLKIT_DEP (${CURRENT_TOOLKIT} CURRENT_TOOLKIT_DEPS)
485
486 # append toolkits are not contained
487 foreach (CURRENT_TOOLKIT_DEP ${CURRENT_TOOLKIT_DEPS})
488 set (CURRENT_TOOLKIT_DEP_FOUND OFF)
489 foreach (LOCAL_TOOLKIT_FULL_DEP ${LOCAL_TOOLKIT_FULL_DEPS})
490 if ("${CURRENT_TOOLKIT_DEP}" STREQUAL "${LOCAL_TOOLKIT_FULL_DEP}")
491 set (CURRENT_TOOLKIT_DEP_FOUND ON)
492 break()
493 endif()
494 endforeach()
495 if ("${CURRENT_TOOLKIT_DEP_FOUND}" STREQUAL "OFF")
496 list (APPEND LOCAL_TOOLKIT_FULL_DEPS ${CURRENT_TOOLKIT_DEP})
497 endif()
498 endforeach()
499
500 # increment the list index
501 MATH(EXPR LIST_INDEX "${LIST_INDEX}+1")
502
503 # calculate new length
504 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
505 endwhile()
506
507 set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE)
508endfunction()
509
1fa16152 510# Function to get list of modules/toolkits/samples from file adm/${FILE_NAME}.
19286d7c 511# Creates list <$MODULE_LIST> to store list of MODULES and
1fa16152 512# <NAME_OF_MODULE>_TOOLKITS foreach module to store its toolkits, where "TOOLKITS" is defined by TOOLKITS_NAME_SUFFIX.
513function (OCCT_MODULES_AND_TOOLKITS FILE_NAME TOOLKITS_NAME_SUFFIX MODULE_LIST)
514 FILE_TO_LIST ("adm/${FILE_NAME}" FILE_CONTENT)
19286d7c 515
516 foreach (CONTENT_LINE ${FILE_CONTENT})
517 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
518 list (GET CONTENT_LINE 0 MODULE_NAME)
519 list (REMOVE_AT CONTENT_LINE 0)
520 list (APPEND ${MODULE_LIST} ${MODULE_NAME})
521 # (!) REMOVE THE LINE BELOW (implicit variables)
1fa16152 522 set (${MODULE_NAME}_${TOOLKITS_NAME_SUFFIX} ${CONTENT_LINE} PARENT_SCOPE)
19286d7c 523 endforeach()
524
525 set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE)
526endfunction()
527
096ef695 528# Returns OCC version string from file Standard_Version.hxx (if available)
529function (OCC_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT)
adc33035 530
096ef695 531 set (OCC_VERSION_MAJOR 7)
532 set (OCC_VERSION_MINOR 0)
533 set (OCC_VERSION_MAINTENANCE 0)
534 set (OCC_VERSION_DEVELOPMENT dev)
535 set (OCC_VERSION_COMPLETE "7.0.0")
536
adc33035 537 set (STANDARD_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/Standard/Standard_Version.hxx")
096ef695 538 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
539 set (STANDARD_VERSION_FILE "${BUILD_PATCH}/src/Standard/Standard_Version.hxx")
540 endif()
541
adc33035 542 if (EXISTS "${STANDARD_VERSION_FILE}")
096ef695 543 foreach (SOUGHT_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE)
adc33035 544 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
096ef695 545 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*([^ ]+).*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
adc33035 546 endforeach()
547
096ef695 548 foreach (SOUGHT_VERSION OCC_VERSION_DEVELOPMENT OCC_VERSION_COMPLETE)
549 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
550 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*\"([^ ]+)\".*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
551 endforeach()
552 endif()
553
554 set (OCC_VERSION_MAJOR "${OCC_VERSION_MAJOR}" PARENT_SCOPE)
555 set (OCC_VERSION_MINOR "${OCC_VERSION_MINOR}" PARENT_SCOPE)
556 set (OCC_VERSION_MAINTENANCE "${OCC_VERSION_MAINTENANCE}" PARENT_SCOPE)
557 set (OCC_VERSION_DEVELOPMENT "${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
558
559 if (OCC_VERSION_DEVELOPMENT AND OCC_VERSION_COMPLETE)
560 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}" PARENT_SCOPE)
561 else()
562 set (OCC_VERSION_STRING_EXT "${OCC_VERSION_COMPLETE}" PARENT_SCOPE)
adc33035 563 endif()
adc33035 564endfunction()
565
e713baee 566macro (CHECK_PATH_FOR_CONSISTENCY THE_ROOT_PATH_NAME THE_BEING_CHECKED_PATH_NAME THE_VAR_TYPE THE_MESSAGE_OF_BEING_CHECKED_PATH)
567
568 set (THE_ROOT_PATH "${${THE_ROOT_PATH_NAME}}")
569 set (THE_BEING_CHECKED_PATH "${${THE_BEING_CHECKED_PATH_NAME}}")
570
571 if (THE_BEING_CHECKED_PATH OR EXISTS "${THE_BEING_CHECKED_PATH}")
572 get_filename_component (THE_ROOT_PATH_ABS "${THE_ROOT_PATH}" ABSOLUTE)
573 get_filename_component (THE_BEING_CHECKED_PATH_ABS "${THE_BEING_CHECKED_PATH}" ABSOLUTE)
574
575 string (REGEX MATCH "${THE_ROOT_PATH_ABS}" DOES_PATH_CONTAIN "${THE_BEING_CHECKED_PATH_ABS}")
576
577 if (NOT DOES_PATH_CONTAIN) # if cmake found the being checked path at different place from THE_ROOT_PATH_ABS
578 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
579 endif()
580 else()
581 set (${THE_BEING_CHECKED_PATH_NAME} "" CACHE ${THE_VAR_TYPE} "${THE_MESSAGE_OF_BEING_CHECKED_PATH}" FORCE)
582 endif()
583
584endmacro()
ada9ef40 585
586# Adds OCCT_INSTALL_BIN_LETTER variable ("" for Release, "d" for Debug and
587# "i" for RelWithDebInfo) in OpenCASCADETargets-*.cmake files during
588# installation process.
589# This and the following macros are used to overcome limitation of CMake
590# prior to version 3.3 not supporting per-configuration install paths
591# for install target files (see https://cmake.org/Bug/view.php?id=14317)
592macro (OCCT_UPDATE_TARGET_FILE)
6acbb1c6 593 if (MSVC)
ada9ef40 594 OCCT_INSERT_CODE_FOR_TARGET ()
595 endif()
596
597 install (CODE
598 "cmake_policy(PUSH)
599 cmake_policy(SET CMP0007 NEW)
600 string (TOLOWER \"\${CMAKE_INSTALL_CONFIG_NAME}\" CMAKE_INSTALL_CONFIG_NAME_LOWERCASE)
601 file (GLOB ALL_OCCT_TARGET_FILES \"${INSTALL_DIR}/${INSTALL_DIR_CMAKE}/OpenCASCADE*Targets-\${CMAKE_INSTALL_CONFIG_NAME_LOWERCASE}.cmake\")
602 foreach(TARGET_FILENAME \${ALL_OCCT_TARGET_FILES})
603 file (STRINGS \"\${TARGET_FILENAME}\" TARGET_FILE_CONTENT)
604 file (REMOVE \"\${TARGET_FILENAME}\")
605 foreach (line IN LISTS TARGET_FILE_CONTENT)
606 string (REGEX REPLACE \"[\\\\]?[\\\$]{OCCT_INSTALL_BIN_LETTER}\" \"\${OCCT_INSTALL_BIN_LETTER}\" line \"\${line}\")
607 file (APPEND \"\${TARGET_FILENAME}\" \"\${line}\\n\")
608 endforeach()
609 endforeach()
610 cmake_policy(POP)")
611endmacro()
612
613macro (OCCT_INSERT_CODE_FOR_TARGET)
614 install(CODE "if (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$\")
615 set (OCCT_INSTALL_BIN_LETTER \"\")
616 elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ww][Ii][Tt][Hh][Dd][Ee][Bb][Ii][Nn][Ff][Oo])$\")
617 set (OCCT_INSTALL_BIN_LETTER \"i\")
618 elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
619 set (OCCT_INSTALL_BIN_LETTER \"d\")
620 endif()")
621endmacro()
46bd680a 622
623macro (OCCT_UPDATE_DRAW_DEFAULT_FILE)
624 install(CODE "cmake_policy(PUSH)
625 cmake_policy(SET CMP0007 NEW)
626 set (DRAW_DEFAULT_FILE_NAME \"${INSTALL_DIR}/${INSTALL_DIR_RESOURCE}/DrawResources/DrawPlugin\")
627 file (STRINGS \"\${DRAW_DEFAULT_FILE_NAME}\" DRAW_DEFAULT_CONTENT)
628 file (REMOVE \"\${DRAW_DEFAULT_FILE_NAME}\")
629 foreach (line IN LISTS DRAW_DEFAULT_CONTENT)
630 string (REGEX MATCH \": TK\([a-zA-Z]+\)$\" IS_TK_LINE \"\${line}\")
631 string (REGEX REPLACE \": TK\([a-zA-Z]+\)$\" \": TK\${CMAKE_MATCH_1}${BUILD_SHARED_LIBRARY_NAME_POSTFIX}\" line \"\${line}\")
632 file (APPEND \"\${DRAW_DEFAULT_FILE_NAME}\" \"\${line}\\n\")
633 endforeach()
634 cmake_policy(POP)")
635endmacro()
636
637macro (OCCT_CREATE_SYMLINK_TO_FILE LIBRARY_NAME LINK_NAME)
638 if (NOT WIN32)
639 install (CODE "if (EXISTS \"${LIBRARY_NAME}\")
640 execute_process (COMMAND ln -s \"${LIBRARY_NAME}\" \"${LINK_NAME}\")
641 endif()
642 ")
643 endif()
644endmacro()