0032315: Configuration, CMake - fix building Draw Harness plugins as static libraries
[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
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
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 # tcl dir and library
68 if (NOT 3RDPARTY_TCL_LIBRARY)
69   if (TCL_LIBRARY AND EXISTS "${TCL_LIBRARY}")
70     set (3RDPARTY_TCL_LIBRARY "${TCL_LIBRARY}" CACHE FILEPATH "TCL library" FORCE)
71
72     if (NOT 3RDPARTY_TCL_LIBRARY_DIR)
73       get_filename_component (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY}" PATH)
74       set (3RDPARTY_TCL_LIBRARY_DIR "${3RDPARTY_TCL_LIBRARY_DIR}" CACHE FILEPATH "The directory containing TCL library" FORCE)
75     endif()
76   endif()
77 endif()
78
79 if (WIN32)
80   if (NOT 3RDPARTY_TCL_DLL)
81     set (CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll .a)
82
83     set (DLL_FOLDER_FOR_SEARCH "")
84     if (3RDPARTY_TCL_DLL_DIR)
85       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DLL_DIR}")
86     elseif (3RDPARTY_TCL_DIR)
87       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_DIR}/bin")
88     elseif (3RDPARTY_TCL_LIBRARY_DIR)
89       get_filename_component (3RDPARTY_TCL_LIBRARY_DIR_PARENT "${3RDPARTY_TCL_LIBRARY_DIR}" PATH)
90       set (DLL_FOLDER_FOR_SEARCH "${3RDPARTY_TCL_LIBRARY_DIR_PARENT}/bin")
91     endif()
92
93     set (3RDPARTY_TCL_DLL "3RDPARTY_TCL_DLL-NOTFOUND" CACHE FILEPATH "TCL shared library" FORCE)
94     find_library (3RDPARTY_TCL_DLL NAMES ${CSF_TclLibs}
95                                          PATHS "${DLL_FOLDER_FOR_SEARCH}"
96                                          NO_DEFAULT_PATH)
97   endif()
98 endif()
99
100 COMPLIANCE_PRODUCT_CONSISTENCY(TCL)
101
102 # tcl dir and library
103 if (NOT 3RDPARTY_TCL_LIBRARY)
104   set (3RDPARTY_TCL_LIBRARY "3RDPARTY_TCL_LIBRARY-NOTFOUND" CACHE FILEPATH "TCL library" FORCE)
105   find_library (3RDPARTY_TCL_LIBRARY NAMES ${CSF_TclLibs}
106                                            PATHS "${3RDPARTY_TCL_LIBRARY_DIR}"
107                                            NO_DEFAULT_PATH)
108
109   # search in another place if previous search doesn't find anything
110   find_library (3RDPARTY_TCL_LIBRARY NAMES ${CSF_TclLibs}
111                                            PATHS "${3RDPARTY_TCL_DIR}/lib"
112                                            NO_DEFAULT_PATH)
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 .a)
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_NO_LIBS 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_NO_DLLS 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
207     if (SINGLE_GENERATOR)
208       install (FILES ${TCL_DLLS} DESTINATION "${INSTALL_DIR_BIN}")
209     else()
210       install (FILES ${TCL_DLLS}
211                CONFIGURATIONS Release
212                DESTINATION "${INSTALL_DIR_BIN}")
213       install (FILES ${TCL_DLLS}
214                CONFIGURATIONS RelWithDebInfo
215                DESTINATION "${INSTALL_DIR_BIN}i")
216       install (FILES ${TCL_DLLS}
217                CONFIGURATIONS Debug
218                DESTINATION "${INSTALL_DIR_BIN}d")
219     endif()
220   else()
221     get_filename_component(3RDPARTY_TCL_LIBRARY_REALPATH ${3RDPARTY_TCL_LIBRARY} REALPATH)
222
223     if (SINGLE_GENERATOR)
224       install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH} DESTINATION "${INSTALL_DIR_LIB}")
225     else()
226       install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
227                CONFIGURATIONS Release
228                DESTINATION "${INSTALL_DIR_LIB}")
229       install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
230                CONFIGURATIONS RelWithDebInfo
231                DESTINATION "${INSTALL_DIR_LIB}i")
232       install (FILES ${3RDPARTY_TCL_LIBRARY_REALPATH}
233                CONFIGURATIONS Debug
234                DESTINATION "${INSTALL_DIR_LIB}d")
235     endif()
236   endif()
237
238   if (TCL_TCLSH_VERSION)
239     # tcl is required to install in lib folder (without)
240     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl8"                    DESTINATION "${INSTALL_DIR_LIB}")
241     install (DIRECTORY "${3RDPARTY_TCL_LIBRARY_DIR}/tcl${TCL_TCLSH_VERSION}" DESTINATION "${INSTALL_DIR_LIB}")
242   else()
243     message (STATUS "\nWarning: tclX.X subdir won't be copied during the installation process.")
244     message (STATUS "Try seeking tcl within another folder by changing 3RDPARTY_TCL_DIR variable.")
245   endif()
246
247   set (USED_3RDPARTY_TCL_DIR "")
248 else()
249   # the library directory for using by the executable
250   if (WIN32)
251     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_DLL_DIR})
252   else()
253     set (USED_3RDPARTY_TCL_DIR ${3RDPARTY_TCL_LIBRARY_DIR})
254   endif()
255 endif()
256
257 mark_as_advanced (3RDPARTY_TCL_LIBRARY 3RDPARTY_TCL_DLL)
258
259 if (TK_FOUND AND 3RDPARTY_TCL_DIR)
260
261   get_filename_component (TK_WISH_ABSOLUTE          "${TK_WISH}"          ABSOLUTE)
262   get_filename_component (3RDPARTY_TCL_DIR_ABSOLUTE "${3RDPARTY_TCL_DIR}" ABSOLUTE)
263
264   string (FIND "${TK_WISH_ABSOLUTE}" "${3RDPARTY_TCL_DIR_ABSOLUTE}" THE_SAME_FOLDER)
265
266   if (${THE_SAME_FOLDER} EQUAL 0)
267     set (3RDPARTY_TCLTK_DIR "${3RDPARTY_TCL_DIR}")
268     message (STATUS "Info: TK is used from TCL folder: ${3RDPARTY_TCLTK_DIR}")
269   endif()
270 endif()
271
272 # unset all redundant variables
273 #TCL
274 OCCT_CHECK_AND_UNSET (TCL_LIBRARY)
275 OCCT_CHECK_AND_UNSET (TCL_INCLUDE_PATH)
276 OCCT_CHECK_AND_UNSET (TCL_TCLSH)
277 #TK
278 OCCT_CHECK_AND_UNSET (TK_LIBRARY)
279 OCCT_CHECK_AND_UNSET (TK_INCLUDE_PATH)
280 OCCT_CHECK_AND_UNSET (TK_WISH)
281