0000670: Problem with the Print method.
[occt.git] / adm / cmake / occt_macros.cmake
CommitLineData
19286d7c 1#
2macro (OCCT_CHECK_AND_UNSET VARNAME)
3 if (DEFINED ${VARNAME})
4 unset (${VARNAME} CACHE)
5 endif()
6endmacro()
7
8macro (OCCT_CHECK_AND_UNSET_GROUP VARNAME)
9 OCCT_CHECK_AND_UNSET ("${VARNAME}_DIR")
10
11 OCCT_CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
12
13 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
14 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY_DIR")
15
16 if (WIN32)
17 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL")
18 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL_DIR")
19 endif()
20endmacro()
21
19286d7c 22# COMPILER_BITNESS variable
23macro (OCCT_MAKE_COMPILER_BITNESS)
24 math (EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
25endmacro()
26
27# OS_WITH_BIT
28macro (OCCT_MAKE_OS_WITH_BITNESS)
29
30 OCCT_MAKE_COMPILER_BITNESS()
31
32 if (WIN32)
33 set (OS_WITH_BIT "win${COMPILER_BITNESS}")
34 elseif(APPLE)
35 set (OS_WITH_BIT "mac${COMPILER_BITNESS}")
36 else()
37 set (OS_WITH_BIT "lin${COMPILER_BITNESS}")
38 endif()
39endmacro()
40
41# COMPILER variable
42macro (OCCT_MAKE_COMPILER_SHORT_NAME)
43 if (MSVC)
44 if (MSVC70)
45 set (COMPILER vc7)
46 elseif (MSVC80)
47 set (COMPILER vc8)
48 elseif (MSVC90)
49 set (COMPILER vc9)
50 elseif (MSVC10)
51 set (COMPILER vc10)
52 elseif (MSVC11)
53 set (COMPILER vc11)
54 elseif (MSVC12)
55 set (COMPILER vc12)
63cf1bb6 56 elseif (MSVC14)
57 set (COMPILER vc14)
19286d7c 58 endif()
59 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
60 set (COMPILER gcc)
61 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
62 set (COMPILER gxx)
63 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
64 set (COMPILER clang)
65 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
66 set (COMPILER icc)
67 else()
68 set (COMPILER ${CMAKE_GENERATOR})
69 string (REGEX REPLACE " " "" COMPILER ${COMPILER})
70 endif()
71endmacro()
72
73function (SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
74 file (GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
75
76 foreach (ITEM ${SUB_ITEMS})
77 if (IS_DIRECTORY "${ITEM}")
78 get_filename_component (ITEM_NAME "${ITEM}" NAME)
79 list (APPEND LOCAL_RESULT "${ITEM_NAME}")
80 endif()
81 endforeach()
82 set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
83endfunction()
84
f2e9c853 85function (OCCT_ORIGIN_AND_PATCHED_FILES RELATIVE_PATH SEARCH_TEMPLATE RESULT)
86
87 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}")
88 file (GLOB FOUND_FILES "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
89 endif()
90
91 file (GLOB ORIGIN_FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_PATH}/${SEARCH_TEMPLATE}")
92 foreach (ORIGIN_FILE ${ORIGIN_FILES})
93 # check for existence of patched version of current file
94 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}")
95 get_filename_component (ORIGIN_FILE_NAME "${ORIGIN_FILE}" NAME)
96 if (EXISTS "${APPLY_OCCT_PATCH_DIR}/${RELATIVE_PATH}/${ORIGIN_FILE_NAME}")
97 continue()
98 endif()
99 endif()
100
101 # append origin version if patched one is not found
102 list (APPEND FOUND_FILES ${ORIGIN_FILE})
103 endforeach()
104
105 set (${RESULT} ${FOUND_FILES} PARENT_SCOPE)
106endfunction()
107
19286d7c 108function (FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
109 OCCT_MAKE_COMPILER_SHORT_NAME()
110 OCCT_MAKE_COMPILER_BITNESS()
111
112 string (TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME)
113
82f443b6 114 list (APPEND SEARCH_TEMPLATES "^${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
115 list (APPEND SEARCH_TEMPLATES "^${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
116 list (APPEND SEARCH_TEMPLATES "^${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
117 list (APPEND SEARCH_TEMPLATES "^${lower_PRODUCT_NAME}.*[0-9.]+")
118 list (APPEND SEARCH_TEMPLATES "^${lower_PRODUCT_NAME}")
19286d7c 119 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
120 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
121 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
122 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
123 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
124
125 SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
126
127 foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
128 if (LOCAL_RESULT)
129 BREAK()
130 endif()
131
132 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
133 string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
134
135 string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
136 if (DUMMY_VAR)
137 list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
138 endif()
139 endforeach()
140 endforeach()
141
142 if (LOCAL_RESULT)
143 list (LENGTH "${LOCAL_RESULT}" LOC_LEN)
144 math (EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
145 list (GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
146 set (${RESULT} ${DUMMY} PARENT_SCOPE)
147 endif()
148endfunction()
149
150macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
316d77d9 151 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
152 if (IS_DIRECTORY "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
19286d7c 153 # first of all, install original files
154 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
155
156 # secondly, rewrite original files with patched ones
316d77d9 157 install (DIRECTORY "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 158 else()
316d77d9 159 install (FILES "${APPLY_OCCT_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 160 endif()
161 else()
162 if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
163 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
164 else()
165 install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
166 endif()
167 endif()
168endmacro()
169
316d77d9 170macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE BUILD_NAME INSTALL_NAME DESTINATION_PATH)
171 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
172 configure_file("${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 173 else()
316d77d9 174 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${BUILD_NAME}" @ONLY)
19286d7c 175 endif()
176
316d77d9 177 install(FILES "${OCCT_BINARY_DIR}/${BUILD_NAME}" DESTINATION "${DESTINATION_PATH}" RENAME ${INSTALL_NAME})
19286d7c 178endmacro()
179
f2e9c853 180macro (COLLECT_AND_INSTALL_OCCT_HEADER_FILES ROOT_TARGET_OCCT_DIR OCCT_BUILD_TOOLKITS)
94829f84 181 set (OCCT_SOURCE_DIRS)
182
f2e9c853 183 # consider patched header.in template
184 set (TEMPLATE_HEADER_PATH "${CMAKE_SOURCE_DIR}/adm/templates/header.in")
185 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/header.in")
186 set (TEMPLATE_HEADER_PATH "${APPLY_OCCT_PATCH_DIR}/adm/templates/header.in")
187 endif()
188
189 set (ROOT_OCCT_DIR ${CMAKE_SOURCE_DIR})
190
316d77d9 191 foreach (OCCT_USED_TOOLKIT ${OCCT_BUILD_TOOLKITS})
94829f84 192 # append parent folder
193 list (APPEND OCCT_SOURCE_DIRS ${OCCT_USED_TOOLKIT})
194
195 # append all required package folders
196 set (OCCT_USED_TOOLKIT_DEPS)
f2e9c853 197 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
198 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_USED_TOOLKIT_DEPS)
199 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES")
200 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_USED_TOOLKIT}/PACKAGES" OCCT_USED_TOOLKIT_DEPS)
94829f84 201 endif()
202
203 foreach (OCCT_USED_TOOLKIT_DEP ${OCCT_USED_TOOLKIT_DEPS})
204 list (APPEND OCCT_SOURCE_DIRS ${OCCT_USED_TOOLKIT_DEP})
205 endforeach()
206 endforeach()
207
208 foreach (OCCT_SOURCE_DIR ${OCCT_SOURCE_DIRS})
f2e9c853 209 # get all header files from each src folder
210 file (GLOB OCCT_HEADER_FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_SOURCE_DIR}/*.[hgl]xx" "${CMAKE_SOURCE_DIR}/src/${OCCT_SOURCE_DIR}/*.h")
94829f84 211 install (FILES ${OCCT_HEADER_FILES} DESTINATION "${INSTALL_DIR}/inc")
212
213 # create new file including found header
214 foreach (OCCT_HEADER_FILE ${OCCT_HEADER_FILES})
215 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
216 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/inc/${HEADER_FILE_NAME}" @ONLY)
217 endforeach()
f2e9c853 218
219 # consider pathed the source files
220 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_SOURCE_DIR}")
221 file (GLOB PATCHED_OCCT_HEADER_FILES "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_SOURCE_DIR}/*.[hgl]xx" "${APPLY_OCCT_PATCH_DIR}/src/${OCCT_SOURCE_DIR}/*.h")
222 install (FILES ${PATCHED_OCCT_HEADER_FILES} DESTINATION "${INSTALL_DIR}/inc")
223
224 # create new patched file including found header
225 foreach (OCCT_HEADER_FILE ${PATCHED_OCCT_HEADER_FILES})
226 get_filename_component (HEADER_FILE_NAME ${OCCT_HEADER_FILE} NAME)
227 configure_file ("${TEMPLATE_HEADER_PATH}" "${ROOT_TARGET_OCCT_DIR}/inc/${HEADER_FILE_NAME}" @ONLY)
228 endforeach()
229 endif()
94829f84 230 endforeach()
231endmacro()
232
19286d7c 233macro (OCCT_COPY_FILE_OR_DIR BEING_COPIED_OBJECT DESTINATION_PATH)
234 # first of all, copy original files
f2e9c853 235 if (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}")
236 file (COPY "${CMAKE_SOURCE_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
237 endif()
19286d7c 238
316d77d9 239 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_COPIED_OBJECT}")
19286d7c 240 # secondly, rewrite original files with patched ones
316d77d9 241 file (COPY "${APPLY_OCCT_PATCH_DIR}/${BEING_COPIED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
19286d7c 242 endif()
243endmacro()
244
245macro (OCCT_CONFIGURE BEING_CONGIRUGED_FILE FINAL_NAME)
316d77d9 246 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
247 configure_file("${APPLY_OCCT_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
19286d7c 248 else()
249 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
250 endif()
251endmacro()
252
f2e9c853 253macro (OCCT_ADD_SUBDIRECTORY BEING_ADDED_DIRECTORY)
254 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
255 add_subdirectory(${APPLY_OCCT_PATCH_DIR}/${BEING_ADDED_DIRECTORY})
256 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY}/CMakeLists.txt")
257 add_subdirectory (${CMAKE_SOURCE_DIR}/${BEING_ADDED_DIRECTORY})
258 else()
259 message (STATUS "${BEING_ADDED_DIRECTORY} directory is not included")
260 endif()
261endmacro()
262
19286d7c 263function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
264 set (${USE_PRODUCT} OFF PARENT_SCOPE)
265
316d77d9 266 if (NOT BUILD_TOOLKITS)
19286d7c 267 message(STATUS "Warning: the list of being used toolkits is empty")
268 else()
316d77d9 269 foreach (USED_TOOLKIT ${BUILD_TOOLKITS})
270 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
271 file (READ "${APPLY_OCCT_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
19286d7c 272 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
273 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
274 endif()
275
276 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
277
278 if (DOES_FILE_CONTAIN)
279 set (${USE_PRODUCT} ON PARENT_SCOPE)
280 break()
281 endif()
282 endforeach()
283 endif()
284endfunction()
285
286function (FILE_TO_LIST FILE_NAME FILE_CONTENT)
287 set (LOCAL_FILE_CONTENT)
316d77d9 288 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/${FILE_NAME}")
289 file (STRINGS "${APPLY_OCCT_PATCH_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
19286d7c 290 elseif (EXISTS "${CMAKE_SOURCE_DIR}/${FILE_NAME}")
291 file (STRINGS "${CMAKE_SOURCE_DIR}/${FILE_NAME}" LOCAL_FILE_CONTENT)
292 endif()
293
294 set (${FILE_CONTENT} ${LOCAL_FILE_CONTENT} PARENT_SCOPE)
295endfunction()
296
297# Function to determine if TOOLKIT is OCCT toolkit
298function (IS_OCCT_TOOLKIT TOOLKIT_NAME MODULES IS_TOOLKIT_FOUND)
299 set (${IS_TOOLKIT_FOUND} OFF PARENT_SCOPE)
300 foreach (MODULE ${${MODULES}})
301 set (TOOLKITS ${${MODULE}_TOOLKITS})
302 list (FIND TOOLKITS ${TOOLKIT_NAME} FOUND)
303
304 if (NOT ${FOUND} EQUAL -1)
305 set (${IS_TOOLKIT_FOUND} ON PARENT_SCOPE)
306 endif()
307 endforeach(MODULE)
308endfunction()
309
310# TOOLKIT_DEPS is defined with dependencies from file src/TOOLKIT_NAME/EXTERNLIB.
311# CSF_ variables are ignored
312function (OCCT_TOOLKIT_DEP TOOLKIT_NAME TOOLKIT_DEPS)
313 FILE_TO_LIST ("src/${TOOLKIT_NAME}/EXTERNLIB" FILE_CONTENT)
314
315 #list (APPEND LOCAL_TOOLKIT_DEPS ${TOOLKIT_NAME})
316 set (LOCAL_TOOLKIT_DEPS)
317 foreach (FILE_CONTENT_LINE ${FILE_CONTENT})
318 string (REGEX MATCH "^TK" TK_FOUND ${FILE_CONTENT_LINE})
319 if ("${FILE_CONTENT_LINE}" STREQUAL "DRAWEXE" OR NOT "${TK_FOUND}" STREQUAL "")
320 list (APPEND LOCAL_TOOLKIT_DEPS ${FILE_CONTENT_LINE})
321 endif()
322 endforeach()
323
324 set (${TOOLKIT_DEPS} ${LOCAL_TOOLKIT_DEPS} PARENT_SCOPE)
325endfunction()
326
327# TOOLKIT_FULL_DEPS is defined with complete dependencies (all levels)
328function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS)
329 # first level dependencies are stored in LOCAL_TOOLKIT_FULL_DEPS
330 OCCT_TOOLKIT_DEP (${TOOLKIT_NAME} LOCAL_TOOLKIT_FULL_DEPS)
331
332 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
333 set (LIST_INDEX 0)
334 while (LIST_INDEX LESS LIST_LENGTH)
335 list (GET LOCAL_TOOLKIT_FULL_DEPS ${LIST_INDEX} CURRENT_TOOLKIT)
336 OCCT_TOOLKIT_DEP (${CURRENT_TOOLKIT} CURRENT_TOOLKIT_DEPS)
337
338 # append toolkits are not contained
339 foreach (CURRENT_TOOLKIT_DEP ${CURRENT_TOOLKIT_DEPS})
340 set (CURRENT_TOOLKIT_DEP_FOUND OFF)
341 foreach (LOCAL_TOOLKIT_FULL_DEP ${LOCAL_TOOLKIT_FULL_DEPS})
342 if ("${CURRENT_TOOLKIT_DEP}" STREQUAL "${LOCAL_TOOLKIT_FULL_DEP}")
343 set (CURRENT_TOOLKIT_DEP_FOUND ON)
344 break()
345 endif()
346 endforeach()
347 if ("${CURRENT_TOOLKIT_DEP_FOUND}" STREQUAL "OFF")
348 list (APPEND LOCAL_TOOLKIT_FULL_DEPS ${CURRENT_TOOLKIT_DEP})
349 endif()
350 endforeach()
351
352 # increment the list index
353 MATH(EXPR LIST_INDEX "${LIST_INDEX}+1")
354
355 # calculate new length
356 list (LENGTH LOCAL_TOOLKIT_FULL_DEPS LIST_LENGTH)
357 endwhile()
358
359 set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE)
360endfunction()
361
362# Function to get list of modules and toolkits from file adm/MODULES.
363# Creates list <$MODULE_LIST> to store list of MODULES and
364# <NAME_OF_MODULE>_TOOLKITS foreach module to store its toolkits.
365function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST)
366 FILE_TO_LIST ("adm/MODULES" FILE_CONTENT)
367
368 foreach (CONTENT_LINE ${FILE_CONTENT})
369 string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE})
370 list (GET CONTENT_LINE 0 MODULE_NAME)
371 list (REMOVE_AT CONTENT_LINE 0)
372 list (APPEND ${MODULE_LIST} ${MODULE_NAME})
373 # (!) REMOVE THE LINE BELOW (implicit variables)
374 set (${MODULE_NAME}_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE)
375 endforeach()
376
377 set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE)
378endfunction()
379
adc33035 380# Returns OCCT version string from file Standard_Version.hxx (if available)
381function (OCCT_VERSION OCCT_VERSION_VAR)
382 set (OCC_VERSION_COMPLETE "7.1.0")
383 set (OCC_VERSION_DEVELOPMENT "")
384
385 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}")
386
387 set (STANDARD_VERSION_FILE "${CMAKE_SOURCE_DIR}/src/Standard/Standard_Version.hxx")
388 if (EXISTS "${STANDARD_VERSION_FILE}")
389 foreach (SOUGHT_VERSION OCC_VERSION_COMPLETE OCC_VERSION_DEVELOPMENT)
390 file (STRINGS "${STANDARD_VERSION_FILE}" ${SOUGHT_VERSION} REGEX "^#define ${SOUGHT_VERSION} .*")
391 string (REGEX REPLACE ".*${SOUGHT_VERSION} .*\"([^ ]+)\".*" "\\1" ${SOUGHT_VERSION} "${${SOUGHT_VERSION}}" )
392 endforeach()
393
394 if (NOT "${OCC_VERSION_DEVELOPMENT}" STREQUAL "")
395 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}.${OCC_VERSION_DEVELOPMENT}")
396 else()
397 set (OCCT_VERSION_LOCALVAR "${OCC_VERSION_COMPLETE}")
398 endif()
399 endif()
400
401 set (${OCCT_VERSION_VAR} "${OCCT_VERSION_LOCALVAR}" PARENT_SCOPE)
402endfunction()
403