0026993: Configuration, CMake - use the abstraction level of VTK instead CSF_VTK...
[occt.git] / adm / cmake / vtk.cmake
CommitLineData
09c597c9 1# vtk
2
e713baee 3#if (NOT DEFINED INSTALL_VTK)
4# set (INSTALL_VTK OFF CACHE BOOL "${INSTALL_VTK_DESCR}")
5#endif()
09c597c9 6
7# vtk directory
8if (NOT DEFINED 3RDPARTY_VTK_DIR)
e713baee 9 set (3RDPARTY_VTK_DIR "" CACHE PATH "The directory containing VTK")
10endif()
11
e713baee 12# include occt macros. compiler_bitness, os_wiht_bit, compiler
13OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
14
15# specify VTK folder in connectin with 3RDPARTY_DIR
16if (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()
25else()
26 #set (3RDPARTY_VTK_DIR "" CACHE PATH "The directory containing VTK" FORCE)
09c597c9 27endif()
28
29# vtk include directory
30if (NOT DEFINED 3RDPARTY_VTK_INCLUDE_DIR)
e713baee 31 set (3RDPARTY_VTK_INCLUDE_DIR "" CACHE PATH "The directory containing headers of VTK")
09c597c9 32endif()
33
34# vtk library directory
35if (NOT DEFINED 3RDPARTY_VTK_LIBRARY_DIR)
e713baee 36 set (3RDPARTY_VTK_LIBRARY_DIR "" CACHE PATH "The directory containing VTK libraries")
09c597c9 37endif()
38
39# vtk dll directory
40if (WIN32 AND NOT DEFINED 3RDPARTY_VTK_DLL_DIR)
e713baee 41 set (3RDPARTY_VTK_DLL_DIR "" CACHE PATH "The directory containing VTK shared libraries")
09c597c9 42endif()
43
e713baee 44# check 3RDPARTY_VTK_ paths for consistency with specified 3RDPARTY_VTK_DIR
45if (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")
09c597c9 51 endif()
52endif()
53
e713baee 54if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
55 set (CACHED_VTK_DIR $ENV{VTK_DIR})
56 set (ENV{VTK_DIR} "${3RDPARTY_VTK_DIR}")
57endif()
58
09c597c9 59find_package(VTK QUIET)
60
e713baee 61if (3RDPARTY_VTK_DIR AND EXISTS "${3RDPARTY_VTK_DIR}")
62 set (ENV{VTK_DIR} ${CACHED_VTK_DIR})
09c597c9 63endif()
64
e713baee 65if (VTK_FOUND)
09c597c9 66
e713baee 67 # add compiler flags, preprocessor definitions, include and link dirs
68 include (${VTK_USE_FILE})
69
e713baee 70 if (VTK_LIBRARIES)
71
72 set (3RDPARTY_VTK_INCLUDE_DIRS)
73 set (3RDPARTY_VTK_LIBRARY_DIRS)
74 set (3RDPARTY_VTK_DLL_DIRS)
75
a6874708 76 foreach (VTK_LIBRARY ${VTK_LIBRARIES})
77 # get paths from corresponding variables
78 if (${VTK_LIBRARY}_INCLUDE_DIRS AND EXISTS "${${VTK_LIBRARY}_INCLUDE_DIRS}")
79 list (APPEND 3RDPARTY_VTK_INCLUDE_DIRS "${${VTK_LIBRARY}_INCLUDE_DIRS}")
80 endif()
e713baee 81
a6874708 82 if (${VTK_LIBRARY}_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_LIBRARY_DIRS}")
83 list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_LIBRARY_DIRS}")
84 endif()
e713baee 85
a6874708 86 if (${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS AND EXISTS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
87 list (APPEND 3RDPARTY_VTK_DLL_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
88 if (NOT WIN32)
89 list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${${VTK_LIBRARY}_RUNTIME_LIBRARY_DIRS}")
e713baee 90 endif()
a6874708 91 endif()
e713baee 92
a6874708 93 # get paths from corresponding properties
94 get_property (TARGET_VTK_IMPORT_CONFS TARGET ${VTK_LIBRARY} PROPERTY IMPORTED_CONFIGURATIONS)
95
96 if (TARGET_VTK_IMPORT_CONFS)
97 list (GET TARGET_VTK_IMPORT_CONFS 0 CHOSEN_IMPORT_CONF)
98
99 # todo: choose configuration in connection with the build type
100 #if (CMAKE_BUILD_TYPE)
101 # foreach (IMPORT_CONF ${TARGET_VTK_IMPORT_CONFS})
102 # endforeach()
103 #endif()
104
105 get_property (TARGET_PROPERTY_IMP_PATH TARGET ${VTK_LIBRARY} PROPERTY IMPORTED_IMPLIB_${CHOSEN_IMPORT_CONF})
106 if(TARGET_PROPERTY_IMP_PATH AND EXISTS "${TARGET_PROPERTY_IMP_PATH}")
107 get_filename_component (TARGET_PROPERTY_IMP_DIR "${TARGET_PROPERTY_IMP_PATH}" PATH)
108 list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_IMP_DIR}")
109 endif()
e713baee 110
a6874708 111 get_property (TARGET_PROPERTY_LOCATION_PATH TARGET ${VTK_LIBRARY} PROPERTY IMPORTED_LOCATION_${CHOSEN_IMPORT_CONF})
112 if(TARGET_PROPERTY_LOCATION_PATH AND EXISTS "${TARGET_PROPERTY_LOCATION_PATH}")
113 get_filename_component (TARGET_PROPERTY_LOCATION_DIR "${TARGET_PROPERTY_LOCATION_PATH}" PATH)
e713baee 114
a6874708 115 if (WIN32)
116 list (APPEND 3RDPARTY_VTK_DLL_DIRS "${TARGET_PROPERTY_LOCATION_DIR}")
117 else()
118 list (APPEND 3RDPARTY_VTK_LIBRARY_DIRS "${TARGET_PROPERTY_LOCATION_DIR}")
e713baee 119 endif()
120 endif()
121 endif()
e713baee 122 endforeach()
09c597c9 123 endif()
e713baee 124
a6874708 125 if (3RDPARTY_VTK_INCLUDE_DIRS)
126 list (REMOVE_DUPLICATES 3RDPARTY_VTK_INCLUDE_DIRS)
127 list (APPEND 3RDPARTY_INCLUDE_DIRS ${3RDPARTY_VTK_INCLUDE_DIRS})
e713baee 128
a6874708 129 list (GET 3RDPARTY_VTK_INCLUDE_DIRS 0 3RDPARTY_VTK_INCLUDE_DIR)
130 set (3RDPARTY_VTK_INCLUDE_DIR "${3RDPARTY_VTK_INCLUDE_DIR}" CACHE PATH "The directory containing headers of VTK" FORCE)
131 endif()
09c597c9 132
a6874708 133 if (3RDPARTY_VTK_LIBRARY_DIRS)
134 list (REMOVE_DUPLICATES 3RDPARTY_VTK_LIBRARY_DIRS)
135 list (APPEND 3RDPARTY_LIBRARY_DIRS ${3RDPARTY_VTK_LIBRARY_DIRS})
fb3267c7 136
a6874708 137 list (GET 3RDPARTY_VTK_LIBRARY_DIRS 0 3RDPARTY_VTK_LIBRARY_DIR)
138 set (3RDPARTY_VTK_LIBRARY_DIR "${3RDPARTY_VTK_LIBRARY_DIR}" CACHE PATH "The directory containing VTK libraries" FORCE)
139 endif()
94829f84 140
a6874708 141 if (WIN32)
142 if (3RDPARTY_VTK_DLL_DIRS)
143 list (REMOVE_DUPLICATES 3RDPARTY_VTK_DLL_DIRS)
144 list (APPEND 3RDPARTY_DLL_DIRS ${3RDPARTY_VTK_DLL_DIRS})
09c597c9 145
a6874708 146 list (GET 3RDPARTY_VTK_DLL_DIRS 0 3RDPARTY_VTK_DLL_DIR)
147 set (3RDPARTY_VTK_DLL_DIR "${3RDPARTY_VTK_DLL_DIR}" CACHE PATH "The directory containing VTK shared libraries" FORCE)
e713baee 148 endif()
149 endif()
150endif()
09c597c9 151
152if (3RDPARTY_VTK_INCLUDE_DIR AND EXISTS "${3RDPARTY_VTK_INCLUDE_DIR}")
e713baee 153 list (APPEND 3RDPARTY_INCLUDE_DIRS ${3RDPARTY_VTK_INCLUDE_DIR})
09c597c9 154else()
155 list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_INCLUDE_DIR)
156endif()
157
e713baee 158if (3RDPARTY_VTK_LIBRARY_DIR AND EXISTS "${3RDPARTY_VTK_LIBRARY_DIR}")
159 list (APPEND 3RDPARTY_LIBRARY_DIRS ${3RDPARTY_VTK_LIBRARY_DIR})
160else()
161 list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_LIBRARY_DIR)
162endif()
fb3267c7 163
e713baee 164if (WIN32)
165 if (3RDPARTY_VTK_DLL_DIR OR EXISTS "${3RDPARTY_VTK_DLL_DIR}")
166 list (APPEND 3RDPARTY_DLL_DIRS ${3RDPARTY_VTK_DLL_DIR})
167 else()
168 list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_VTK_DLL_DIR)
09c597c9 169 endif()
e713baee 170endif()
0a66e59d 171
e713baee 172# the library directory for using by the executable
173if (WIN32)
174 set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_DLL_DIR})
0a66e59d 175else()
e713baee 176 set (USED_3RDPARTY_VTK_DIR ${3RDPARTY_VTK_LIBRARY_DIR})
09c597c9 177endif()
178
a6874708 179OCCT_CHECK_AND_UNSET (VTK_INCLUDE_DIRS)
180OCCT_CHECK_AND_UNSET (VTK_LIBRARY_DIRS)
181OCCT_CHECK_AND_UNSET (VTK_DIR)