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