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