0024023: Revamp the OCCT Handle - non-cost reference cast
[occt.git] / adm / templates / occt_macros.cmake
CommitLineData
9f33b387 1#
2
3macro (OCCT_CHECK_AND_UNSET VARNAME)
4 if (DEFINED ${VARNAME})
5 unset (${VARNAME} CACHE)
6 endif()
7endmacro()
8
9macro (OCCT_CHECK_AND_UNSET_GROUP VARNAME)
10 OCCT_CHECK_AND_UNSET ("${VARNAME}_DIR")
11
12 OCCT_CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
13
14 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
15 OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY_DIR")
16
17 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL")
18 OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL_DIR")
19endmacro()
20
21# BUILD_POSTFIX, IS_BUILD_DEBUG variables
22macro (OCCT_MAKE_BUILD_POSTFIX)
23 if ("${BUILD_CONFIGURATION}" STREQUAL "Debug")
24 set (BUILD_POSTFIX "d")
25 set (IS_BUILD_DEBUG "")
26 else()
27 set (BUILD_POSTFIX "")
28 OCCT_CHECK_AND_UNSET (IS_BUILD_DEBUG)
29 endif()
30endmacro()
31
32# COMPILER_BITNESS variable
33macro (OCCT_MAKE_COMPILER_BITNESS)
34 math (EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
35endmacro()
36
37# OS_WITH_BIT
38macro (OCCT_MAKE_OS_WITH_BITNESS)
39
40 OCCT_MAKE_COMPILER_BITNESS()
41
42 if (WIN32)
43 set (OS_WITH_BIT "win${COMPILER_BITNESS}")
44 elseif(APPLE)
45 set (OS_WITH_BIT "mac${COMPILER_BITNESS}")
46 else()
47 set (OS_WITH_BIT "lin${COMPILER_BITNESS}")
48 endif()
49endmacro()
50
51# COMPILER variable
52macro (OCCT_MAKE_COMPILER_SHORT_NAME)
53 if (MSVC)
54 if (MSVC70)
55 set (COMPILER vc7)
56 elseif (MSVC80)
57 set (COMPILER vc8)
58 elseif (MSVC90)
59 set (COMPILER vc9)
60 elseif (MSVC10)
61 set (COMPILER vc10)
62 elseif (MSVC11)
63 set (COMPILER vc11)
64 elseif (MSVC12)
65 set (COMPILER vc12)
66 endif()
67 elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
68 set (COMPILER gcc)
69 elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
70 set (COMPILER gxx)
71 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
72 set (COMPILER clang)
73 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
74 set (COMPILER icc)
75 else()
76 set (COMPILER ${CMAKE_GENERATOR})
77 string (REGEX REPLACE " " "" COMPILER ${COMPILER})
78 endif()
79endmacro()
80
81function (SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
82 file (GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
83
84 foreach (ITEM ${SUB_ITEMS})
85 if (IS_DIRECTORY "${ITEM}")
86 get_filename_component (ITEM_NAME "${ITEM}" NAME)
87 list (APPEND LOCAL_RESULT "${ITEM_NAME}")
88 endif()
89 endforeach()
90 set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
91endfunction()
92
93function (FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
94 OCCT_MAKE_COMPILER_SHORT_NAME()
95 OCCT_MAKE_COMPILER_BITNESS()
96
97 string (TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME)
98
99 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
100 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
101 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
102 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
103 list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
104
105 SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
106
107 foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
108 if (LOCAL_RESULT)
109 BREAK()
110 endif()
111
112 foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
113 string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
114
115 string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
116 if (DUMMY_VAR)
117 list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
118 endif()
119 endforeach()
120 endforeach()
121
122 if (LOCAL_RESULT)
123 list (LENGTH "${LOCAL_RESULT}" LOC_LEN)
124 math (EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
125 list (GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
126 set (${RESULT} ${DUMMY} PARENT_SCOPE)
127 endif()
128endfunction()
129
130macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
131 if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
132 if (IS_DIRECTORY "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
133 # first of all, install original files
134 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
135
136 # secondly, rewrite original files with patched ones
137 install (DIRECTORY "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
138 else()
139 install (FILES "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
140 endif()
141 else()
142 if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
143 install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
144 else()
145 install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
146 endif()
147 endif()
148endmacro()
149
150macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE FINAL_NAME DESTINATION_PATH)
151 if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
152 configure_file("${BUILD_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
153 else()
154 configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
155 endif()
156
157 install(FILES "${OCCT_BINARY_DIR}/${FINAL_NAME}" DESTINATION "${DESTINATION_PATH}")
158endmacro()
159
160function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
161 set (${USE_PRODUCT} OFF PARENT_SCOPE)
162
163 if (NOT USED_TOOLKITS)
164 message(STATUS "Warning: the list of being used toolkits is empty")
165 else()
166 foreach (USED_TOOLKIT ${USED_TOOLKITS})
167 if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
168 file (READ "${BUILD_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
169 elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
170 file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
171 endif()
172
173 string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
174
175 if (DOES_FILE_CONTAIN)
176 set (${USE_PRODUCT} ON PARENT_SCOPE)
177 break()
178 endif()
179 endforeach()
180 endif()
181endfunction()
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201