0025244: CMake building procedure should support VTK usage
[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     endif()
61   else()
62     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_VTK_LIBRARY_DIR}")
63   endif()
64 endif()
65
66 # vtk libraries
67 # lib
68 set (VTK_LIBRARY_NAMES vtkCommonCore-${VTK_VERSION}.lib vtkCommonDataModel-${VTK_VERSION}.lib vtkCommonExecutionModel-${VTK_VERSION}.lib 
69                        vtkCommonMath-${VTK_VERSION}.lib vtkCommonTransforms-${VTK_VERSION}.lib vtkRenderingCore-${VTK_VERSION}.lib 
70                        vtkRenderingOpenGL-${VTK_VERSION}.lib vtkFiltersGeneral-${VTK_VERSION}.lib vtkIOCore-${VTK_VERSION}.lib 
71                        vtkIOImage-${VTK_VERSION}.lib vtkImagingCore-${VTK_VERSION}.lib vtkInteractionStyle-${VTK_VERSION}.lib )
72
73 #dll
74 set (VTK_DLL_NAMES vtkCommonComputationalGeometry-${VTK_VERSION}.dll
75                    vtkCommonCore-${VTK_VERSION}.dll
76                    vtkCommonDataModel-${VTK_VERSION}.dll
77                    vtkCommonExecutionModel-${VTK_VERSION}.dll
78                    vtkCommonMath-${VTK_VERSION}.dll
79                    vtkCommonMisc-${VTK_VERSION}.dll
80                    vtkCommonSystem-${VTK_VERSION}.dll
81                    vtkCommonTransforms-${VTK_VERSION}.dll
82                    vtkDICOMParser-${VTK_VERSION}.dll
83                    vtkFiltersCore-${VTK_VERSION}.dll
84                    vtkFiltersExtraction-${VTK_VERSION}.dll
85                    vtkFiltersGeneral-${VTK_VERSION}.dll
86                    vtkFiltersGeometry-${VTK_VERSION}.dll
87                    vtkFiltersSources-${VTK_VERSION}.dll
88                    vtkFiltersStatistics-${VTK_VERSION}.dll
89                    vtkIOCore-${VTK_VERSION}.dll
90                    vtkIOImage-${VTK_VERSION}.dll
91                    vtkImagingCore-${VTK_VERSION}.dll
92                    vtkImagingFourier-${VTK_VERSION}.dll
93                    vtkImagingHybrid-${VTK_VERSION}.dll
94                    vtkInteractionStyle-${VTK_VERSION}.dll
95                    vtkRenderingCore-${VTK_VERSION}.dll
96                    vtkRenderingOpenGL-${VTK_VERSION}.dll
97                    vtkalglib-${VTK_VERSION}.dll
98                    vtkjpeg-${VTK_VERSION}.dll
99                    vtkmetaio-${VTK_VERSION}.dll
100                    vtkpng-${VTK_VERSION}.dll
101                    vtksys-${VTK_VERSION}.dll
102                    vtktiff-${VTK_VERSION}.dll
103                    vtkzlib-${VTK_VERSION}.dll )
104
105 # search for dll directory
106 if (WIN32)
107   if (NOT 3RDPARTY_VTK_DLL_DIR OR NOT EXISTS "${3RDPARTY_VTK_DLL_DIR}")
108     if(EXISTS "${3RDPARTY_VTK_DIR}/bin${BUILD_POSTFIX}")
109       set (3RDPARTY_VTK_DLL_DIR "${3RDPARTY_VTK_DIR}/bin${BUILD_POSTFIX}" CACHE FILEPATH "The directory containing dll of VTK" FORCE)
110     endif()
111   endif()
112 endif() 
113
114 OCCT_CHECK_AND_UNSET(VTK_DIR)
115
116 if (3RDPARTY_VTK_INCLUDE_DIR AND EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}")
117   list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_VTK_INCLUDE_DIR}")
118 else()
119   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_INCLUDE_DIR)
120 endif()
121
122 if (INSTALL_VTK)
123   OCCT_MAKE_OS_WITH_BITNESS()
124   OCCT_MAKE_COMPILER_SHORT_NAME()
125   if (WIN32)
126     if(3RDPARTY_VTK_DLL_DIR AND EXISTS "${3RDPARTY_VTK_DLL_DIR}")
127       set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
128       foreach(VTK_DLL_NAME ${VTK_DLL_NAMES})
129         set (3RDPARTY_VTK_DLL "3RDPARTY_VTK_DLL-NOTFOUND" CACHE FILEPATH "VTK shared library" FORCE)
130         find_library(3RDPARTY_VTK_DLL "${VTK_DLL_NAME}" PATHS "${3RDPARTY_VTK_DLL_DIR}" NO_DEFAULT_PATH)
131         if (NOT 3RDPARTY_VTK_DLL OR NOT EXISTS "${3RDPARTY_VTK_DLL}")
132           list (APPEND 3RDPARTY_NOT_INCLUDED "${3RDPARTY_VTK_DLL}")
133         else()
134           install (FILES ${3RDPARTY_VTK_DLL} DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BUILD_POSTFIX}")
135         endif()
136       endforeach()
137       OCCT_CHECK_AND_UNSET(3RDPARTY_VTK_DLL)
138     endif()
139   else ()
140     foreach(VTK_DLL_NAME ${VTK_DLL_NAMES})
141       string(REPLACE ".dll" ".so.1" VTK_DLL_NAME "${VTK_DLL_NAME}")
142       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}")
143     endforeach()
144   endif()
145 endif()
146
147 mark_as_advanced (VTK_INCLUDE_DIRS VTK_LIBRARY_DIRS VTK_DIR)