0029571: Samples: build qt samples together with OCCT
[occt.git] / adm / cmake / occt_toolkit.cmake
1 # script for each OCCT toolkit
2
3 # filling some variables by default values(src) or using custom(tools, samples)
4 set (RELATIVE_SOURCES_DIR "${RELATIVE_DIR}")
5 if ("${RELATIVE_SOURCES_DIR}" STREQUAL "")
6   #if it is not defined, use default directory
7   set (RELATIVE_SOURCES_DIR "src")
8 endif()
9
10 set (OCC_MODULES_LIST "${MODULES_LIST}")
11 if ("${OCC_MODULES_LIST}" STREQUAL "")
12   set (OCC_MODULES_LIST ${OCCT_MODULES})
13 endif()
14
15 set (OCC_TARGET_FOLDER "${TARGET_FOLDER}")
16 if ("${OCC_TARGET_FOLDER}" STREQUAL "")
17   set (OCC_TARGET_FOLDER "Modules")
18 endif()
19
20 set (OCCT_TOOLKITS_NAME_SUFFIX "${TOOLKITS_NAME_SUFFIX}")
21 if ("${OCCT_TOOLKITS_NAME_SUFFIX}" STREQUAL "")
22   set (OCCT_TOOLKITS_NAME_SUFFIX "TOOLKITS")
23 endif()
24
25 # parce PACKAGES file
26 FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/PACKAGES" USED_PACKAGES)
27 if ("${USED_PACKAGES}" STREQUAL "")
28   set (USED_PACKAGES ${PROJECT_NAME})
29 endif()
30
31 if (USE_QT)
32   # Qt dependencies
33   OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro)
34   FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES)
35   include_directories("${PROJECT_INCLUDES}")
36 endif(USE_QT)
37
38 set (PRECOMPILED_DEFS)
39
40 if (NOT BUILD_SHARED_LIBS)
41   list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS")
42   if (WIN32)
43     list (APPEND PRECOMPILED_DEFS "-DOCCT_STATIC_BUILD")
44   endif()
45 endif()
46
47 # Get all used packages from toolkit
48 UNSET(RESOURCE_FILES)
49 foreach (OCCT_PACKAGE ${USED_PACKAGES})
50
51   #remove part after "/" in the OCCT_PACKAGE variable if exists
52   string (FIND "${OCCT_PACKAGE}" "/" _index)
53   if (_index GREATER -1)
54     math (EXPR _index "${_index}")
55     string (SUBSTRING "${OCCT_PACKAGE}" 0 ${_index} OCCT_PACKAGE_NAME)
56   else()
57     set (OCCT_PACKAGE_NAME "${OCCT_PACKAGE}")
58   endif()
59
60   # TKService contains platform-dependent packages: Xw and WNT
61   if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT"))
62     # do nothing
63   else()
64
65     if (WIN32)
66       list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE_NAME}_DLL")
67     endif()
68
69     set (SOURCE_FILES)
70     set (HEADER_FILES)
71
72     # Generate Flex and Bison files
73     if (${BUILD_YACCLEX})
74
75       # flex files
76       OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX)
77       list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN)
78
79       # bison files
80       OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON)
81       list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN)
82
83       if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0)
84       
85         list (SORT SOURCE_FILES_FLEX)
86         list (SORT SOURCE_FILES_BISON)
87
88         math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1")
89         foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN})
90
91           list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE)
92           get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE)
93
94           list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE)
95           get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE)
96           
97           string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL)
98
99           if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL})
100             set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c)
101             set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c)
102             BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}")
103             FLEX_TARGET  (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}")
104             ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME})
105            
106             list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE})
107           endif()
108         endforeach()
109       endif()
110     endif()
111
112     # header files
113     if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES")
114       file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M   REGEX ".+[.]h")
115       file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx")
116       file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx")
117
118       file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c")
119       if(APPLE)
120         file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm")
121       endif()
122     else()
123       file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES"     HEADER_FILES_M   REGEX ".+[.]h")
124       file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES"     HEADER_FILES_LXX REGEX ".+[.]lxx")
125       file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES"     HEADER_FILES_GXX REGEX ".+[.]gxx")
126
127       file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES"     SOURCE_FILES_C REGEX ".+[.]c")
128       if(APPLE)
129         file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES"   SOURCE_FILES_M REGEX ".+[.]mm")
130       endif()
131     endif()
132     
133     list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX})
134     list (APPEND SOURCE_FILES ${SOURCE_FILES_C})
135     if(APPLE)
136       list (APPEND SOURCE_FILES ${SOURCE_FILES_M})
137     endif()
138
139     foreach(HEADER_FILE ${HEADER_FILES})
140       if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
141         message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
142         list (APPEND USED_INCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
143         SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
144       else()
145         list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
146         SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}")
147       endif()
148     endforeach()
149
150     foreach(SOURCE_FILE ${SOURCE_FILES})
151       if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
152         message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
153         list (APPEND USED_SRCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
154         SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
155       else()
156         list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
157         SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}")
158       endif()
159     endforeach()
160
161     if (USE_QT)
162       FIND_AND_INSTALL_QT_RESOURCES (${OCCT_PACKAGE} RESOURCE_FILES)
163       #message("Qt Resource files are: ${QT_RESOURCE_FILES} in ${OCCT_PACKAGE}")
164     endif(USE_QT)
165
166     #message("Resource files are: ${RESOURCE_FILES} in ${OCCT_PACKAGE}")
167     foreach(RESOURCE_FILE ${RESOURCE_FILES})
168       SOURCE_GROUP ("Resource Files\\${OCCT_PACKAGE_NAME}" FILES "${RESOURCE_FILE}")
169     endforeach()
170   endif()
171 endforeach()
172 string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}")
173
174 set (USED_RCFILE "")
175 if (MSVC)
176   set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc")
177
178   if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in")
179     configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
180   else()
181     configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY)
182   endif()
183 endif()
184
185 set (CURRENT_MODULE)
186 foreach (OCCT_MODULE ${OCC_MODULES_LIST})
187   list (FIND ${OCCT_MODULE}_${OCCT_TOOLKITS_NAME_SUFFIX} ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT)
188
189   if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1)
190     set (CURRENT_MODULE ${OCCT_MODULE})
191   endif()
192 endforeach()
193
194 if (WIN32)
195   OCCT_INSERT_CODE_FOR_TARGET ()
196 endif()
197
198 if (USE_QT)
199   FIND_AND_WRAP_MOC_FILES("${USED_INCFILES}" "${PROJECT_NAME}_MOC_FILES")
200   #message("MOC files: ${${PROJECT_NAME}_MOC_FILES}")
201 endif (USE_QT)
202
203 if (EXECUTABLE_PROJECT)
204   add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES})
205
206   install (TARGETS ${PROJECT_NAME}
207            DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
208 else()
209   add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES})
210
211   if (MSVC)
212     install (FILES  ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb
213              CONFIGURATIONS Debug RelWithDebInfo
214              DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}")
215   endif()
216
217   if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
218     set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX})
219     set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
220   endif()
221
222   install (TARGETS ${PROJECT_NAME}
223            EXPORT OpenCASCADE${CURRENT_MODULE}Targets
224            RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}"
225            ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}"
226            LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}")
227
228   if (NOT WIN32)
229     if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "")
230       set (LINK_NAME    "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}")
231       set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
232       OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME})
233     endif()
234   endif()
235 endif()
236
237 if (CURRENT_MODULE)
238   set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "${OCC_TARGET_FOLDER}/${CURRENT_MODULE}")
239   set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}")
240   if (APPLE)
241     if (NOT "${INSTALL_NAME_DIR}" STREQUAL "")
242       set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}")
243     endif()
244   endif()
245 endif()
246
247 get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR)
248 get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR)
249 get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE)
250
251 if (ANDROID)
252   # do not append version to the filename
253   set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}")
254 else()
255   set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}"
256                                                     SOVERSION     "${OCC_VERSION_MAJOR}"
257                                                     VERSION       "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}")
258 endif()
259
260 set (USED_TOOLKITS_BY_CURRENT_PROJECT)
261 set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT)
262
263 # parce EXTERNLIB file
264 FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS)
265 foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
266   string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM})
267   if (NOT COMMENT_FOUND)
268     string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM})
269     string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM})
270     
271     if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "")
272       list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM})
273       if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK)
274         OCCT_INSTALL_VTK(${USED_ITEM})
275       endif()
276     else()
277       string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM})
278       if ("${CSF_FOUND}" STREQUAL "")
279         message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty")
280       else() # get CSF_ value
281         set (CURRENT_CSF ${${USED_ITEM}})
282         if (NOT "x${CURRENT_CSF}" STREQUAL "x")
283           set (LIBRARY_FROM_CACHE 0)
284           separate_arguments (CURRENT_CSF)
285           foreach (CSF_LIBRARY ${CURRENT_CSF})
286             string (TOLOWER "${CSF_LIBRARY}" CSF_LIBRARY)
287             string (REPLACE "+" "[+]" CSF_LIBRARY "${CSF_LIBRARY}")
288             string (REPLACE "." "" CSF_LIBRARY "${CSF_LIBRARY}")
289             get_cmake_property(ALL_CACHE_VARIABLES CACHE_VARIABLES)
290             string (REGEX MATCHALL "(^|;)3RDPARTY_[^;]+_LIBRARY[^;]*" ALL_CACHE_VARIABLES "${ALL_CACHE_VARIABLES}")
291             foreach (CACHE_VARIABLE ${ALL_CACHE_VARIABLES})
292               set (CURRENT_CACHE_LIBRARY ${${CACHE_VARIABLE}})
293               string (TOLOWER "${CACHE_VARIABLE}" CACHE_VARIABLE)
294
295               if (EXISTS "${CURRENT_CACHE_LIBRARY}" AND NOT IS_DIRECTORY "${CURRENT_CACHE_LIBRARY}")
296                 string (REGEX MATCH "_${CSF_LIBRARY}$" IS_ENDING "${CACHE_VARIABLE}")
297                 string (REGEX MATCH "^([a-z]+)" CSF_WO_VERSION "${CSF_LIBRARY}")
298                 string (REGEX MATCH "_${CSF_WO_VERSION}$" IS_ENDING_WO_VERSION "${CACHE_VARIABLE}")
299                 if ("3rdparty_${CSF_LIBRARY}_library" STREQUAL "${CACHE_VARIABLE}" OR
300                     "3rdparty_${CSF_WO_VERSION}_library" STREQUAL "${CACHE_VARIABLE}" OR
301                     NOT "x${IS_ENDING}" STREQUAL "x" OR
302                     NOT "x${IS_ENDING_WO_VERSION}" STREQUAL "x")
303                   list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT "${CURRENT_CACHE_LIBRARY}")
304                   set (LIBRARY_FROM_CACHE 1)
305                 endif()
306               endif()
307             endforeach()
308           endforeach()
309
310           if (NOT ${LIBRARY_FROM_CACHE})
311             # prepare a list from a string with whitespaces
312             separate_arguments (CURRENT_CSF)
313             list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF})
314           endif()
315         endif()
316       endif()
317     endif()
318   endif()
319 endforeach()
320
321 if (APPLE)
322   list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND)
323   if (NOT ${IS_X11_FOUND} EQUAL -1)
324     find_package (X11 COMPONENTS X11 Xext Xmu Xi)
325     if (NOT X11_FOUND)
326       message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org")
327     endif()
328   endif()
329 endif()
330
331 # Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used.
332 # Add VTK_OPENGL2_BACKEND definition.
333 if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2")
334   add_definitions(-DVTK_OPENGL2_BACKEND)
335   foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL)
336     list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND)
337     if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1)
338       list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY})
339       if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL)
340         list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2)
341         if(VTK_MAJOR_VERSION GREATER 6)
342           list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingGL2PSOpenGL2)
343         endif()
344       endif()
345     endif()
346   endforeach()
347 else()
348   if(VTK_MAJOR_VERSION EQUAL 6 AND VTK_MINOR_VERSION GREATER 2 OR VTK_MAJOR_VERSION GREATER 6)
349     list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL" IS_VTK_RENDER_FREETYPE_FOUND)
350     if (NOT ${IS_VTK_RENDER_FREETYPE_FOUND} EQUAL -1)
351       list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT "vtkRenderingFreeTypeOpenGL")
352     endif()
353   endif()
354 endif()
355
356 if (BUILD_SHARED_LIBS)
357   target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT})
358 endif()
359
360 if (USE_QT)
361   foreach (PROJECT_LIBRARY_DEBUG ${PROJECT_LIBRARIES_DEBUG})
362     target_link_libraries (${PROJECT_NAME} debug ${PROJECT_LIBRARY_DEBUG})
363   endforeach()
364   foreach (PROJECT_LIBRARY_RELEASE ${PROJECT_LIBRARIES_RELEASE})
365     target_link_libraries (${PROJECT_NAME} optimized ${PROJECT_LIBRARY_RELEASE})
366   endforeach()
367 endif()
368
369 # suppress deprecation warnings inside OCCT itself for old gcc versions with unavailable Standard_DISABLE_DEPRECATION_WARNINGS
370 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
371   if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6.0)
372     add_definitions("-DOCCT_NO_DEPRECATED")
373     message (STATUS "Warning: internal deprecation warnings by Standard_DEPRECATED have been disabled due to old gcc version being used")
374   endif()
375 endif()
376
377 # use Cotire to accelerate build via usage of precompiled headers
378 if (BUILD_USE_PCH)
379   if (WIN32)
380     # prevent definition of min and max macros through inclusion of Windows.h
381     # (for cotire builds)
382     add_definitions("-DNOMINMAX")
383     # avoid warnings on deprecated names from standard C library (see strsafe.h)
384     add_definitions("-DSTRSAFE_NO_DEPRECATE")
385     # avoid "std::Equal1" warning in QANCollection_Stl.cxx in debug mode
386     # suggesting using msvc "Checked Iterators"
387     add_definitions("-D_SCL_SECURE_NO_WARNINGS")
388   endif()
389
390   # Exclude system-provided glext.h.
391   # These macros are already defined within OpenGl_GlFunctions.hxx,
392   # however we have to duplicate them here for building TKOpenGl with PCH.
393   add_definitions("-DGL_GLEXT_LEGACY")
394   add_definitions("-DGLX_GLXEXT_LEGACY")
395
396   # workaround for old gcc
397   if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
398     add_definitions("-D__STDC_CONSTANT_MACROS")
399     add_definitions("-D__STDC_FORMAT_MACROS")
400   endif()
401
402   # unity builds are not used since they do not add speed but cause conflicts
403   # in TKV3d
404   set_target_properties(${PROJECT_NAME} PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
405
406   cotire(${PROJECT_NAME})
407 endif()