ENH: fix advanced bug
[cmake.git] / Modules / FindTCL.cmake
blob3810609b55a397cf6013bd2cd3ec880815b8f401
1 # - Find Tcl includes and libraries.
2 # This module finds if Tcl is installed and determines where the
3 # include files and libraries are. It also determines what the name of
4 # the library is. This code sets the following variables:
5 #  TCL_FOUND              = Tcl was found
6 #  TK_FOUND               = Tk was found
7 #  TCLTK_FOUND            = Tcl and Tk were found
8 #  TCL_LIBRARY            = path to Tcl library (tcl tcl80)
9 #  TCL_INCLUDE_PATH       = path to where tcl.h can be found
10 #  TCL_TCLSH              = path to tclsh binary (tcl tcl80)
11 #  TK_LIBRARY             = path to Tk library (tk tk80 etc)
12 #  TK_INCLUDE_PATH        = path to where tk.h can be found
13 #  TK_WISH                = full path to the wish executable
15 # In an effort to remove some clutter and clear up some issues for people
16 # who are not necessarily Tcl/Tk gurus/developpers, some variables were
17 # moved or removed. Changes compared to CMake 2.4 are:
18 # - The stub libraries are now found in FindTclStub.cmake
19 #   => they were only useful for people writing Tcl/Tk extensions.
20 # - TCL_LIBRARY_DEBUG and TK_LIBRARY_DEBUG were removed.
21 #   => these libs are not packaged by default with Tcl/Tk distributions. 
22 #      Even when Tcl/Tk is built from source, several flavors of debug libs
23 #      are created and there is no real reason to pick a single one
24 #      specifically (say, amongst tcl84g, tcl84gs, or tcl84sgx). 
25 #      Let's leave that choice to the user by allowing him to assign 
26 #      TCL_LIBRARY to any Tcl library, debug or not.
27 # - TK_INTERNAL_PATH was removed.
28 #   => this ended up being only a Win32 variable, and there is a lot of
29 #      confusion regarding the location of this file in an installed Tcl/Tk
30 #      tree anyway (see 8.5 for example). If you need the internal path at
31 #      this point it is safer you ask directly where the *source* tree is
32 #      and dig from there.
34 INCLUDE(CMakeFindFrameworks)
35 INCLUDE(FindTclsh)
36 INCLUDE(FindWish)
38 GET_FILENAME_COMPONENT(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
39 GET_FILENAME_COMPONENT(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH)
40 STRING(REGEX REPLACE 
41   "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
43 GET_FILENAME_COMPONENT(TK_WISH_PATH "${TK_WISH}" PATH)
44 GET_FILENAME_COMPONENT(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH)
45 STRING(REGEX REPLACE 
46   "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
48 GET_FILENAME_COMPONENT(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
49 GET_FILENAME_COMPONENT(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
51 GET_FILENAME_COMPONENT(TCL_LIBRARY_PATH "${TCL_LIBRARY}" PATH)
52 GET_FILENAME_COMPONENT(TCL_LIBRARY_PATH_PARENT "${TCL_LIBRARY_PATH}" PATH)
53 STRING(REGEX REPLACE 
54   "^.*tcl([0-9]\\.*[0-9]).*$" "\\1" TCL_LIBRARY_VERSION "${TCL_LIBRARY}")
56 GET_FILENAME_COMPONENT(TK_LIBRARY_PATH "${TK_LIBRARY}" PATH)
57 GET_FILENAME_COMPONENT(TK_LIBRARY_PATH_PARENT "${TK_LIBRARY_PATH}" PATH)
58 STRING(REGEX REPLACE 
59   "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
61 SET(TCLTK_POSSIBLE_LIB_PATHS
62   "${TCL_INCLUDE_PATH_PARENT}/lib"
63   "${TK_INCLUDE_PATH_PARENT}/lib"
64   "${TCL_LIBRARY_PATH}"
65   "${TK_LIBRARY_PATH}"
66   "${TCL_TCLSH_PATH_PARENT}/lib"
67   "${TK_WISH_PATH_PARENT}/lib"
68   /usr/lib 
69   /usr/local/lib
70   )
72 IF(WIN32)
73   GET_FILENAME_COMPONENT(
74     ActiveTcl_CurrentVersion 
75     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl;CurrentVersion]" 
76     NAME)
77   SET(TCLTK_POSSIBLE_LIB_PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
78     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/lib"
79     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/lib"
80     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/lib"
81     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib"
82     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib"
83     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib"
84     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib"
85     "$ENV{ProgramFiles}/Tcl/Lib"
86     "C:/Program Files/Tcl/lib" 
87     "C:/Tcl/lib" 
88     )
89 ENDIF(WIN32)
91 FIND_LIBRARY(TCL_LIBRARY
92   NAMES 
93   tcl   
94   tcl${TK_LIBRARY_VERSION} tcl${TCL_TCLSH_VERSION} tcl${TK_WISH_VERSION}
95   tcl86 tcl8.6 
96   tcl85 tcl8.5 
97   tcl84 tcl8.4 
98   tcl83 tcl8.3 
99   tcl82 tcl8.2 
100   tcl80 tcl8.0
101   PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
102   )
104 FIND_LIBRARY(TK_LIBRARY 
105   NAMES 
106   tk
107   tk${TCL_LIBRARY_VERSION} tk${TCL_TCLSH_VERSION} tk${TK_WISH_VERSION}
108   tk86 tk8.6
109   tk85 tk8.5 
110   tk84 tk8.4 
111   tk83 tk8.3 
112   tk82 tk8.2 
113   tk80 tk8.0
114   PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
115   )
117 CMAKE_FIND_FRAMEWORKS(Tcl)
118 CMAKE_FIND_FRAMEWORKS(Tk)
120 SET(TCL_FRAMEWORK_INCLUDES)
121 IF(Tcl_FRAMEWORKS)
122   IF(NOT TCL_INCLUDE_PATH)
123     FOREACH(dir ${Tcl_FRAMEWORKS})
124       SET(TCL_FRAMEWORK_INCLUDES ${TCL_FRAMEWORK_INCLUDES} ${dir}/Headers)
125     ENDFOREACH(dir)
126   ENDIF(NOT TCL_INCLUDE_PATH)
127 ENDIF(Tcl_FRAMEWORKS)
129 SET(TK_FRAMEWORK_INCLUDES)
130 IF(Tk_FRAMEWORKS)
131   IF(NOT TK_INCLUDE_PATH)
132     FOREACH(dir ${Tk_FRAMEWORKS})
133       SET(TK_FRAMEWORK_INCLUDES ${TK_FRAMEWORK_INCLUDES}
134         ${dir}/Headers ${dir}/PrivateHeaders)
135     ENDFOREACH(dir)
136   ENDIF(NOT TK_INCLUDE_PATH)
137 ENDIF(Tk_FRAMEWORKS)
139 SET(TCLTK_POSSIBLE_INCLUDE_PATHS
140   "${TCL_LIBRARY_PATH_PARENT}/include"
141   "${TK_LIBRARY_PATH_PARENT}/include"
142   "${TCL_INCLUDE_PATH}"
143   "${TK_INCLUDE_PATH}"
144   ${TCL_FRAMEWORK_INCLUDES} 
145   ${TK_FRAMEWORK_INCLUDES} 
146   "${TCL_TCLSH_PATH_PARENT}/include"
147   "${TK_WISH_PATH_PARENT}/include"
148   /usr/include
149   /usr/local/include
150   /usr/include/tcl${TK_LIBRARY_VERSION}
151   /usr/include/tcl${TCL_LIBRARY_VERSION}
152   /usr/include/tcl8.6
153   /usr/include/tcl8.5
154   /usr/include/tcl8.4
155   /usr/include/tcl8.3
156   /usr/include/tcl8.2
157   /usr/include/tcl8.0
158   )
160 IF(WIN32)
161   SET(TCLTK_POSSIBLE_INCLUDE_PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
162     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActiveTcl\\${ActiveTcl_CurrentVersion}]/include"
163     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.6;Root]/include"
164     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.5;Root]/include"
165     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include"
166     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include"
167     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include"
168     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include"
169     "$ENV{ProgramFiles}/Tcl/include"
170     "C:/Program Files/Tcl/include"
171     "C:/Tcl/include"
172     )
173 ENDIF(WIN32)
175 FIND_PATH(TCL_INCLUDE_PATH 
176   NAMES tcl.h
177   PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS} 
178   NO_DEFAULT_PATH
179   )
180 FIND_PATH(TCL_INCLUDE_PATH 
181   NAMES tcl.h
182   PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
183   )
185 FIND_PATH(TK_INCLUDE_PATH 
186   NAMES tk.h
187   PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS} 
188   NO_DEFAULT_PATH
189   )
190 FIND_PATH(TK_INCLUDE_PATH 
191   NAMES tk.h
192   PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
193   )
195 # handle the QUIETLY and REQUIRED arguments and set TCL_FOUND to TRUE if 
196 # all listed variables are TRUE
197 INCLUDE(FindPackageHandleStandardArgs)
199 FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCL DEFAULT_MSG TCL_LIBRARY TCL_INCLUDE_PATH)
200 SET(TCLTK_FIND_REQUIRED ${TCL_FIND_REQUIRED})
201 SET(TCLTK_FIND_QUIETLY  ${TCL_FIND_QUIETLY})
202 FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCLTK DEFAULT_MSG TCL_LIBRARY TCL_INCLUDE_PATH TK_LIBRARY TK_INCLUDE_PATH)
203 SET(TK_FIND_REQUIRED ${TCL_FIND_REQUIRED})
204 SET(TK_FIND_QUIETLY  ${TCL_FIND_QUIETLY})
205 FIND_PACKAGE_HANDLE_STANDARD_ARGS(TK DEFAULT_MSG TK_LIBRARY TK_INCLUDE_PATH)
207 MARK_AS_ADVANCED(
208   TCL_INCLUDE_PATH
209   TK_INCLUDE_PATH
210   TCL_LIBRARY
211   TK_LIBRARY
212   )