0029580: Regression: invalid result of BOP Fuse
[occt.git] / adm / cmake / occt_toolkit_tool.cmake
CommitLineData
14bbbdcb 1# script for each OCCT tool toolkit
2
3# Qt dependencies
4f4b8935 4OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro)
14bbbdcb 5
4f4b8935 6FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES)
14bbbdcb 7include_directories("${PROJECT_INCLUDES}"
8 "${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/tools")
9
10FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
11# parce PACKAGES file
12
13if ("${PROJECT_NAME}" STREQUAL TInspectorEXE)
14 set (USED_PACKAGES ${PROJECT_NAME})
15 set (PACKAGE_PREFIX_DIR "samples/tools")
16 include_directories("${PROJECT_INCLUDES}"
17 "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${PROJECT_NAME}")
18else()
19 FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
20 set (PACKAGE_PREFIX_DIR "tools")
21endif()
22
23
24SET (RCC_FILES)
25foreach (OCCT_PACKAGE ${USED_PACKAGES})
14bbbdcb 26 #message("Dir is ${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${OCCT_PACKAGE}.qrc")
27 FIND_AND_WRAP_RESOURCE_FILE("${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${OCCT_PACKAGE}.qrc" RCC_FILES)
28endforeach()
29#message("RCC_FILES for ${PROJECT_NAME} are ${RCC_FILES}")
30
31set (PRECOMPILED_DEFS)
32
33if (NOT BUILD_SHARED_LIBS)
34 list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
77cd443b 35 if (WIN32)
68df8478 36 list (APPEND PRECOMPILED_DEFS "-DOCCT_STATIC_BUILD")
77cd443b 37 endif()
14bbbdcb 38endif()
39
40# Get all used packages from toolkit
41foreach (OCCT_PACKAGE ${USED_PACKAGES})
42
43 ADD_DEFINITIONS(-D${OCCT_PACKAGE}_EXPORTS)
44
45 # TKService contains platform-dependent packages: Xw and WNT
46 if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT"))
47 # do nothing
48 else()
49
68df8478 50# if (WIN32)
51# list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL")
52# endif()
14bbbdcb 53
54 set (SOURCE_FILES)
55 set (HEADER_FILES)
56
57 # Generate Flex and Bison files
58 if (${BUILD_YACCLEX})
59
60 # flex files
61 OCCT_ORIGIN_AND_PATCHED_FILES ("tools/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
62 list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
63
64 # bison files
65 OCCT_ORIGIN_AND_PATCHED_FILES ("tools/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
66 list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
67
68 if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
69
70 list (SORT SOURCE_FILES_FLEX)
71 list (SORT SOURCE_FILES_BISON)
72
73 math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
74 foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
75
76 list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
77 get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
78
79 list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
80 get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
81
82 string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
83
84 if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
85 set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c)
86 set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c)
87 BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/tools/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
88 FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/tools/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}")
89 ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
90
91 list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
92 endif()
93 endforeach()
94 endif()
95 endif()
96
97 # header files
98 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES")
99 file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
100 file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
101 file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
102
103 file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
104 if(APPLE)
105 file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
106 endif()
107 else()
108 file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h")
109 file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
110 file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
111
112 file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
113 if(APPLE)
114 file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
115 endif()
116 endif()
117
118
119
120 list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
121 list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
122 if(APPLE)
123 list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
124 endif()
125
126 foreach(HEADER_FILE ${HEADER_FILES})
127 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}")
128 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}")
129 list (APPEND USED_INCFILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}")
130 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}")
131 else()
132 list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
133 SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
134 endif()
135 endforeach()
136
137
138 foreach(SOURCE_FILE ${SOURCE_FILES})
139 if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}")
140 message (STATUS "Info: consider patched file: ${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}")
141 list (APPEND USED_SRCFILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}")
142 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}")
143 else()
144 list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
145 SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
146 endif()
147 endforeach()
148 endif()
149endforeach()
150string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
151
152set (USED_RCFILE "")
153if (MSVC)
154 set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc")
155
156 if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in")
157 configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
158 else()
159 configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
160 endif()
161endif()
162
163set (CURRENT_MODULE)
164foreach (OCCT_MODULE ${OCCT_TOOLS})
165 list (FIND ${OCCT_MODULE}_TOOL_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
166 if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
167 set (CURRENT_MODULE ${OCCT_MODULE})
168 endif()
169endforeach()
170
b1f350a2 171if (WIN32)
14bbbdcb 172 OCCT_INSERT_CODE_FOR_TARGET ()
173endif()
174
410dd2c9 175FIND_AND_WRAP_MOC_FILES("${USED_INCFILES}" "${PROJECT_NAME}_MOC_FILES")
176#message("MOC files: ${${PROJECT_NAME}_MOC_FILES}")
177
14bbbdcb 178if ("${PROJECT_NAME}" STREQUAL TInspectorEXE)
410dd2c9 179 add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RCC_FILES} ${${PROJECT_NAME}_MOC_FILES})
14bbbdcb 180
181 install (TARGETS ${PROJECT_NAME}
182 DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
183else()
410dd2c9 184 add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RCC_FILES} ${${PROJECT_NAME}_MOC_FILES})
14bbbdcb 185
186 if (MSVC)
956d6346 187 install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb
188 CONFIGURATIONS Debug RelWithDebInfo
14bbbdcb 189 DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
190 endif()
191
192 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
193 set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
194 set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
195 endif()
196
197 install (TARGETS ${PROJECT_NAME}
198 EXPORT OpenCASCADE${CURRENT_MODULE}Targets
199 RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
200 ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
201 LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
202
203
204 if (NOT WIN32)
205 if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
206 set (LINK_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}/tools")
207 set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}/tools")
208 OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
209 endif()
210 endif()
211endif()
212
213if (CURRENT_MODULE)
214 set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Tools/${CURRENT_MODULE}")
215 set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
216 if (APPLE)
217 if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
218 set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
219 endif()
220 endif()
221endif()
222
223get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
224get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
225get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
226
227if (ANDROID)
228 # do not append version to the filename
229 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
230else()
231 set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
232 SOVERSION "${OCC_VERSION_MAJOR}"
233 VERSION "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
234endif()
235
236set (USED_TOOLKITS_BY_CURRENT_PROJECT)
237set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
238
239# parce EXTERNLIB file
240FILE_TO_LIST ("${PACKAGE_PREFIX_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
241foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
242 string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM})
243 if (NOT COMMENT_FOUND)
244 string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
245 string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM})
246
247 if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
248 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
c22e576d 249 if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK)
250 OCCT_INSTALL_VTK(${USED_ITEM})
251 endif()
14bbbdcb 252 else()
253 string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
254 if ("${CSF_FOUND}" STREQUAL "")
255 message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
256 else() # get CSF_ value
257 set (CURRENT_CSF ${${USED_ITEM}})
258 if (NOT "x${CURRENT_CSF}" STREQUAL "x")
259 # prepare a list from a string with whitespaces
260 separate_arguments (CURRENT_CSF)
261 list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
262 endif()
263 endif()
264 endif()
265 endif()
266endforeach()
267
268if (APPLE)
269 list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
270 if (NOT ${IS_X11_FOUND} EQUAL -1)
271 find_package (X11 COMPONENTS X11 Xext Xmu Xi)
272 if (NOT X11_FOUND)
273 message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
274 endif()
275 endif()
276endif()
277
278# Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
279# Add VTK_OPENGL2_BACKEND definition.
280if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
281 add_definitions(-DVTK_OPENGL2_BACKEND)
282 foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
283 list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
284 if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
285 list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
286 if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
287 list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
288 endif()
289 endif()
290 endforeach()
291endif()
292
293if (BUILD_SHARED_LIBS)
294 target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
295endif()
296
297# Set Qt dependencies
298target_link_libraries(${PROJECT_NAME} "${PROJECT_LIBRARIES}")
299
300target_link_libraries(${PROJECT_NAME} debug "${PROJECT_LIBRARIES_DEBUG}")
301target_link_libraries(${PROJECT_NAME} optimized "${PROJECT_LIBRARIES_RELEASE}")
302