0026763: CMake configuration process does not allow setup paths for TK library if...
[occt.git] / adm / cmake / tcl.cmake
1 # tcl
2
3 if (NOT DEFINED INSTALL_TCL)
4   set (INSTALL_TCL OFF CACHE BOOL "${INSTALL_TCL_DESCR}")
5 endif()
6
7 # tcl directory
8 if (NOT DEFINED 3RDPARTY_TCL_DIR)
9   set (3RDPARTY_TCL_DIR "" CACHE PATH "The directory containing tcl")
10 endif()
11
12 # tcl include directory
13 if (NOT DEFINED 3RDPARTY_TCL_INCLUDE_DIR)
14   set (3RDPARTY_TCL_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of tcl")
15 endif()
16
17 # tcl library file (with absolute path)
18 if (NOT DEFINED 3RDPARTY_TCL_LIBRARY OR NOT 3RDPARTY_TCL_LIBRARY_DIR)
19   set (3RDPARTY_TCL_LIBRARY "" CACHE FILEPATH "tcl library"  FORCE)
20 endif()
21
22 # tcl library directory
23 if (NOT DEFINED 3RDPARTY_TCL_LIBRARY_DIR)
24   set (3RDPARTY_TCL_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tcl library")
25 endif()
26
27 # tcl shared library (with absolute path)
28 if (WIN32)
29   if (NOT DEFINED 3RDPARTY_TCL_DLL OR NOT 3RDPARTY_TCL_DLL_DIR)
30     set (3RDPARTY_TCL_DLL "" CACHE FILEPATH "tcl shared library" FORCE)
31   endif()
32 endif()
33
34 # tcl shared library directory
35 if (WIN32 AND NOT DEFINED 3RDPARTY_TCL_DLL_DIR)
36   set (3RDPARTY_TCL_DLL_DIR "" CACHE FILEPATH "The directory containing tcl shared library")
37 endif()
38
39 # search for tcl in user defined directory
40 if (NOT 3RDPARTY_TCL_DIR AND 3RDPARTY_DIR)
41   FIND_PRODUCT_DIR("${3RDPARTY_DIR}" tcl TCL_DIR_NAME)
42   if (TCL_DIR_NAME)
43     set (3RDPARTY_TCL_DIR "${3RDPARTY_DIR}/${TCL_DIR_NAME}" CACHE PATH "The directory containing tcl" FORCE)
44   endif()
45 endif()
46
47 # define paths for default engine
48 if (3RDPARTY_TCL_DIR AND EXISTS "${3RDPARTY_TCL_DIR}")
49   set (TCL_INCLUDE_PATH "${3RDPARTY_TCL_DIR}/include")
50 endif()
51
52 # check tcl include dir, library dir and shared library dir
53 COMPLIANCE_PRODUCT_CONSISTENCY(TCL)
54
55 # use default (CMake) TCL search
56 find_package(TCL)
57
58 # tcl include dir
59 if (NOT 3RDPARTY_TCL_INCLUDE_DIR)
60   if (TCL_INCLUDE_PATH AND EXISTS "${TCL_INCLUDE_PATH}")
61     set (3RDPARTY_TCL_INCLUDE_DIR "${TCL_INCLUDE_PATH}" CACHE FILEPATH "The directory containing headers of TCL" FORCE)
62   endif()
63 endif()
64
65 # tcl dir and library
66 if (NOT 3RDPARTY_TCL_LIBRARY)
67   if (TCL_LIBRARY AND EXISTS "${TCL_LIBRARY}")
68     set (3RDPARTY_TCL_LIBRARY "${TCL_LIBRARY}" CACHE FILEPATH "TCL library" FORCE)
69
70     if (NOT 3RDPARTY_TCL_LIBRARY_DIR)
71       get_filename_component (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
72       set (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY_DIR}" CACHE FILEPATH "The directory containing TCL library" FORCE)
73     endif()
74   endif()
75 endif()
76
77
78 if (WIN32)
79   if (NOT 3RDPARTY_TCL_DLL)
80     set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
81
82     set (DLL_FOLDER_FOR_SEARCH "")
83     if (3RDPARTY_TCL_DLL_DIR)
84       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DLL_DIR}")
85     elseif (3RDPARTY_TCL_DIR)
86       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DIR}/bin")
87     elseif (3RDPARTY_TCL_LIBRARY_DIR)
88       get_filename_component (3RDPARTY_TCL_LIBRARY_DIR_PARENT "${3RDPARTY_TCL_LIBRARY_DIR}" PATH)
89       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_LIBRARY_DIR_PARENT}/bin")
90     endif()
91
92     set (3RDPARTY_TCL_DLL "3RDPARTY_TCL_DLL-NOTFOUND" CACHE FILEPATH "TCL shared library" FORCE)
93     find_library (3RDPARTY_TCL_DLL NAMES tcl86 tcl85
94                                           PATHS "${DLL_FOLDER_FOR_SEARCH}"
95                                           NO_DEFAULT_PATH)
96   endif()
97 endif()
98
99 COMPLIANCE_PRODUCT_CONSISTENCY(TCL)
100
101 # tcl dir and library
102 if (NOT 3RDPARTY_TCL_LIBRARY)
103   set (3RDPARTY_TCL_LIBRARY "3RDPARTY_TCL_LIBRARY-NOTFOUND" CACHE FILEPATH "TCL library" FORCE)
104   find_library (3RDPARTY_TCL_LIBRARY NAMES tcl8.6 tcl86 tcl8.5 tcl85
105                                             PATHS "${3RDPARTY_TCL_LIBRARY_DIR}"
106                                             NO_DEFAULT_PATH)
107
108   # search in another place if previous search doesn't find anything
109   find_library (3RDPARTY_TCL_LIBRARY NAMES tcl8.6 tcl86 tcl8.5 tcl85
110                                             PATHS "${3RDPARTY_TCL_DIR}/lib"
111                                             NO_DEFAULT_PATH)
112
113
114   if (NOT 3RDPARTY_TCL_LIBRARY OR NOT EXISTS "${3RDPARTY_TCL_LIBRARY}")
115     set (3RDPARTY_TCL_LIBRARY "" CACHE FILEPATH "TCL library" FORCE)
116   endif()
117
118   if (NOT 3RDPARTY_TCL_LIBRARY_DIR AND 3RDPARTY_TCL_LIBRARY)
119     get_filename_component (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
120     set (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY_DIR}" CACHE FILEPATH "The directory containing TCL library" FORCE)
121   endif()
122 endif()
123
124 set (3RDPARTY_TCL_LIBRARY_VERSION "")
125 if (3RDPARTY_TCL_LIBRARY AND EXISTS "${3RDPARTY_TCL_LIBRARY}")
126   get_filename_component (TCL_LIBRARY_NAME "${3RDPARTY_TCL_LIBRARY}" NAME)
127   string(REGEX REPLACE "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY_NAME}")
128
129   if (NOT "${TCL_LIBRARY_VERSION}" STREQUAL "${TCL_LIBRARY_NAME}")
130     set (3RDPARTY_TCL_LIBRARY_VERSION "${TCL_LIBRARY_VERSION}")
131   else() # if the version isn't found - seek other library with 8.6 or 8.5 version in the same dir
132     message (STATUS "Info: TCL version isn't found")
133   endif()
134 endif()
135
136 set (3RDPARTY_TCL_LIBRARY_VERSION_WITH_DOT "")
137 if (3RDPARTY_TCL_LIBRARY_VERSION)
138   string (REGEX REPLACE "^.*([0-9])[^0-9]*[0-9].*$" "\\1" 3RDPARTY_TCL_MAJOR_VERSION "${3RDPARTY_TCL_LIBRARY_VERSION}")
139   string (REGEX REPLACE "^.*[0-9][^0-9]*([0-9]).*$" "\\1" 3RDPARTY_TCL_MINOR_VERSION "${3RDPARTY_TCL_LIBRARY_VERSION}")
140   set (3RDPARTY_TCL_LIBRARY_VERSION_WITH_DOT "${3RDPARTY_TCL_MAJOR_VERSION}.${3RDPARTY_TCL_MINOR_VERSION}")
141 endif()
142
143 if (WIN32)
144   if (NOT 3RDPARTY_TCL_DLL)
145     set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
146
147     set (DLL_FOLDER_FOR_SEARCH "")
148     if (3RDPARTY_TCL_DLL_DIR)
149       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DLL_DIR}")
150     elseif (3RDPARTY_TCL_DIR)
151       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DIR}/bin")
152     else()
153       get_filename_component (3RDPARTY_TCL_LIBRARY_DIR_PARENT "${3RDPARTY_TCL_LIBRARY_DIR}" PATH)
154       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_LIBRARY_DIR_PARENT}/bin")
155     endif()
156
157     set (3RDPARTY_TCL_DLL "3RDPARTY_TCL_DLL-NOTFOUND" CACHE FILEPATH "TCL shared library" FORCE)
158     find_library (3RDPARTY_TCL_DLL NAMES tcl${3RDPARTY_TCL_LIBRARY_VERSION}
159                                           PATHS "${DLL_FOLDER_FOR_SEARCH}"
160                                           NO_DEFAULT_PATH)
161
162     if (NOT 3RDPARTY_TCL_DLL OR NOT EXISTS "${3RDPARTY_TCL_DLL}")
163       set (3RDPARTY_TCL_DLL "" CACHE FILEPATH "TCL shared library" FORCE)
164     endif()
165   endif()
166   if (NOT 3RDPARTY_TCL_DLL_DIR AND 3RDPARTY_TCL_DLL)
167     get_filename_component (3RDPARTY_TCL_DLL_DIR "${3RDPARTY_TCL_DLL}" PATH)
168     set (3RDPARTY_TCL_DLL_DIR "${3RDPARTY_TCL_DLL_DIR}" CACHE FILEPATH "The directory containing TCL shared library" FORCE)
169   endif()
170 endif()
171
172 # include found paths to common variables
173 if (3RDPARTY_TCL_INCLUDE_DIR AND EXISTS "${3RDPARTY_TCL_INCLUDE_DIR}")
174   list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_TCL_INCLUDE_DIR}")
175 else()
176   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TCL_INCLUDE_DIR)
177 endif()
178
179 if (3RDPARTY_TCL_LIBRARY AND EXISTS "${3RDPARTY_TCL_LIBRARY}")
180   list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_TCL_LIBRARY_DIR}")
181 else()
182   list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TCL_LIBRARY_DIR})
183 endif()
184
185 if (WIN32)
186   if (3RDPARTY_TCL_DLL OR EXISTS "${3RDPARTY_TCL_DLL}")
187     list (APPEND 3RDPARTY_DLL_DIRS "${3RDPARTY_TCL_DLL_DIR}")
188   else()
189     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_TCL_DLL_DIR)
190   endif()
191 endif()
192
193 # install tcl
194 if (INSTALL_TCL)
195   # include occt macros. compiler_bitness, os_wiht_bit, compiler
196   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
197
198   OCCT_MAKE_OS_WITH_BITNESS()
199   OCCT_MAKE_COMPILER_SHORT_NAME()
200
201   if (WIN32)
202     # tcl 8.6 requires zlib. install all dlls from tcl bin folder that may contain zlib also
203
204     # collect and install all dlls from tcl dll dirs
205     file (GLOB TCL_DLLS "${3RDPARTY_TCL_DLL_DIR}/*.dll")
206     install (FILES ${TCL_DLLS}
207              CONFIGURATIONS Release
208              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin")
209     install (FILES ${TCL_DLLS}
210              CONFIGURATIONS RelWithDebInfo
211              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bini")
212     install (FILES ${TCL_DLLS}
213              CONFIGURATIONS Debug
214              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bind")
215   else()
216     get_filename_component(3RDPARTY_TCL_LIBRARY_REALPATH ${3RDPARTY_TCL_LIBRARY} REALPATH)
217     install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
218              CONFIGURATIONS Release
219              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
220     install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
221              CONFIGURATIONS RelWithDebInfo
222              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libi")
223     install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
224              CONFIGURATIONS Debug
225              DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/libd")
226   endif()
227
228   if (TCL_TCLSH_VERSION)
229     # tcl is required to install in lib folder (without)
230     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl8"                    DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
231     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl${TCL_TCLSH_VERSION}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
232   else()
233     message (STATUS "\nWarning: tclX.X subdir won't be copyied during the installation process.")
234     message (STATUS "Try seeking tcl within another folder by changing 3RDPARTY_TCL_DIR variable.")
235   endif()
236
237   set (USED_3RDPARTY_TCL_DIR "")
238 else()
239   # the library directory for using by the executable
240   if (WIN32)
241     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_DLL_DIR})
242   else()
243     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_LIBRARY_DIR})
244   endif()
245 endif()
246
247 mark_as_advanced (3RDPARTY_TCL_LIBRARY 3RDPARTY_TCL_DLL)
248
249 if (TK_FOUND AND 3RDPARTY_TCL_DIR)
250   get_filename_component (3RDPARTY_TK_WISH_DIR "${TK_WISH}" PATH)
251   get_filename_component (3RDPARTY_TK_WISH_DIR_PARENT "${3RDPARTY_TK_WISH_DIR}" PATH)
252   if ("${3RDPARTY_TK_WISH_DIR_PARENT}" STREQUAL "${3RDPARTY_TCL_DIR}")
253     set (3RDPARTY_TCLTK_DIR "${3RDPARTY_TCL_DIR}")
254   endif()
255 endif()
256
257 # unset all redundant variables
258 #TCL
259 OCCT_CHECK_AND_UNSET (TCL_LIBRARY)
260 OCCT_CHECK_AND_UNSET (TCL_INCLUDE_PATH)
261 OCCT_CHECK_AND_UNSET (TCL_TCLSH)
262 #TK
263 OCCT_CHECK_AND_UNSET (TK_LIBRARY)
264 OCCT_CHECK_AND_UNSET (TK_INCLUDE_PATH)
265 OCCT_CHECK_AND_UNSET (TK_WISH)