Skip to content

Commit b73c713

Browse files
authored
Enable building without TCL (parflow#720)
Add CMake option enable building without TCL. This is first step towards deprecating TCL. See parflow#707, parflow#641
1 parent c9dd2e3 commit b73c713

6 files changed

Lines changed: 132 additions & 62 deletions

File tree

.github/workflows/linux.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
cudaos: 'ubuntu2204',
122122
cc: "gcc", cxx: "g++", fc: "gfortran",
123123
python: "true",
124+
tcl: "true",
124125
backend: "none",
125126
amps_layer: mpi1,
126127
netcdf: "true",
@@ -134,6 +135,7 @@ jobs:
134135
cudaos: 'ubuntu2404',
135136
cc: "gcc", cxx: "g++", fc: "gfortran",
136137
python: "true",
138+
tcl: "true",
137139
backend: "none",
138140
amps_layer: mpi1,
139141
netcdf: "true",
@@ -147,6 +149,24 @@ jobs:
147149
cudaos: 'ubuntu2404',
148150
cc: "gcc", cxx: "g++", fc: "gfortran",
149151
python: "true",
152+
tcl: "true",
153+
backend: "none",
154+
amps_layer: mpi1,
155+
netcdf: "true",
156+
memory_manager: "none",
157+
pdi: "false",
158+
sundials: "external"
159+
}
160+
- {
161+
# Testing deprecation of TCL
162+
# Should switch default in other matrix builds to build without TCL when we deprecate TCL
163+
# Keep at least one test with TCL until we fully remove TCL
164+
name: "Ubuntu 24.04 GCC without TCL",
165+
os: ubuntu-24.04,
166+
cudaos: 'ubuntu2404',
167+
cc: "gcc", cxx: "g++", fc: "gfortran",
168+
python: "true",
169+
tcl: "false",
150170
backend: "none",
151171
amps_layer: mpi1,
152172
netcdf: "true",
@@ -160,6 +180,7 @@ jobs:
160180
cudaos: 'ubuntu2404',
161181
cc: "clang-18", cxx: "clang++-18", fc: "gfortran",
162182
python: "true",
183+
tcl: "true",
163184
backend: "none",
164185
amps_layer: mpi1,
165186
netcdf: "true",
@@ -173,6 +194,7 @@ jobs:
173194
cudaos: 'ubuntu2404',
174195
cc: "gcc", cxx: "g++", fc: "gfortran",
175196
python: "true",
197+
tcl: "true",
176198
backend: "omp",
177199
amps_layer: mpi1,
178200
netcdf: "false",
@@ -210,6 +232,7 @@ jobs:
210232
os: ubuntu-24.04,
211233
cc: "gcc", cxx: "g++", fc: "gfortran",
212234
python: "true",
235+
tcl: "true",
213236
backend: "cuda",
214237
cudaos: 'ubuntu2404',
215238
amps_layer: mpi1,
@@ -234,6 +257,7 @@ jobs:
234257
os: ubuntu-24.04,
235258
cc: "gcc", cxx: "g++", fc: "gfortran",
236259
python: "true",
260+
tcl: "true",
237261
backend: "kokkos",
238262
cudaos: 'ubuntu2404',
239263
amps_layer: mpi1,
@@ -248,6 +272,7 @@ jobs:
248272
cudaos: 'ubuntu2404',
249273
cc: "gcc", cxx: "g++", fc: "gfortran",
250274
python: "true",
275+
tcl: "true",
251276
backend: "none",
252277
amps_layer: mpi1,
253278
netcdf: "false",
@@ -591,6 +616,7 @@ jobs:
591616
-DOAS3_ROOT=$PARFLOW_DEP_DIR \
592617
-DSILO_ROOT=$PARFLOW_DEP_DIR \
593618
-DPARFLOW_ENABLE_PYTHON=${{ matrix.config.python }} \
619+
-DPARFLOW_ENABLE_TCL=${{ matrix.config.tcl }} \
594620
-DCMAKE_INSTALL_PREFIX=$PARFLOW_DIR \
595621
$NETCDF_FLAGS $KOKKOS_FLAGS $RMM_FLAGS $UMPIRE_FLAGS $PDI_FLAGS $SUNDIALS_FLAGS
596622

CMakeLists.txt

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -280,42 +280,45 @@ if ( ${PARFLOW_AMPS_LAYER} IN_LIST PARFLOW_AMPS_LAYER_REQUIRE_MPI )
280280

281281
endif ( ${PARFLOW_AMPS_LAYER} IN_LIST PARFLOW_AMPS_LAYER_REQUIRE_MPI )
282282

283-
find_package(TCL QUIET)
284-
if(TCL_FOUND)
285-
# Warn: TCL support is deprecated and will be removed in a future release.
286-
# Tracking issue: https://github.com/parflow/parflow/issues/707<N>
287-
message(WARNING
288-
"TCL support in ParFlow is deprecated and will be removed in a future release. "
289-
"Users are encouraged to migrate to the Python-based pftools. "
290-
"See https://github.com/parflow/parflow/issues/707 for migration guidance."
291-
)
292-
set(PARFLOW_HAVE_TCL TRUE)
293-
set(HAVE_TCL "${PARFLOW_HAVE_TCL}")
294-
295-
# Determine TCL version
296-
# TCL_VERSION is the canonical macro in tcl.h across all supported versions.
297-
if(TCL_INCLUDE_PATH AND EXISTS "${TCL_INCLUDE_PATH}/tcl.h")
298-
file(STRINGS "${TCL_INCLUDE_PATH}/tcl.h" _tcl_version_line
299-
REGEX "^#[ \t]*define[ \t]+TCL_VERSION[ \t]+\"[^\"]+\"")
300-
if(_tcl_version_line)
301-
string(REGEX REPLACE ".*\"([^\"]+)\".*" "\\1" PARFLOW_TCL_VERSION "${_tcl_version_line}")
302-
unset(_tcl_version_line)
303-
endif(_tcl_version_line)
304-
endif(TCL_INCLUDE_PATH AND EXISTS "${TCL_INCLUDE_PATH}/tcl.h")
305-
# Tcl 9.x removed PFIDB support. Warn early rather than fail at runtime
306-
if(PARFLOW_TCL_VERSION VERSION_GREATER_EQUAL "9.0")
283+
option(PARFLOW_ENABLE_TCL "Enable Tcl-based tools and tests" "OFF")
284+
if (PARFLOW_ENABLE_TCL)
285+
find_package(TCL QUIET)
286+
if(TCL_FOUND)
287+
# Warn: TCL support is deprecated and will be removed in a future release.
288+
# Tracking issue: https://github.com/parflow/parflow/issues/707<N>
307289
message(WARNING
308-
"TCL ${PARFLOW_TCL_VERSION} detected (>= 9.0). "
309-
"ParFlow will compile, but creating or running PFIDB files is not supported with Tcl 9.x. "
310-
"Migrate to Python-based pftools or use Tcl 8.x."
311-
)
312-
endif()
290+
"TCL support in ParFlow is deprecated and will be removed in a future release. "
291+
"Users are encouraged to migrate to the Python-based pftools. "
292+
"See https://github.com/parflow/parflow/issues/707 for migration guidance."
293+
)
294+
set(PARFLOW_HAVE_TCL TRUE)
295+
set(HAVE_TCL "${PARFLOW_HAVE_TCL}")
296+
297+
# Determine TCL version
298+
# TCL_VERSION is the canonical macro in tcl.h across all supported versions.
299+
if(TCL_INCLUDE_PATH AND EXISTS "${TCL_INCLUDE_PATH}/tcl.h")
300+
file(STRINGS "${TCL_INCLUDE_PATH}/tcl.h" _tcl_version_line
301+
REGEX "^#[ \t]*define[ \t]+TCL_VERSION[ \t]+\"[^\"]+\"")
302+
if(_tcl_version_line)
303+
string(REGEX REPLACE ".*\"([^\"]+)\".*" "\\1" PARFLOW_TCL_VERSION "${_tcl_version_line}")
304+
unset(_tcl_version_line)
305+
endif(_tcl_version_line)
306+
endif(TCL_INCLUDE_PATH AND EXISTS "${TCL_INCLUDE_PATH}/tcl.h")
307+
# Tcl 9.x removed PFIDB support. Warn early rather than fail at runtime
308+
if(PARFLOW_TCL_VERSION VERSION_GREATER_EQUAL "9.0")
309+
message(WARNING
310+
"TCL ${PARFLOW_TCL_VERSION} detected (>= 9.0). "
311+
"ParFlow will compile, but creating or running PFIDB files is not supported with Tcl 9.x. "
312+
"Migrate to Python-based pftools or use Tcl 8.x."
313+
)
314+
endif()
313315

314-
else(TCL_FOUND)
315-
if(PARFLOW_ENABLE_TOOLS)
316-
message(FATAL_ERROR "TCL is required for building pftools")
317-
endif()
318-
endif(TCL_FOUND)
316+
else(TCL_FOUND)
317+
if(PARFLOW_ENABLE_TOOLS)
318+
message(FATAL_ERROR "TCL is required for building pftools")
319+
endif()
320+
endif(TCL_FOUND)
321+
endif(PARFLOW_ENABLE_TCL)
319322

320323
#-----------------------------------------------------------------------------
321324
# SILO

cmake/modules/ParflowTest.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
# For sequential tests set topology to 1 1 1
1616
#
1717
function (pf_add_parallel_test inputfile topology)
18+
if (NOT PARFLOW_HAVE_TCL)
19+
return()
20+
endif()
21+
1822
string(REGEX REPLACE "/\.tcl" "" testname ${inputfile})
1923
string(REGEX REPLACE " " "_" postfix ${topology})
2024

@@ -37,6 +41,10 @@ endfunction()
3741
# inputfile is the TCL script that defines the test.
3842
#
3943
function (pf_add_sequential_test inputfile)
44+
if (NOT PARFLOW_HAVE_TCL)
45+
return()
46+
endif()
47+
4048
string(REGEX REPLACE "/\.tcl" "" testname ${inputfile})
4149

4250
list(APPEND args ${inputfile})
@@ -57,6 +65,10 @@ endfunction()
5765
# inputfile is the TCL script that defines the test.
5866
#
5967
function (pf_add_amps_parallel_test test ranks loops)
68+
if (NOT PARFLOW_HAVE_TCL)
69+
return()
70+
endif()
71+
6072
set (testname amps-${test}-${ranks}-${loops})
6173

6274
add_test (NAME ${testname} COMMAND ${CMAKE_COMMAND} -DPARFLOW_TEST=${test} -DPARFLOW_RANKS=${ranks} -DPARFLOW_ARGS=${loops} -DMPIEXEC=${MPIEXEC} -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} "-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS}" "-DMPIEXEC_POSTFLAGS=${MPIEXEC_POSTFLAGS}" -DPARFLOW_HAVE_OAS3=${PARFLOW_HAVE_OAS3} -DPARFLOW_HAVE_SILO=${PARFLOW_HAVE_SILO} -DTCL_TCLSH=${TCL_TCLSH} -P ${CMAKE_SOURCE_DIR}/cmake/modules/RunAmpsTest.cmake)

pftools/CMakeLists.txt

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,40 @@ set (TOOLS_SRC_FILES pftappinit.c printdatabox.c readdatabox.c databox.c
99
toposlopes.c sum.c solidtools.c
1010
)
1111

12-
add_library(pftools SHARED ${TOOLS_SRC_FILES})
12+
if (PARFLOW_HAVE_TCL)
13+
add_library(pftools SHARED ${TOOLS_SRC_FILES})
1314

14-
target_include_directories(pftools PUBLIC ${TCL_INCLUDE_PATH})
15-
target_link_libraries(pftools ${TCL_LIBRARY})
15+
target_include_directories(pftools PUBLIC ${TCL_INCLUDE_PATH})
16+
target_link_libraries(pftools ${TCL_LIBRARY})
1617

17-
if (${PARFLOW_HAVE_SILO})
18-
target_include_directories (pftools PUBLIC "${SILO_INCLUDE_DIRS}")
19-
target_link_libraries (pftools ${SILO_LIBRARIES})
20-
endif (${PARFLOW_HAVE_SILO})
18+
if (${PARFLOW_HAVE_SILO})
19+
target_include_directories (pftools PUBLIC "${SILO_INCLUDE_DIRS}")
20+
target_link_libraries (pftools ${SILO_LIBRARIES})
21+
endif (${PARFLOW_HAVE_SILO})
2122

22-
if (${PARFLOW_HAVE_HDF5})
23-
target_include_directories (pftools PUBLIC "${HDF5_INCLUDE_DIRS}")
24-
target_link_libraries (pftools ${HDF5_LIBRARIES})
25-
endif (${PARFLOW_HAVE_HDF5})
23+
if (${PARFLOW_HAVE_HDF5})
24+
target_include_directories (pftools PUBLIC "${HDF5_INCLUDE_DIRS}")
25+
target_link_libraries (pftools ${HDF5_LIBRARIES})
26+
endif (${PARFLOW_HAVE_HDF5})
2627

27-
if (${PARFLOW_HAVE_ZLIB})
28-
target_link_libraries (pftools ${ZLIB_LIBRARIES})
29-
endif (${PARFLOW_HAVE_ZLIB})
28+
if (${PARFLOW_HAVE_ZLIB})
29+
target_link_libraries (pftools ${ZLIB_LIBRARIES})
30+
endif (${PARFLOW_HAVE_ZLIB})
3031

31-
if (${PARFLOW_HAVE_SZLIB})
32-
target_link_libraries (pftools ${SZLIB_LIBRARIES})
33-
endif (${PARFLOW_HAVE_SZLIB})
32+
if (${PARFLOW_HAVE_SZLIB})
33+
target_link_libraries (pftools ${SZLIB_LIBRARIES})
34+
endif (${PARFLOW_HAVE_SZLIB})
3435

35-
# Install to bin is for TCL which seem to prefer shared libraries
36-
# there for some installs.
37-
install(TARGETS pftools DESTINATION bin)
38-
install(TARGETS pftools DESTINATION lib)
36+
# Install to bin is for Tcl, which expects shared libraries there on some systems.
37+
install(TARGETS pftools DESTINATION bin)
38+
install(TARGETS pftools DESTINATION lib)
3939

40-
file (GLOB TCL_SRC *.tcl)
41-
install(FILES ${TCL_SRC} DESTINATION bin)
40+
file (GLOB TCL_SRC *.tcl)
41+
install(FILES ${TCL_SRC} DESTINATION bin)
4242

43-
set(SCRIPTS pfhelp pfmvio pfbtosa pfbtovis pfbtosilo pfsbtosa pfstrip)
44-
install(PROGRAMS ${SCRIPTS} DESTINATION bin)
43+
set(SCRIPTS pfhelp pfmvio pfbtosa pfbtovis pfbtosilo pfsbtosa pfstrip)
44+
install(PROGRAMS ${SCRIPTS} DESTINATION bin)
45+
endif ()
4546

4647
add_executable(pfwell_cat pfwell_cat.c well.c)
4748
install(TARGETS pfwell_cat DESTINATION bin)
@@ -65,9 +66,25 @@ install(TARGETS projecttin DESTINATION bin)
6566
#-----------------------------------------------------------------------------
6667
# Mask utilities
6768
#-----------------------------------------------------------------------------
68-
add_executable(pfmask-to-pfsol pfmask-to-pfsol.cpp)
69+
70+
# This is first step at enabling building without TCL. The pfmask-to-pfsol utility was
71+
# originally written to link against the TCL library; this was changed to
72+
# compile allow compiling with the needed funtions directly. Should consider
73+
# reworking this utility using the Python library or seperating the TCL from the other
74+
# utilities into two libraries to link against.
75+
if (PARFLOW_HAVE_TCL)
76+
add_executable(pfmask-to-pfsol pfmask-to-pfsol.cpp)
77+
target_link_libraries(pfmask-to-pfsol pftools)
78+
else ()
79+
add_executable(pfmask-to-pfsol pfmask-to-pfsol.cpp readdatabox.c databox.c tools_io.c)
80+
endif()
81+
6982
target_include_directories(pfmask-to-pfsol PUBLIC third_party)
70-
target_link_libraries(pfmask-to-pfsol pftools)
83+
if (${PARFLOW_HAVE_SILO})
84+
target_include_directories (pfmask-to-pfsol PUBLIC "${SILO_INCLUDE_DIRS}")
85+
target_link_libraries (pfmask-to-pfsol ${SILO_LIBRARIES})
86+
endif (${PARFLOW_HAVE_SILO})
87+
7188
install(TARGETS pfmask-to-pfsol DESTINATION bin)
7289

7390
add_executable(pfsol-to-vtk pfsol-to-vtk.c)
@@ -77,4 +94,6 @@ add_executable(pfmaskdownsize pfmaskdownsize.cpp)
7794
target_include_directories(pfmaskdownsize PUBLIC third_party)
7895
install(TARGETS pfmaskdownsize DESTINATION bin)
7996

80-
add_subdirectory (test)
97+
if (PARFLOW_HAVE_TCL)
98+
add_subdirectory (test)
99+
endif ()

pftools/databox.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Databox *NewDataboxDefault(
116116
* print Databox grid info
117117
*-----------------------------------------------------------------------*/
118118

119+
#ifdef PARFLOW_HAVE_TCL
120+
119121
void GetDataboxGrid(
120122
Tcl_Interp *interp,
121123
Databox * databox)
@@ -163,6 +165,8 @@ void GetDataboxGrid(
163165
Tcl_ListObjAppendElement(interp, result, list_obj);
164166
}
165167

168+
#endif // PARFLOW_HAVE_TCL
169+
166170

167171
// IMF
168172
/*-----------------------------------------------------------------------

pftools/databox.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
#include <hdf.h>
4747
#endif
4848

49+
#ifdef PARFLOW_HAVE_TCL
4950
#include <tcl.h>
51+
#endif
52+
53+
#include <stddef.h>
5054

5155
#ifdef __cplusplus
5256
extern "C" {
@@ -113,7 +117,9 @@ typedef enum {
113117
Databox *NewDatabox(size_t nx, size_t ny, size_t nz, double x, double y, double z, double dx, double dy, double dz);
114118
Databox *NewDataboxDefault(size_t nx, size_t ny, size_t nz, double x, double y, double z, double dx, double dy, double dz,
115119
double default_value);
120+
#ifdef PARFLOW_HAVE_TCL
116121
void GetDataboxGrid(Tcl_Interp *interp, Databox *databox);
122+
#endif
117123
void SetDataboxGrid(Databox *databox, int nx, int ny, int nz, double x, double y, double z,
118124
double dx, double dy, double dz);
119125
void FreeDatabox(Databox *databox);

0 commit comments

Comments
 (0)