0027209: CMake - warnings on configuration step for VTK when using vc14 target
[occt.git] / adm / cmake / vtk.cmake
1 # vtk
2
3 #if (NOT DEFINED INSTALL_VTK)
4 #  set (INSTALL_VTK OFF CACHE BOOL "${INSTALL_VTK_DESCR}")
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 # include occt macros. compiler_bitness, os_wiht_bit, compiler
13 OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
14
15 # specify VTK folder in connectin with 3RDPARTY_DIR
16 if (3RDPARTY_DIR AND EXISTS "${3RDPARTY_DIR}")
17   #CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_DIR 3RDPARTY_VTK_DIR PATH "The directory containing VTK")
18
19   if (NOT 3RDPARTY_VTK_DIR OR NOT EXISTS "${3RDPARTY_VTK_DIR}")
20     FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" VTK VTK_DIR_NAME)
21     if (VTK_DIR_NAME)
22       set (3RDPARTY_VTK_DIR "${3RDPARTY_DIR}/${VTK_DIR_NAME}" CACHE PATH "The directory containing VTK" FORCE)
23     endif()
24   endif()
25 else()
26   #set (3RDPARTY_VTK_DIR "" CACHE PATH "The directory containing VTK" FORCE)
27 endif()
28
29 # vtk include directory
30 if (NOT DEFINED 3RDPARTY_VTK_INCLUDE_DIR)
31   set (3RDPARTY_VTK_INCLUDE_DIR "" CACHE PATH "The directory containing headers of VTK")
32 endif()
33
34 # vtk library directory
35 if (NOT DEFINED 3RDPARTY_VTK_LIBRARY_DIR)
36   set (3RDPARTY_VTK_LIBRARY_DIR "" CACHE PATH "The directory containing VTK libraries")
37 endif()
38
39 # vtk dll directory
40 if (WIN32 AND NOT DEFINED 3RDPARTY_VTK_DLL_DIR)
41   set (3RDPARTY_VTK_DLL_DIR "" CACHE PATH "The directory containing VTK shared libraries")
42 endif()
43
44 # check 3RDPARTY_VTK_ paths for consistency with specified 3RDPARTY_VTK_DIR
45 if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
46   CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_VTK_DIR 3RDPARTY_VTK_INCLUDE_DIR PATH "The directory containing headers of VTK")
47   CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_VTK_DIR 3RDPARTY_VTK_LIBRARY_DIR PATH "The directory containing VTK libraries")
48
49   if (WIN32)
50     CHECK_PATH_FOR_CONSISTENCY (3RDPARTY_VTK_DIR 3RDPARTY_VTK_DLL_DIR PATH "The directory containing VTK shared library")
51   endif()
52 endif()
53
54 if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
55   set (CACHED_VTK_DIR $ENV{VTK_DIR})
56   set (ENV{VTK_DIR} "${3RDPARTY_VTK_DIR}")
57 endif()
58
59 find_package(VTK QUIET)
60
61 if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
62   set (ENV{VTK_DIR} ${CACHED_VTK_DIR})
63 endif()
64
65 if (VTK_FOUND)
66
67   # add compiler flags, preprocessor definitions, include and link dirs
68   include (${VTK_USE_FILE})
69
70   if (VTK_LIBRARIES)
71
72     set (3RDPARTY_VTK_INCLUDE_DIRS)
73     set (3RDPARTY_VTK_LIBRARY_DIRS)
74     set (3RDPARTY_VTK_DLL_DIRS)
75
76     foreach (VTK_LIBRARY ${VTK_LIBRARIES})
77       string (REGEX MATCH "^vtk" IS_VTK_LIBRARY ${VTK_LIBRARY})
78       if (IS_VTK_LIBRARY AND TARGET ${VTK_LIBRARY})
79         # get paths from corresponding variables
80         if (${VTK_LIBRARY}_INCLUDE_DIRS AND EXISTS "${${VTK_LIBRARY}_INCLUDE_DIRS}")
81           list (APPEND 3RDPARTY_VTK_INCLUDE_DIRS "${${VTK_LIBRARY}_INCLUDE_DIRS}")
82         endif()
83
84         if (${VTK_LIBRARY}_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_LIBRARY_DIRS}")
85           list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_LIBRARY_DIRS}")
86         endif()
87
88         if (${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
89           list (APPEND 3RDPARTY_VTK_DLL_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
90           if (NOT WIN32)
91             list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
92           endif()
93         endif()
94
95         # get paths from corresponding properties
96         get_target_property (TARGET_VTK_IMPORT_CONFS ${VTK_LIBRARY} IMPORTED_CONFIGURATIONS)
97
98         if (TARGET_VTK_IMPORT_CONFS)
99           list (GET TARGET_VTK_IMPORT_CONFS 0 CHOSEN_IMPORT_CONF)
100           
101           # todo: choose configuration in connection with the build type
102           #if (CMAKE_BUILD_TYPE)
103           #  foreach (IMPORT_CONF ${TARGET_VTK_IMPORT_CONFS})
104           #  endforeach()
105           #endif()
106
107           # Work-around against link failure in case if VTK contains dependency
108           # on DirectX: its run-time is always present on Windows, but SDK can
109           # be absent on current workstation, while not actually needed for 
110           # OCCT linking.
111           # VTK 6.1 for VC 10
112           get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF})
113           if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES)
114             string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}")
115             if (HARDCODED_D3D9_LIB)
116               message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}")
117               
118               list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB})
119               set_target_properties (${VTK_LIBRARY} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_${CHOSEN_IMPORT_CONF} "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}")
120             endif()            
121           endif()
122           # VTK 6.1 for VC 12, 14
123           get_target_property (TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${VTK_LIBRARY} INTERFACE_LINK_LIBRARIES)
124           if(TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES)
125             string (REGEX MATCH "[^;]*d3d[0-9]+[.]lib" HARDCODED_D3D9_LIB "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}")
126             if (HARDCODED_D3D9_LIB)
127               message (STATUS "Warning: ${HARDCODED_D3D9_LIB} has been removed from imported dependencies of ${VTK_LIBRARY}")
128               
129               list (REMOVE_ITEM TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES ${HARDCODED_D3D9_LIB})
130               set_target_properties (${VTK_LIBRARY} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET_PROPERTY_IMP_LINK_INTERFACE_LIBRARIES}")
131             endif()            
132           endif()
133
134           get_target_property (TARGET_PROPERTY_IMP_PATH ${VTK_LIBRARY} IMPORTED_IMPLIB_${CHOSEN_IMPORT_CONF})
135           if(TARGET_PROPERTY_IMP_PATH AND EXISTS "${TARGET_PROPERTY_IMP_PATH}")
136             get_filename_component (TARGET_PROPERTY_IMP_DIR "${TARGET_PROPERTY_IMP_PATH}" PATH)
137             list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_IMP_DIR}")
138           endif()
139
140           get_target_property (TARGET_PROPERTY_LOCATION_PATH ${VTK_LIBRARY} IMPORTED_LOCATION_${CHOSEN_IMPORT_CONF})
141           if(TARGET_PROPERTY_LOCATION_PATH AND EXISTS "${TARGET_PROPERTY_LOCATION_PATH}")
142             get_filename_component (TARGET_PROPERTY_LOCATION_DIR "${TARGET_PROPERTY_LOCATION_PATH}" PATH)
143
144             if (WIN32)
145               list (APPEND 3RDPARTY_VTK_DLL_DIRS "${TARGET_PROPERTY_LOCATION_DIR}")
146             else()
147               list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_LOCATION_DIR}")
148             endif()
149           endif()
150         endif()
151       endif()
152     endforeach()
153   endif()
154
155   if (3RDPARTY_VTK_INCLUDE_DIRS)
156     list (REMOVE_DUPLICATES 3RDPARTY_VTK_INCLUDE_DIRS)
157     list (APPEND 3RDPARTY_INCLUDE_DIRS ${3RDPARTY_VTK_INCLUDE_DIRS})
158
159     list (GET 3RDPARTY_VTK_INCLUDE_DIRS 0 3RDPARTY_VTK_INCLUDE_DIR)
160     set (3RDPARTY_VTK_INCLUDE_DIR "${3RDPARTY_VTK_INCLUDE_DIR}" CACHE PATH "The directory containing headers of VTK" FORCE)
161   endif()
162
163   if (3RDPARTY_VTK_LIBRARY_DIRS)
164     list (REMOVE_DUPLICATES 3RDPARTY_VTK_LIBRARY_DIRS)
165     list (APPEND 3RDPARTY_LIBRARY_DIRS ${3RDPARTY_VTK_LIBRARY_DIRS})
166
167     list (GET 3RDPARTY_VTK_LIBRARY_DIRS 0 3RDPARTY_VTK_LIBRARY_DIR)
168     set (3RDPARTY_VTK_LIBRARY_DIR "${3RDPARTY_VTK_LIBRARY_DIR}" CACHE PATH "The directory containing VTK libraries" FORCE)
169   endif()
170
171   if (WIN32)
172     if (3RDPARTY_VTK_DLL_DIRS)
173       list (REMOVE_DUPLICATES 3RDPARTY_VTK_DLL_DIRS)
174       list (APPEND 3RDPARTY_DLL_DIRS ${3RDPARTY_VTK_DLL_DIRS})
175
176       list (GET 3RDPARTY_VTK_DLL_DIRS 0 3RDPARTY_VTK_DLL_DIR)
177       set (3RDPARTY_VTK_DLL_DIR "${3RDPARTY_VTK_DLL_DIR}" CACHE PATH "The directory containing VTK shared libraries" FORCE)
178     endif()
179   endif()
180 endif()
181
182 if (3RDPARTY_VTK_INCLUDE_DIR AND EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}")
183   list (APPEND 3RDPARTY_INCLUDE_DIRS ${3RDPARTY_VTK_INCLUDE_DIR})
184 else()
185   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_INCLUDE_DIR)
186 endif()
187
188 if (3RDPARTY_VTK_LIBRARY_DIR AND EXISTS "${3RDPARTY_VTK_LIBRARY_DIR}")
189   list (APPEND 3RDPARTY_LIBRARY_DIRS ${3RDPARTY_VTK_LIBRARY_DIR})
190 else()
191   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_LIBRARY_DIR)
192 endif()
193
194 if (WIN32)
195   if (3RDPARTY_VTK_DLL_DIR OR EXISTS "${3RDPARTY_VTK_DLL_DIR}")
196     list (APPEND 3RDPARTY_DLL_DIRS ${3RDPARTY_VTK_DLL_DIR})
197   else()
198     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_DLL_DIR)
199   endif()
200 endif()
201
202 # the library directory for using by the executable
203 if (WIN32)
204   set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_DLL_DIR})
205 else()
206   set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_LIBRARY_DIR})
207 endif()
208
209 OCCT_CHECK_AND_UNSET (VTK_INCLUDE_DIRS)
210 OCCT_CHECK_AND_UNSET (VTK_LIBRARY_DIRS)
211 OCCT_CHECK_AND_UNSET (VTK_DIR)