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