Skip to content

Commit

Permalink
Add patching option to try and make Itcl build more robust to missing…
Browse files Browse the repository at this point in the history
… private headers.
  • Loading branch information
starseeker committed Aug 6, 2024
1 parent 4d5e8db commit 1c367b9
Show file tree
Hide file tree
Showing 3 changed files with 8,024 additions and 41 deletions.
45 changes: 42 additions & 3 deletions itcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,52 @@ if (ENABLE_ITCL)

TargetDeps(ITCL)

# If we're building ITCL, it's path setup must take into account the
# subdirectory in which we are storing the library.
# Itcl3 has a problem in that it requires internal Tcl headers.
# Occasionally (but not always) we can get these headers from
# a system include path.
set(HDRS_CANDIDATE_DIR ${TCL_INCLUDE_PATH}8.6/tcl-private)
if (EXISTS ${HDRS_CANDIDATE_DIR})
set(TCL_PRIVATE_HDRS ${HDRS_CANDIDATE_DIR}/generic)
if(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${HDRS_CANDIDATE_DIR}/unix)
else(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${HDRS_CANDIDATE_DIR}/win)
endif(NOT WIN32)
endif (EXISTS ${HDRS_CANDIDATE_DIR})

# If we can't find them from the system, see if we have a local
# clone of Tcl to use
if (NOT TCL_PRIVATE_HDRS AND EXISTS ${CMAKE_SOURCE_DIR}/tcl/tcl)
set(TCL_PRIVATE_HDRS ${TCL_SOURCE_DIR}/generic)
if(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${TCL_SOURCE_DIR}/unix)
else(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${TCL_SOURCE_DIR}/win)
endif(NOT WIN32)
endif (NOT TCL_PRIVATE_HDRS AND EXISTS ${CMAKE_SOURCE_DIR}/tcl/tcl)

# If we STILL don't have anything, patch the Itcl sources to add
# the headers in question
set(TCL_HDRS_PATCH_CMD)
if (NOT TCL_PRIVATE_HDRS)
set(TCL_HDRS_PATCH_CMD ${PATCH_EXECUTABLE};-E;-p1;${PATCH_OPTIONS};-i;${CMAKE_CURRENT_SOURCE_DIR}/tcl_priv_hdrs.patch)
set(TCL_PRIVATE_HDRS "${CMAKE_CURRENT_BINARY_DIR}/ITCL_BLD-prefix/src/ITCL_BLD/tcl_hdrs")
if(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${TCL_PRIVATE_HDRS}/unix)
else(NOT WIN32)
set(TCL_PRIVATE_HDRS_OS ${TCL_PRIVATE_HDRS}/win)
endif(NOT WIN32)
endif (NOT TCL_PRIVATE_HDRS)

# When building ITCL, its path setup must take into account the subdirectory
# in which we are storing the library.
set(RPATH_SUFFIX itcl3.4)

ExternalProject_Add(ITCL_BLD
URL "${CMAKE_CURRENT_SOURCE_DIR}/itcl"
BUILD_ALWAYS ${EXT_BUILD_ALWAYS} ${LOG_OPTS}
PATCH_COMMAND ${PATCH_EXECUTABLE};-E;-p1;${PATCH_OPTIONS};-i;${CMAKE_CURRENT_SOURCE_DIR}/itcl.patch
COMMAND ${TCL_HDRS_PATCH_CMD}
CMAKE_ARGS
${BUILD_TYPE_SPECIFIER}
-DBIN_DIR=$<IF:$<BOOL:${WIN32}>,${LIB_DIR},${BIN_DIR}>
Expand All @@ -48,7 +86,8 @@ if (ENABLE_ITCL)
-DSHARED_DIR=${LIB_DIR}
-DTCL_ENABLE_TK=ON
-DTCL_ROOT=$<$<BOOL:${TCL_TARGET}>:${CMAKE_BUNDLE_INSTALL_PREFIX}>
-DTCL_SOURCE_DIR=${CMAKE_SOURCE_DIR}/tcl/tcl
-DTCL_PRIVATE_HDRS=${TCL_PRIVATE_HDRS}
-DTCL_PRIVATE_HDRS_OS=${TCL_PRIVATE_HDRS_OS}
LOG_CONFIGURE ${EXT_BUILD_QUIET}
LOG_BUILD ${EXT_BUILD_QUIET}
LOG_INSTALL ${EXT_BUILD_QUIET}
Expand Down
56 changes: 18 additions & 38 deletions itcl/itcl.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -Naur itcl/CMake/FindTCL.cmake ITCL_BLD/CMake/FindTCL.cmake
--- itcl/CMake/FindTCL.cmake 1969-12-31 19:00:00.000000000 -0500
+++ ITCL_BLD/CMake/FindTCL.cmake 2024-02-16 18:52:59.757617957 -0500
+++ ITCL_BLD/CMake/FindTCL.cmake 2024-08-06 13:12:35.229286326 -0400
@@ -0,0 +1,496 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
Expand Down Expand Up @@ -500,8 +500,8 @@ diff -Naur itcl/CMake/FindTCL.cmake ITCL_BLD/CMake/FindTCL.cmake
+# ex: shiftwidth=2 tabstop=8
diff -Naur itcl/CMakeLists.txt ITCL_BLD/CMakeLists.txt
--- itcl/CMakeLists.txt 1969-12-31 19:00:00.000000000 -0500
+++ ITCL_BLD/CMakeLists.txt 2024-02-16 19:04:42.805398844 -0500
@@ -0,0 +1,243 @@
+++ ITCL_BLD/CMakeLists.txt 2024-08-06 13:14:14.013768111 -0400
@@ -0,0 +1,223 @@
+# C M A K E L I S T S . T X T
+# ITCL
+#
Expand Down Expand Up @@ -672,36 +672,16 @@ diff -Naur itcl/CMakeLists.txt ITCL_BLD/CMakeLists.txt
+set(ITCL_INCLUDE_PATH ${ITCL_SOURCE_DIR}/generic ${ITCL_BINARY_DIR}/include)
+mark_as_advanced(ITCL_INCLUDE_PATH)
+
+# At least one Linux distro puts what we need here
+set(HDRS_CANDIDATE_DIR ${TCL_INCLUDE_PATH}8.6/tcl-private)
+if (EXISTS ${HDRS_CANDIDATE_DIR})
+ set(TCL_PRIVATE_HDRS ${HDRS_CANDIDATE_DIR}/generic)
+ if(NOT WIN32)
+ set(TCL_PRIVATE_HDRS ${TCL_PRIVATE_HDRS} ${HDRS_CANDIDATE_DIR}/unix)
+ else(NOT WIN32)
+ set(TCL_PRIVATE_HDRS ${TCL_PRIVATE_HDRS} ${HDRS_CANDIDATE_DIR}/win)
+ endif(NOT WIN32)
+endif ()
+
+# ITcl requires private Tcl headers, which we can't assume from a system
+# install of Tcl. The fallback is to use our local copies and hope they
+# work. (Ugh.)
+if (NOT TCL_PRIVATE_HDRS)
+ if (NOT DEFINED TCL_SOURCE_DIR)
+ message(FATAL_ERROR "Itcl3 needs to know where to find the Tcl source directory")
+ endif (NOT DEFINED TCL_SOURCE_DIR)
+ set(TCL_PRIVATE_HDRS ${TCL_SOURCE_DIR}/generic)
+ if(NOT WIN32)
+ set(TCL_PRIVATE_HDRS ${TCL_PRIVATE_HDRS} ${TCL_SOURCE_DIR}/unix)
+ else(NOT WIN32)
+ set(TCL_PRIVATE_HDRS ${TCL_PRIVATE_HDRS} ${TCL_SOURCE_DIR}/win)
+ endif(NOT WIN32)
+endif (NOT TCL_PRIVATE_HDRS)
+# ITcl requires private Tcl headers, which we can't always assume from a system
+# install of Tcl. Require the build to tell us where to look
+if (NOT DEFINED TCL_PRIVATE_HDRS)
+ message(FATAL_ERROR "Itcl3 needs to know where to find the Tcl private headers")
+endif (NOT DEFINED TCL_PRIVATE_HDRS)
+
+include_directories(
+ ${TCL_INCLUDE_PATH}
+ ${ITCL_INCLUDE_PATH}
+ ${TCL_PRIVATE_HDRS}
+ ${TCL_PRIVATE_HDRS};${TCL_PRIVATE_HDRS_OS}
+ )
+
+add_library(itcl${ITCL_VERSION} SHARED ${ITCL_SRCS})
Expand Down Expand Up @@ -746,8 +726,8 @@ diff -Naur itcl/CMakeLists.txt ITCL_BLD/CMakeLists.txt
+# ex: shiftwidth=2 tabstop=8
+
diff -Naur itcl/generic/itcl_cmds.c ITCL_BLD/generic/itcl_cmds.c
--- itcl/generic/itcl_cmds.c 2024-02-16 19:03:13.054947128 -0500
+++ ITCL_BLD/generic/itcl_cmds.c 2024-02-16 18:47:06.635909397 -0500
--- itcl/generic/itcl_cmds.c 2024-08-06 13:13:08.429776852 -0400
+++ ITCL_BLD/generic/itcl_cmds.c 2024-08-06 13:12:35.230286310 -0400
@@ -53,9 +53,6 @@
if {[info exists library]} {\n\
lappend dirs $library\n\
Expand Down Expand Up @@ -777,8 +757,8 @@ diff -Naur itcl/generic/itcl_cmds.c ITCL_BLD/generic/itcl_cmds.c
result = TCL_ERROR;
goto scopeCmdDone;
diff -Naur itcl/generic/itclInt.decls ITCL_BLD/generic/itclInt.decls
--- itcl/generic/itclInt.decls 2024-02-16 19:03:13.050947197 -0500
+++ ITCL_BLD/generic/itclInt.decls 2024-02-16 18:47:06.635909397 -0500
--- itcl/generic/itclInt.decls 2024-08-06 13:13:08.429776852 -0400
+++ ITCL_BLD/generic/itclInt.decls 2024-08-06 13:12:35.230286310 -0400
@@ -252,7 +252,7 @@
CONST char* arglist, CONST char* body, ItclMemberCode** mcodePtr)
}
Expand All @@ -789,8 +769,8 @@ diff -Naur itcl/generic/itclInt.decls ITCL_BLD/generic/itclInt.decls
declare 59 generic {
int Itcl_GetMemberCode (Tcl_Interp* interp, ItclMember* member)
diff -Naur itcl/generic/itclIntDecls.h ITCL_BLD/generic/itclIntDecls.h
--- itcl/generic/itclIntDecls.h 2024-02-16 19:03:13.054947128 -0500
+++ ITCL_BLD/generic/itclIntDecls.h 2024-02-16 18:47:06.635909397 -0500
--- itcl/generic/itclIntDecls.h 2024-08-06 13:13:08.429776852 -0400
+++ ITCL_BLD/generic/itclIntDecls.h 2024-08-06 13:12:35.230286310 -0400
@@ -410,7 +410,7 @@
#ifndef Itcl_DeleteMemberCode_TCL_DECLARED
#define Itcl_DeleteMemberCode_TCL_DECLARED
Expand All @@ -810,8 +790,8 @@ diff -Naur itcl/generic/itclIntDecls.h ITCL_BLD/generic/itclIntDecls.h
void *reserved60;
int (*itcl_EvalMemberCode) _ANSI_ARGS_((Tcl_Interp * interp, ItclMemberFunc * mfunc, ItclMember * member, ItclObject * contextObj, int objc, Tcl_Obj *CONST objv[])); /* 61 */
diff -Naur itcl/generic/itcl_methods.c ITCL_BLD/generic/itcl_methods.c
--- itcl/generic/itcl_methods.c 2024-02-16 19:03:13.054947128 -0500
+++ ITCL_BLD/generic/itcl_methods.c 2024-02-16 18:47:06.635909397 -0500
--- itcl/generic/itcl_methods.c 2024-08-06 13:13:08.429776852 -0400
+++ ITCL_BLD/generic/itcl_methods.c 2024-08-06 13:12:35.230286310 -0400
@@ -731,8 +731,7 @@
* ------------------------------------------------------------------------
*/
Expand All @@ -833,7 +813,7 @@ diff -Naur itcl/generic/itcl_methods.c ITCL_BLD/generic/itcl_methods.c
localPtr->nextPtr = NULL;
diff -Naur itcl/win/itcl.rc ITCL_BLD/win/itcl.rc
--- itcl/win/itcl.rc 1969-12-31 19:00:00.000000000 -0500
+++ ITCL_BLD/win/itcl.rc 2024-02-16 18:47:06.635909397 -0500
+++ ITCL_BLD/win/itcl.rc 2024-08-06 13:12:35.230286310 -0400
@@ -0,0 +1,55 @@
+//
+// Version resource script.
Expand Down
Loading

0 comments on commit 1c367b9

Please sign in to comment.