0029056: Configuration - It is not possible to install VTK products
[occt.git] / adm / cmake / occt_toolkit_tool.cmake
1 # script for each OCCT tool toolkit
2
3 # Qt dependencies
4 OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro)
5
6 FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES)
7 include_directories("${PROJECT_INCLUDES}"
8                     "${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/tools")
9
10 FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
11 # parce PACKAGES file
12
13 if ("${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}")
18 else()
19   FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
20   set (PACKAGE_PREFIX_DIR "tools")
21 endif()
22
23
24 SET (RCC_FILES)
25 foreach (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)
33 endforeach()
34 #message("RCC_FILES for ${PROJECT_NAME} are ${RCC_FILES}")
35
36 set (PRECOMPILED_DEFS)
37
38 if (NOT BUILD_SHARED_LIBS)
39   list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
40 endif()
41
42 # Get all used packages from toolkit
43 foreach (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()
151 endforeach()
152 string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
153
154 set (USED_RCFILE "")
155 if (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()
163 endif()
164
165 set (CURRENT_MODULE)
166 foreach (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()
171 endforeach()
172
173 if (NOT SINGLE_GENERATOR)
174   OCCT_INSERT_CODE_FOR_TARGET ()
175 endif()
176
177 if ("${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}")
182 else()
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}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb
187              CONFIGURATIONS Debug RelWithDebInfo
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()
210 endif()
211
212 if (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()
220 endif()
221
222 get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
223 get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
224 get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
225
226 if (ANDROID)
227   # do not append version to the filename
228   set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
229 else()
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}")
233 endif()
234
235 set (USED_TOOLKITS_BY_CURRENT_PROJECT)
236 set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
237
238 # parce EXTERNLIB file
239 FILE_TO_LIST ("${PACKAGE_PREFIX_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
240 foreach (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       if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK)
249         OCCT_INSTALL_VTK(${USED_ITEM})
250       endif()
251     else()
252       string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
253       if ("${CSF_FOUND}" STREQUAL "")
254         message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
255       else() # get CSF_ value
256         set (CURRENT_CSF ${${USED_ITEM}})
257         if (NOT "x${CURRENT_CSF}" STREQUAL "x")
258           # prepare a list from a string with whitespaces
259           separate_arguments (CURRENT_CSF)
260           list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
261         endif()
262       endif()
263     endif()
264   endif()
265 endforeach()
266
267 if (APPLE)
268   list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
269   if (NOT ${IS_X11_FOUND} EQUAL -1)
270     find_package (X11 COMPONENTS X11 Xext Xmu Xi)
271     if (NOT X11_FOUND)
272       message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
273     endif()
274   endif()
275 endif()
276
277 # Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
278 # Add VTK_OPENGL2_BACKEND definition.
279 if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
280   add_definitions(-DVTK_OPENGL2_BACKEND)
281   foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
282     list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
283     if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
284       list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
285       if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
286         list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
287       endif()
288     endif()
289   endforeach()
290 endif()
291
292 if (BUILD_SHARED_LIBS)
293   target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
294 endif()
295
296 # Set Qt dependencies
297 target_link_libraries(${PROJECT_NAME} "${PROJECT_LIBRARIES}")
298
299 target_link_libraries(${PROJECT_NAME} debug "${PROJECT_LIBRARIES_DEBUG}")
300 target_link_libraries(${PROJECT_NAME} optimized "${PROJECT_LIBRARIES_RELEASE}")
301