Update of tests data base for reproduced issues
[occt.git] / adm / cmake / occt_toolkit.cmake
CommitLineData
316d77d9 1# script for each OCCT toolkit
2
fb3267c7 3# parce PACKAGES file
4if ("${PROJECT_NAME}" STREQUAL DRAWEXE)
5 set (USED_PACKAGES DRAWEXE)
6else()
7 FILE_TO_LIST ("src/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
8endif()
9
10set (PRECOMPILED_DEFS)
11
d5265175 12if (NOT BUILD_SHARED_LIBS)
13 list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
14endif()
15
316d77d9 16# Get all used packages from toolkit
fb3267c7 17foreach (OCCT_PACKAGE ${USED_PACKAGES})
18
19 # TKService contains platform-dependent packages: Xw and WNT
20 if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT"))
e713baee 21 # do nothing
22 else()
316d77d9 23
e713baee 24 if (WIN32)
25 list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL")
26 endif()
316d77d9 27
e713baee 28 set (SOURCE_FILES)
29 set (HEADER_FILES)
30
31 # Generate Flex and Bison files
109aa56e 32 if (${BUILD_YACCLEX})
e713baee 33
34 # flex files
35 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
36 list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
37
38 # bison files
39 OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
40 list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
41
42 if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
43
44 list (SORT SOURCE_FILES_FLEX)
45 list (SORT SOURCE_FILES_BISON)
46
47 math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
48 foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
49
50 list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
51 get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
52
53 list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
54 get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
55
56 string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
57
58 if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
59 set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c)
60 set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c)
61 BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
62 FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}")
63 ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
64
65 list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
66 endif()
67 endforeach()
68 endif()
69 endif()
316d77d9 70
e713baee 71 # header files
109aa56e 72 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES")
73 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
74 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
75 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 76
109aa56e 77 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
e713baee 78 if(APPLE)
109aa56e 79 file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
e713baee 80 endif()
81 else()
82 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
83 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
84 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
316d77d9 85
e713baee 86 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
87 if(APPLE)
88 file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
89 endif()
316d77d9 90 endif()
e713baee 91
92 list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
93 list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
f2e9c853 94 if(APPLE)
e713baee 95 list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
f2e9c853 96 endif()
f2e9c853 97
e713baee 98 foreach(HEADER_FILE ${HEADER_FILES})
109aa56e 99 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
100 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
101 list (APPEND USED_INCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
102 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
e713baee 103 else()
104 list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
105 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}")
106 endif()
107 endforeach()
108
109 foreach(SOURCE_FILE ${SOURCE_FILES})
109aa56e 110 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
111 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
112 list (APPEND USED_SRCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
113 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
e713baee 114 else()
115 list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
116 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}")
117 endif()
118 endforeach()
316d77d9 119 endif()
316d77d9 120endforeach()
f2e9c853 121string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
122
dfadf641 123set (USED_RCFILE "")
124if (MSVC)
125 set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc")
126
127 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in")
128 configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
129 else()
130 configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
131 endif()
132endif()
133
ada9ef40 134set (CURRENT_MODULE)
135foreach (OCCT_MODULE ${OCCT_MODULES})
136 list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
137 if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
138 set (CURRENT_MODULE ${OCCT_MODULE})
139 endif()
140endforeach()
141
142if (NOT SINGLE_GENERATOR)
143 OCCT_INSERT_CODE_FOR_TARGET ()
144endif()
145
fb3267c7 146if ("${PROJECT_NAME}" STREQUAL "DRAWEXE")
dfadf641 147 add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
fb3267c7 148
ada9ef40 149 install (TARGETS ${PROJECT_NAME}
d26375e2 150 DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
fb3267c7 151else()
dfadf641 152 add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE})
fb3267c7 153
ada9ef40 154 if (MSVC)
155 install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bind/${PROJECT_NAME}.pdb
fb3267c7 156 CONFIGURATIONS Debug
d26375e2 157 DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
fb3267c7 158 endif()
46bd680a 159
160 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
161 set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
162 set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
163 endif()
164
ada9ef40 165 install (TARGETS ${PROJECT_NAME}
166 EXPORT OpenCASCADE${CURRENT_MODULE}Targets
167 RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
168 ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
169 LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
46bd680a 170
171 if (NOT WIN32)
172 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
173 set (LINK_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}")
174 set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
175 OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
176 endif()
177 endif()
fb3267c7 178endif()
179
fb3267c7 180if (CURRENT_MODULE)
096ef695 181 set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Modules/${CURRENT_MODULE}")
ada9ef40 182 set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
09eca2b5 183 if (APPLE)
184 if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
185 set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
186 endif()
187 endif()
fb3267c7 188endif()
316d77d9 189
096ef695 190get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
191get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
192get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
193
41c012f0 194if (ANDROID)
195 # do not append version to the filename
196 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
197else()
198 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
199 SOVERSION "${OCC_VERSION_MAJOR}"
200 VERSION "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
201endif()
fb3267c7 202
203set (USED_TOOLKITS_BY_CURRENT_PROJECT)
204set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
205
206# parce EXTERNLIB file
207FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
208foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
a6874708 209 string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM})
210 if (NOT COMMENT_FOUND)
211 string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
212 string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM})
213
214 if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
215 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
216 else()
217 string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
218 if ("${CSF_FOUND}" STREQUAL "")
219 message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
220 else() # get CSF_ value
221 set (CURRENT_CSF ${${USED_ITEM}})
a20cce39 222 if (NOT "x${CURRENT_CSF}" STREQUAL "x")
4fecc365 223 set (LIBRARY_FROM_CACHE 0)
a6874708 224 separate_arguments (CURRENT_CSF)
4fecc365 225 foreach (CSF_LIBRARY ${CURRENT_CSF})
226 string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY)
227 string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}")
228 string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}")
229 get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES)
230 string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}")
231 foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES})
232 set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}})
233 string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE)
234
235 if (EXISTS "${CURRENT_CACHE_LIBRARY}" AND NOT IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}")
236 string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}")
237 string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}")
238 string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}")
239 if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR
240 "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR
241 NOT "x${IS_ENDING}" STREQUAL "x" OR
242 NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x")
243 list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${CURRENT_CACHE_LIBRARY}")
244 set (LIBRARY_FROM_CACHE 1)
245 endif()
246 endif()
247 endforeach()
248 endforeach()
249
250 if (NOT ${LIBRARY_FROM_CACHE})
251 # prepare a list from a string with whitespaces
252 separate_arguments (CURRENT_CSF)
253 list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
254 endif()
a6874708 255 endif()
fb3267c7 256 endif()
316d77d9 257 endif()
258 endif()
fb3267c7 259endforeach()
316d77d9 260
e713baee 261if (APPLE)
262 list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
263 if (NOT ${IS_X11_FOUND} EQUAL -1)
264 find_package (X11 COMPONENTS X11 Xext Xmu Xi)
265 if (NOT X11_FOUND)
a6874708 266 message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
e713baee 267 endif()
268 endif()
269endif()
270
88d533be 271# Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
272# Add VTK_OPENGL2_BACKEND definition.
273if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
274 add_definitions(-DVTK_OPENGL2_BACKEND)
275 foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
276 list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
277 if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
278 list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
279 if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
280 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
281 endif()
282 endif()
283 endforeach()
284endif()
285
3321f684 286if (BUILD_SHARED_LIBS)
287 target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
288endif()
896faa72 289
290# use Cotire to accelerate build via usage of precompiled headers
291if (BUILD_USE_PCH)
292 if (WIN32)
293 # prevent definition of min and max macros through inclusion of Windows.h
294 # (for cotire builds)
295 add_definitions("-DNOMINMAX")
296 # avoid warnings on deprecated names from standard C library (see strsafe.h)
297 add_definitions("-DSTRSAFE_NO_DEPRECATE")
298 # avoid "std::Equal1" warning in QANCollection_Stl.cxx in debug mode
299 # suggesting using msvc "Checked Iterators"
300 add_definitions("-D_SCL_SECURE_NO_WARNINGS")
301 endif()
302
303 # Exclude system-provided glext.h.
304 # These macros are already defined within OpenGl_GlFunctions.hxx,
305 # however we have to duplicate them here for building TKOpenGl with PCH.
306 add_definitions("-DGL_GLEXT_LEGACY")
307 add_definitions("-DGLX_GLXEXT_LEGACY")
308
309 # workaround for old gcc
310 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
311 add_definitions("-D__STDC_FORMAT_MACROS")
312 endif()
313
314 # unity builds are not used since they do not add speed but cause conflicts
315 # in TKV3d
316 set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
317
318 cotire(${PROJECT_NAME})
319endif()