93c06352290c0e98ae5ad011e1b8f0ecbf0dbd31
[occt.git] / adm / templates / vtk.cmake
1 # vtk
2
3 if (NOT DEFINED INSTALL_VTK)
4   set (INSTALL_VTK OFF CACHE BOOL "Is vtk required to be copied into install directory")
5 endif()
6
7 # vtk directory
8 if (NOT DEFINED 3RDPARTY_VTK_DIR)
9   set (3RDPARTY_VTK_DIR "" CACHE PATH "The directory containing vtk")
10 endif()
11
12 # vtk include directory
13 if (NOT DEFINED 3RDPARTY_VTK_INCLUDE_DIR)
14   set (3RDPARTY_VTK_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of vtk")
15 endif()
16
17 # vtk library directory
18 if (NOT DEFINED 3RDPARTY_VTK_LIBRARY_DIR)
19   set (3RDPARTY_VTK_LIBRARY_DIR "" CACHE FILEPATH "The directory containing vtk library")
20 endif()
21
22 # vtk dll directory
23 if (WIN32 AND NOT DEFINED 3RDPARTY_VTK_DLL_DIR)
24   set (3RDPARTY_VTK_DLL_DIR "" CACHE FILEPATH "The directory containing VTK dll")
25 endif()
26
27 # search for vtk in user defined directory
28 if (NOT 3RDPARTY_VTK_DIR AND 3RDPARTY_DIR)
29   FIND_PRODUCT_DIR("${3RDPARTY_DIR}" vtk VTK_DIR_NAME)
30   if (VTK_DIR_NAME)
31     set (3RDPARTY_VTK_DIR "${3RDPARTY_DIR}/${VTK_DIR_NAME}" CACHE PATH "The directory containing vtk product" FORCE)
32   endif()
33 endif()
34
35 # find installed vtk
36 find_package(VTK QUIET)
37
38 # find native vtk
39 if (NOT VTK_FOUND)
40   find_package(VTK QUIET PATHS "${3RDPARTY_VTK_DIR}")
41 endif()
42
43 if (NOT VTK_FOUND AND NOT 3RDPARTY_VTK_DIR OR NOT EXISTS "${3RDPARTY_VTK_DIR}")
44   message(SEND_ERROR "VTK not found. Set the 3RDPARTY_VTK_DIR cmake cache entry to the directory containing VTK.")
45   set (3RDPARTY_VTK_DIR "3RDPARTY_VTK_DIR-NOTFOUND" CACHE PATH "The directory containing vtk product" FORCE)
46 endif()
47
48 OCCT_MAKE_BUILD_POSTFIX()
49 set(VTK_VERSION "")
50 if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
51   get_filename_component(3RDPARTY_VTK_DIR_NAME "${3RDPARTY_VTK_DIR}" NAME)
52   string(REGEX MATCH "^VTK-([0-9].[0-9])" VTK_VERSION "${3RDPARTY_VTK_DIR_NAME}")
53   set(VTK_VERSION "${CMAKE_MATCH_1}")
54   if (NOT 3RDPARTY_VTK_INCLUDE_DIR OR NOT EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}")
55     set (3RDPARTY_VTK_INCLUDE_DIR "${3RDPARTY_VTK_DIR}/include/vtk-${VTK_VERSION}" CACHE FILEPATH "The directory containing includes of VTK" FORCE)
56   endif()
57   if (NOT 3RDPARTY_VTK_LIBRARY_DIR OR NOT EXISTS "${3RDPARTY_VTK_LIBRARY_DIR}")
58     if(EXISTS "${3RDPARTY_VTK_DIR}/lib${BUILD_POSTFIX}")
59       set (3RDPARTY_VTK_LIBRARY_DIR "${3RDPARTY_VTK_DIR}/lib${BUILD_POSTFIX}" CACHE FILEPATH "The directory containing libs of VTK" FORCE)
60     else()
61           if (NOT "${BUILD_POSTFIX}" STREQUAL "" AND EXISTS "${3RDPARTY_VTK_DIR}/lib")
62             set (3RDPARTY_VTK_LIBRARY_DIR "${3RDPARTY_VTK_DIR}/lib" CACHE FILEPATH "The directory containing libs of VTK" FORCE)
63       endif()
64         endif()
65   endif()
66   if(3RDPARTY_VTK_LIBRARY_DIR)
67     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_VTK_LIBRARY_DIR}")
68   endif()
69 endif()
70
71 # vtk libraries
72 # lib
73 set (VTK_LIBRARY_NAMES vtkCommonCore-${VTK_VERSION}.lib vtkCommonDataModel-${VTK_VERSION}.lib vtkCommonExecutionModel-${VTK_VERSION}.lib 
74                        vtkCommonMath-${VTK_VERSION}.lib vtkCommonTransforms-${VTK_VERSION}.lib vtkRenderingCore-${VTK_VERSION}.lib 
75                        vtkRenderingOpenGL-${VTK_VERSION}.lib vtkFiltersGeneral-${VTK_VERSION}.lib vtkIOCore-${VTK_VERSION}.lib 
76                        vtkIOImage-${VTK_VERSION}.lib vtkImagingCore-${VTK_VERSION}.lib vtkInteractionStyle-${VTK_VERSION}.lib )
77
78 #dll
79 set (VTK_DLL_NAMES vtkCommonComputationalGeometry-${VTK_VERSION}.dll
80                    vtkCommonCore-${VTK_VERSION}.dll
81                    vtkCommonDataModel-${VTK_VERSION}.dll
82                    vtkCommonExecutionModel-${VTK_VERSION}.dll
83                    vtkCommonMath-${VTK_VERSION}.dll
84                    vtkCommonMisc-${VTK_VERSION}.dll
85                    vtkCommonSystem-${VTK_VERSION}.dll
86                    vtkCommonTransforms-${VTK_VERSION}.dll
87                    vtkDICOMParser-${VTK_VERSION}.dll
88                    vtkFiltersCore-${VTK_VERSION}.dll
89                    vtkFiltersExtraction-${VTK_VERSION}.dll
90                    vtkFiltersGeneral-${VTK_VERSION}.dll
91                    vtkFiltersGeometry-${VTK_VERSION}.dll
92                    vtkFiltersSources-${VTK_VERSION}.dll
93                    vtkFiltersStatistics-${VTK_VERSION}.dll
94                    vtkIOCore-${VTK_VERSION}.dll
95                    vtkIOImage-${VTK_VERSION}.dll
96                    vtkImagingCore-${VTK_VERSION}.dll
97                    vtkImagingFourier-${VTK_VERSION}.dll
98                    vtkImagingHybrid-${VTK_VERSION}.dll
99                    vtkInteractionStyle-${VTK_VERSION}.dll
100                    vtkRenderingCore-${VTK_VERSION}.dll
101                    vtkRenderingOpenGL-${VTK_VERSION}.dll
102                    vtkalglib-${VTK_VERSION}.dll
103                    vtkjpeg-${VTK_VERSION}.dll
104                    vtkmetaio-${VTK_VERSION}.dll
105                    vtkpng-${VTK_VERSION}.dll
106                    vtksys-${VTK_VERSION}.dll
107                    vtktiff-${VTK_VERSION}.dll
108                    vtkzlib-${VTK_VERSION}.dll )
109
110 # search for dll directory
111 if (WIN32)
112   if (NOT 3RDPARTY_VTK_DLL_DIR OR NOT EXISTS "${3RDPARTY_VTK_DLL_DIR}")
113     if(EXISTS "${3RDPARTY_VTK_DIR}/bin${BUILD_POSTFIX}")
114       set (3RDPARTY_VTK_DLL_DIR "${3RDPARTY_VTK_DIR}/bin${BUILD_POSTFIX}" CACHE FILEPATH "The directory containing dll of VTK" FORCE)
115     else()
116           if (NOT "${BUILD_POSTFIX}" STREQUAL "" AND EXISTS "${3RDPARTY_VTK_DIR}/bin")
117             set (3RDPARTY_VTK_DLL_DIR "${3RDPARTY_VTK_DIR}/bin" CACHE FILEPATH "The directory containing dll of VTK" FORCE)
118       endif()
119         endif()
120   endif()
121 endif() 
122
123 OCCT_CHECK_AND_UNSET(VTK_DIR)
124
125 if (3RDPARTY_VTK_INCLUDE_DIR AND EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}")
126   list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_VTK_INCLUDE_DIR}")
127 else()
128   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_INCLUDE_DIR)
129 endif()
130
131 if (INSTALL_VTK)
132   OCCT_MAKE_OS_WITH_BITNESS()
133   OCCT_MAKE_COMPILER_SHORT_NAME()
134   if (WIN32)
135     if(3RDPARTY_VTK_DLL_DIR AND EXISTS "${3RDPARTY_VTK_DLL_DIR}")
136       set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
137       foreach(VTK_DLL_NAME ${VTK_DLL_NAMES})
138         set (3RDPARTY_VTK_DLL "3RDPARTY_VTK_DLL-NOTFOUND" CACHE FILEPATH "VTK shared library" FORCE)
139         find_library(3RDPARTY_VTK_DLL "${VTK_DLL_NAME}" PATHS "${3RDPARTY_VTK_DLL_DIR}" NO_DEFAULT_PATH)
140         if (NOT 3RDPARTY_VTK_DLL OR NOT EXISTS "${3RDPARTY_VTK_DLL}")
141           list (APPEND 3RDPARTY_NOT_INCLUDED "${3RDPARTY_VTK_DLL}")
142         else()
143           install (FILES ${3RDPARTY_VTK_DLL} DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BUILD_POSTFIX}")
144         endif()
145       endforeach()
146       OCCT_CHECK_AND_UNSET(3RDPARTY_VTK_DLL)
147     endif()
148   else ()
149     foreach(VTK_DLL_NAME ${VTK_DLL_NAMES})
150       string(REPLACE ".dll" ".so.1" VTK_DLL_NAME "${VTK_DLL_NAME}")
151       install(FILES "${3RDPARTY_VTK_LIBRARY_DIR}/lib${VTK_DLL_NAME}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BUILD_POSTFIX}" RENAME "lib${VTK_DLL_NAME}")
152     endforeach()
153   endif()
154
155   set (USED_3RDPARTY_VTK_DIR "")
156 else()
157   # the library directory for using by the executable
158   if (WIN32)
159     set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_DLL_DIR})
160   else()
161     set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_LIBRARY_DIR})
162   endif()
163 endif()
164
165 mark_as_advanced (VTK_INCLUDE_DIRS VTK_LIBRARY_DIRS VTK_DIR)