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