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