0025114: CMake-based build tools for OCCT 7.0
[occt.git] / adm / cmake / tcl.cmake
1 # tcl
2
3 if (NOT DEFINED INSTALL_TCL)
4   set (INSTALL_TCL OFF CACHE BOOL "Is tcl lib required to be copied into install directory")
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 # tk include directory
18 if (NOT DEFINED 3RDPARTY_TK_INCLUDE_DIR)
19   set (3RDPARTY_TK_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of tk")
20 endif()
21
22 # tcl library file (with absolute path)
23 if (NOT DEFINED 3RDPARTY_TCL_LIBRARY OR NOT 3RDPARTY_TCL_LIBRARY_DIR)
24   set (3RDPARTY_TCL_LIBRARY "" CACHE FILEPATH "tcl library"  FORCE)
25 endif()
26
27 # tcl library directory
28 if (NOT DEFINED 3RDPARTY_TCL_LIBRARY_DIR)
29   set (3RDPARTY_TCL_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tcl library")
30 endif()
31
32 # tk library file (with absolute path)
33 if (NOT DEFINED 3RDPARTY_TK_LIBRARY OR NOT 3RDPARTY_TK_LIBRARY_DIR)
34   set (3RDPARTY_TK_LIBRARY "" CACHE FILEPATH "tk library" FORCE)
35 endif()
36
37 # tk library directory
38 if (NOT DEFINED 3RDPARTY_TK_LIBRARY_DIR)
39   set (3RDPARTY_TK_LIBRARY_DIR "" CACHE FILEPATH "The directory containing tk library")
40 endif()
41
42 # tcl shared library (with absolute path)
43 if (WIN32)
44   if (NOT DEFINED 3RDPARTY_TCL_DLL OR NOT 3RDPARTY_TCL_DLL_DIR)
45     set (3RDPARTY_TCL_DLL "" CACHE FILEPATH "tcl shared library" FORCE)
46   endif()
47 endif()
48
49 # tcl shared library directory
50 if (WIN32 AND NOT DEFINED 3RDPARTY_TCL_DLL_DIR)
51   set (3RDPARTY_TCL_DLL_DIR "" CACHE FILEPATH "The directory containing tcl shared library")
52 endif()
53
54 # tk shared library (with absolute path)
55 if (WIN32)
56   if (NOT DEFINED 3RDPARTY_TK_DLL OR NOT 3RDPARTY_TK_DLL_DIR)
57     set (3RDPARTY_TK_DLL "" CACHE FILEPATH "tk shared library" FORCE)
58   endif()
59 endif()
60
61 # tk shared library directory
62 if (WIN32 AND NOT DEFINED 3RDPARTY_TK_DLL_DIR)
63   set (3RDPARTY_TK_DLL_DIR "" CACHE FILEPATH "The directory containing tk shared library")
64 endif()
65
66 # search for tcl in user defined directory
67 if (NOT 3RDPARTY_TCL_DIR AND 3RDPARTY_DIR)
68   FIND_PRODUCT_DIR("${3RDPARTY_DIR}" tcl TCL_DIR_NAME)
69   if (TCL_DIR_NAME)
70     set (3RDPARTY_TCL_DIR "${3RDPARTY_DIR}/${TCL_DIR_NAME}" CACHE PATH "The directory containing tcl" FORCE)
71   endif()
72 endif()
73
74 # define paths for default engine
75 if (3RDPARTY_TCL_DIR AND EXISTS "${3RDPARTY_TCL_DIR}")
76   set (TCL_INCLUDE_PATH "${3RDPARTY_TCL_DIR}/include")
77 endif()
78
79 # check tcl/tk include dir, library dir and shared library dir
80 macro (DIR_SUBDIR_FILE_FIT LIBNAME)
81   if (3RDPARTY_TCL_DIR AND EXISTS "${3RDPARTY_TCL_DIR}")
82     # tcl/tk include dir
83     if (3RDPARTY_${LIBNAME}_INCLUDE_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
84       string (REGEX MATCH "${3RDPARTY_TCL_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
85       if (NOT DOES_PATH_CONTAIN)
86         set (3RDPARTY_${LIBNAME}_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of ${LIBNAME}" FORCE)
87       endif()
88     else()
89       set (3RDPARTY_${LIBNAME}_INCLUDE_DIR "" CACHE FILEPATH "The directory containing headers of ${LIBNAME}" FORCE)
90     endif()
91
92     # tcl/tk library dir
93     if (3RDPARTY_${LIBNAME}_LIBRARY_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
94
95       string (REGEX MATCH "${3RDPARTY_TCL_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
96       if (NOT DOES_PATH_CONTAIN)
97         set (3RDPARTY_${LIBNAME}_LIBRARY_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} library" FORCE)
98       endif()
99     else()
100       set (3RDPARTY_${LIBNAME}_LIBRARY_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} library" FORCE)
101     endif()
102
103     # tcl/tk shared library dir
104     if (WIN32)
105       if (3RDPARTY_${LIBNAME}_DLL_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_DLL_DIR}")
106         string (REGEX MATCH "${3RDPARTY_TCL_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_DLL_DIR}")
107         if (NOT DOES_PATH_CONTAIN)
108           set (3RDPARTY_${LIBNAME}_DLL_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} shared library" FORCE)
109         endif()
110       else()
111         set (3RDPARTY_${LIBNAME}_DLL_DIR "" CACHE FILEPATH "The directory containing ${LIBNAME} shared library" FORCE)
112       endif()
113     endif()
114   endif()
115
116   # check tcl/tk library
117   if (3RDPARTY_${LIBNAME}_LIBRARY_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
118     if (3RDPARTY_${LIBNAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY}")
119       string (REGEX MATCH "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_LIBRARY}")
120
121       if (NOT DOES_PATH_CONTAIN)
122         set (3RDPARTY_${LIBNAME}_LIBRARY "" CACHE FILEPATH "${LIBNAME} library" FORCE)
123       endif()
124     else()
125       set (3RDPARTY_${LIBNAME}_LIBRARY "" CACHE FILEPATH "${LIBNAME} library" FORCE)
126     endif()
127   else()
128     set (3RDPARTY_${LIBNAME}_LIBRARY "" CACHE FILEPATH "${LIBNAME} library" FORCE)
129   endif()
130
131   # check tcl/tk shared library
132   if (WIN32)
133     if (3RDPARTY_${LIBNAME}_DLL_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_DLL_DIR}")
134       if (3RDPARTY_${LIBNAME}_DLL AND EXISTS "${3RDPARTY_${LIBNAME}_DLL}")
135         string (REGEX MATCH "${3RDPARTY_${LIBNAME}_DLL_DIR}" DOES_PATH_CONTAIN "${3RDPARTY_${LIBNAME}_DLL}")
136
137         if (NOT DOES_PATH_CONTAIN)
138           set (3RDPARTY_${LIBNAME}_DLL "" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
139         endif()
140       else()
141         set (3RDPARTY_${LIBNAME}_DLL "" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
142       endif()
143     else()
144       set (3RDPARTY_${LIBNAME}_DLL "" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
145     endif()
146   endif()
147 endmacro()
148
149
150 DIR_SUBDIR_FILE_FIT(TCL)
151 DIR_SUBDIR_FILE_FIT(TK)
152
153
154 # use default (CMake) TCL search
155 find_package(TCL)
156
157 foreach (LIBNAME TCL TK)
158   string (TOLOWER "${LIBNAME}" LIBNAME_L)
159
160   # tcl/tk include dir
161   if (NOT 3RDPARTY_${LIBNAME}_INCLUDE_DIR)
162     if (${LIBNAME}_INCLUDE_PATH AND EXISTS "${${LIBNAME}_INCLUDE_PATH}")
163       set (3RDPARTY_${LIBNAME}_INCLUDE_DIR "${${LIBNAME}_INCLUDE_PATH}" CACHE FILEPATH "The directory containing headers of ${LIBNAME}" FORCE)
164     endif()
165   endif()
166
167   # tcl/tk dir and library
168   if (NOT 3RDPARTY_${LIBNAME}_LIBRARY)
169     if (${LIBNAME}_LIBRARY AND EXISTS "${${LIBNAME}_LIBRARY}")
170       set (3RDPARTY_${LIBNAME}_LIBRARY "${${LIBNAME}_LIBRARY}" CACHE FILEPATH "${LIBNAME} library" FORCE)
171
172       if (NOT 3RDPARTY_${LIBNAME}_LIBRARY_DIR)
173         get_filename_component (3RDPARTY_${LIBNAME}_LIBRARY_DIR "${3RDPARTY_${LIBNAME}_LIBRARY}" PATH)
174         set (3RDPARTY_${LIBNAME}_LIBRARY_DIR "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${LIBNAME} library" FORCE)
175       endif()
176     endif()
177   endif()
178
179
180   if (WIN32)
181     if (NOT 3RDPARTY_${LIBNAME}_DLL)
182         set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
183
184         set (DLL_FOLDER_FOR_SEARCH "")
185         if (3RDPARTY_${LIBNAME}_DLL_DIR)
186           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_${LIBNAME}_DLL_DIR}")
187         elseif (3RDPARTY_TCL_DIR)
188           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DIR}/bin")
189         elseif (3RDPARTY_${LIBNAME}_LIBRARY_DIR)
190           get_filename_component (3RDPARTY_${LIBNAME}_LIBRARY_DIR_PARENT "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" PATH)
191           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_${LIBNAME}_LIBRARY_DIR_PARENT}/bin")
192         endif()
193
194         set (3RDPARTY_${LIBNAME}_DLL "3RDPARTY_${LIBNAME}_DLL-NOTFOUND" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
195         find_library (3RDPARTY_${LIBNAME}_DLL NAMES ${LIBNAME_L}86 ${LIBNAME_L}85
196                                               PATHS "${DLL_FOLDER_FOR_SEARCH}"
197                                               NO_DEFAULT_PATH)
198     endif()
199   endif()
200
201   DIR_SUBDIR_FILE_FIT(${LIBNAME})
202
203
204   # tcl/tk dir and library
205   if (NOT 3RDPARTY_${LIBNAME}_LIBRARY)
206     set (3RDPARTY_${LIBNAME}_LIBRARY "3RDPARTY_${LIBNAME}_LIBRARY-NOTFOUND" CACHE FILEPATH "${LIBNAME} library" FORCE)
207     find_library (3RDPARTY_${LIBNAME}_LIBRARY NAMES ${LIBNAME_L}8.6 ${LIBNAME_L}86 ${LIBNAME_L}8.5 ${LIBNAME_L}85
208                                               PATHS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}"
209                                               NO_DEFAULT_PATH)
210
211     # search in another place if previous search doesn't find anything
212     find_library (3RDPARTY_${LIBNAME}_LIBRARY NAMES ${LIBNAME_L}8.6 ${LIBNAME_L}86 ${LIBNAME_L}8.5 ${LIBNAME_L}85
213                                               PATHS "${3RDPARTY_TCL_DIR}/lib"
214                                               NO_DEFAULT_PATH)
215
216
217     if (NOT 3RDPARTY_${LIBNAME}_LIBRARY OR NOT EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY}")
218       set (3RDPARTY_${LIBNAME}_LIBRARY "" CACHE FILEPATH "${LIBNAME} library" FORCE)
219     endif()
220
221     if (NOT 3RDPARTY_${LIBNAME}_LIBRARY_DIR AND 3RDPARTY_${LIBNAME}_LIBRARY)
222       get_filename_component (3RDPARTY_${LIBNAME}_LIBRARY_DIR "${3RDPARTY_${LIBNAME}_LIBRARY}" PATH)
223       set (3RDPARTY_${LIBNAME}_LIBRARY_DIR "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" CACHE FILEPATH "The directory containing ${LIBNAME} library" FORCE)
224     endif()
225   endif()
226
227   set (3RDPARTY_${LIBNAME}_LIBRARY_VERSION "")
228   if (3RDPARTY_${LIBNAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY}")
229     get_filename_component (${LIBNAME}_LIBRARY_NAME "${3RDPARTY_${LIBNAME}_LIBRARY}" NAME)
230     string(REGEX REPLACE "^.*${LIBNAME_L}([0-9]\\.*[0-9]).*$" "\\1" ${LIBNAME}_LIBRARY_VERSION "${${LIBNAME}_LIBRARY_NAME}")
231
232     if (NOT "${${LIBNAME}_LIBRARY_VERSION}" STREQUAL "${${LIBNAME}_LIBRARY_NAME}")
233       set (3RDPARTY_${LIBNAME}_LIBRARY_VERSION "${${LIBNAME}_LIBRARY_VERSION}")
234     else() # if the version isn't found - seek other library with 8.6 or 8.5 version in the same dir
235       message (STATUS "Info: ${LIBNAME} version isn't found")
236     endif()
237   endif()
238
239
240   set (3RDPARTY_${LIBNAME}_LIBRARY_VERSION_WITH_DOT "")
241   if (3RDPARTY_${LIBNAME}_LIBRARY_VERSION)
242     string (REGEX REPLACE "^.*([0-9])[^0-9]*[0-9].*$" "\\1" 3RDPARTY_${LIBNAME}_MAJOR_VERSION "${3RDPARTY_${LIBNAME}_LIBRARY_VERSION}")
243     string (REGEX REPLACE "^.*[0-9][^0-9]*([0-9]).*$" "\\1" 3RDPARTY_${LIBNAME}_MINOR_VERSION "${3RDPARTY_${LIBNAME}_LIBRARY_VERSION}")
244     set (3RDPARTY_${LIBNAME}_LIBRARY_VERSION_WITH_DOT "${3RDPARTY_${LIBNAME}_MAJOR_VERSION}.${3RDPARTY_${LIBNAME}_MINOR_VERSION}")
245   endif()
246
247   if (WIN32)
248     if (NOT 3RDPARTY_${LIBNAME}_DLL)
249         set (CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
250
251         set (DLL_FOLDER_FOR_SEARCH "")
252         if (3RDPARTY_${LIBNAME}_DLL_DIR)
253           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_${LIBNAME}_DLL_DIR}")
254         elseif (3RDPARTY_TCL_DIR)
255           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DIR}/bin")
256         else()
257           get_filename_component (3RDPARTY_${LIBNAME}_LIBRARY_DIR_PARENT "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}" PATH)
258           set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_${LIBNAME}_LIBRARY_DIR_PARENT}/bin")
259         endif()
260
261         set (3RDPARTY_${LIBNAME}_DLL "3RDPARTY_${LIBNAME}_DLL-NOTFOUND" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
262         find_library (3RDPARTY_${LIBNAME}_DLL NAMES ${LIBNAME_L}${3RDPARTY_${LIBNAME}_LIBRARY_VERSION}
263                                               PATHS "${DLL_FOLDER_FOR_SEARCH}"
264                                               NO_DEFAULT_PATH)
265
266         if (NOT 3RDPARTY_${LIBNAME}_DLL OR NOT EXISTS "${3RDPARTY_${LIBNAME}_DLL}")
267           set (3RDPARTY_${LIBNAME}_DLL "" CACHE FILEPATH "${LIBNAME} shared library" FORCE)
268         endif()
269
270         if (NOT 3RDPARTY_${LIBNAME}_DLL_DIR AND 3RDPARTY_${LIBNAME}_DLL)
271           get_filename_component (3RDPARTY_${LIBNAME}_DLL_DIR "${3RDPARTY_${LIBNAME}_DLL}" PATH)
272           set (3RDPARTY_${LIBNAME}_DLL_DIR "${3RDPARTY_${LIBNAME}_DLL_DIR}" CACHE FILEPATH "The directory containing ${LIBNAME} shared library" FORCE)
273         endif()
274     endif()
275   endif()
276
277   # include found paths to common variables
278   if (3RDPARTY_${LIBNAME}_INCLUDE_DIR AND EXISTS "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
279     list (APPEND 3RDPARTY_INCLUDE_DIRS "${3RDPARTY_${LIBNAME}_INCLUDE_DIR}")
280   else()
281     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBNAME}_INCLUDE_DIR)
282   endif()
283
284   if (3RDPARTY_${LIBNAME}_LIBRARY AND EXISTS "${3RDPARTY_${LIBNAME}_LIBRARY}")
285     list (APPEND 3RDPARTY_LIBRARY_DIRS "${3RDPARTY_${LIBNAME}_LIBRARY_DIR}")
286   else()
287     list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBNAME}_LIBRARY_DIR})
288   endif()
289
290   if (WIN32)
291     if (NOT 3RDPARTY_${LIBNAME}_DLL OR NOT EXISTS "${3RDPARTY_${LIBNAME}_DLL}")
292       list (APPEND 3RDPARTY_NOT_INCLUDED 3RDPARTY_${LIBNAME}_DLL_DIR)
293     endif()
294   endif()
295 endforeach()
296
297 # install tcltk
298 if (INSTALL_TCL)
299   # include occt macros. compiler_bitness, os_wiht_bit, compiler and build_postfix
300   OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")
301
302   OCCT_MAKE_OS_WITH_BITNESS()
303   OCCT_MAKE_COMPILER_SHORT_NAME()
304   OCCT_MAKE_BUILD_POSTFIX()
305
306   if (WIN32)
307     install (FILES ${3RDPARTY_TCL_DLL} ${3RDPARTY_TK_DLL} DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BUILD_POSTFIX}")
308         install (FILES ${3RDPARTY_TCL_DLL_DIR}/zlib1.dll DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/bin${BUILD_POSTFIX}")
309   else()
310         get_filename_component(ABS_PATH ${3RDPARTY_TCL_LIBRARY} REALPATH)
311     install (FILES ${ABS_PATH} DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BUILD_POSTFIX}")
312         get_filename_component(ABS_PATH ${3RDPARTY_TK_LIBRARY} REALPATH)
313         install (FILES ${ABS_PATH} DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib${BUILD_POSTFIX}")
314   endif()
315
316   if (TCL_TCLSH_VERSION)
317     # tcl is required to install in lib folder (without ${BUILD_POSTFIX})
318     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl8"                    DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
319     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl${TCL_TCLSH_VERSION}" DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
320     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tk${TCL_TCLSH_VERSION}"  DESTINATION "${INSTALL_DIR}/${OS_WITH_BIT}/${COMPILER}/lib")
321   else()
322     message (STATUS "\nWarning: tclX.X and tkX.X subdirs won't be copyied during the installation process.")
323     message (STATUS "Try seeking tcl within another folder by changing 3RDPARTY_TCL_DIR variable.")
324   endif()
325
326   set (USED_3RDPARTY_TCL_DIR "")
327 else()
328   # the library directory for using by the executable
329   if (WIN32)
330     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_DLL_DIR})
331   else()
332     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_LIBRARY_DIR})
333   endif()
334 endif()
335
336 mark_as_advanced (3RDPARTY_TCL_LIBRARY 3RDPARTY_TK_LIBRARY 3RDPARTY_TCL_DLL 3RDPARTY_TK_DLL)
337
338 # unset all redundant variables
339 #TCL
340 OCCT_CHECK_AND_UNSET (TCL_LIBRARY)
341 OCCT_CHECK_AND_UNSET (TCL_INCLUDE_PATH)
342 OCCT_CHECK_AND_UNSET (TCL_TCLSH)
343 #TK
344 OCCT_CHECK_AND_UNSET (TK_LIBRARY)
345 OCCT_CHECK_AND_UNSET (TK_INCLUDE_PATH)
346 OCCT_CHECK_AND_UNSET (TK_WISH)