From 7db669df4013efb41eb455eef692982afba4d40e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Oct 2020 18:29:16 -0400 Subject: [PATCH] add support to also build an extended tcl shell as opposed to dynamically loading the extension --- tools/swig/CMakeLists.txt | 4 +++ tools/swig/lammps.i | 4 +++ tools/swig/run_tcl_example.sh | 62 +++++++++++++++++++++++++++++++++++ tools/swig/tcldummy.c | 5 +++ tools/swig/tclmain.c | 11 ------- 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 tools/swig/tcldummy.c delete mode 100644 tools/swig/tclmain.c diff --git a/tools/swig/CMakeLists.txt b/tools/swig/CMakeLists.txt index 1dd682794d..e818152c03 100644 --- a/tools/swig/CMakeLists.txt +++ b/tools/swig/CMakeLists.txt @@ -84,5 +84,9 @@ if(BUILD_SWIG_TCL) target_include_directories(tcllammps PRIVATE ${TCL_INCLUDE_PATH}) swig_link_libraries(tcllammps PRIVATE lammps ${TCL_LIBRARY}) configure_file(run_tcl_example.sh run_tcl_example.sh COPYONLY) + swig_add_library(libtcllammps TYPE STATIC LANGUAGE tcl SOURCES lammps.i) + add_executable(tcllmpsh tcldummy.c) + target_include_directories(tcllmpsh PRIVATE ${TCL_INCLUDE_PATH}) + target_link_libraries(tcllmpsh PRIVATE libtcllammps lammps ${TCL_LIBRARY}) endif() diff --git a/tools/swig/lammps.i b/tools/swig/lammps.i index e28240b8ef..9358140a08 100644 --- a/tools/swig/lammps.i +++ b/tools/swig/lammps.i @@ -3,6 +3,10 @@ %include "cdata.i" %include "cstring.i" +#ifdef SWIGTCL +%include "tclsh.i" +#endif + %pointer_functions(int, int_p); %pointer_functions(int, int64_p); %pointer_functions(double, double_p); diff --git a/tools/swig/run_tcl_example.sh b/tools/swig/run_tcl_example.sh index b3949192e6..03263ce286 100755 --- a/tools/swig/run_tcl_example.sh +++ b/tools/swig/run_tcl_example.sh @@ -53,3 +53,65 @@ lammps_close \$lmp EOF tclsh example.tcl + +# now try again with static extended shell +echo '=====================================================================' + +if [ ! -f tcllmpsh ] +then \ + echo "Need to compile 'tcllmpsh' first for this script to work" + exit 1 +fi + +cat > example.tcllmp < -int AppInit(Tcl_Interp *interp) { - if (Tcl_Init(interp) == TCL_ERROR) return TCL_ERROR; - Tcl_SetVar(interp,"tcl_rcFileName","~/.wishrc",TCL_GLOBAL_ONLY); - return TCL_OK; -} - -int main(int argc, char *argv[]) { - Tcl_Main(argc, argv, AppInit); - return 0; -}