Skip to content

Commit a24b682

Browse files
committed
Add config for getm, does not work since gotm does not...
1 parent e0ecde1 commit a24b682

2 files changed

Lines changed: 122 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ endif()
2828
# Options for third-party packages that we an link into
2929
option(USE_HAMSOM "Enable HAMSOM-based drivers" OFF)
3030
option(USE_CMAQ "Enable CMAQ-based drivers" OFF)
31-
option(USE_GETM "Enable GETM-based drivers" ON)
32-
option(USE_GOTM "Enable GOTM-based drivers" ON)
31+
option(USE_GETM "Enable GETM-based drivers" OFF)
32+
option(USE_SCHISM "Enable SCHISM drivers" OFF)
33+
option(USE_GOTM "Enable GOTM-based drivers" OFF)
3334
option(USE_FABM "Enable FABM-based drivers" ON)
3435
option(USE_EROSED "Enable EROSED-related drivers (biotypes, benthoseffect_class)" OFF)
3536

@@ -64,17 +65,57 @@ if(USE_FABM)
6465
endif()
6566

6667
set(FABM_FORCED_HOST mossco)
67-
cmake_policy(PUSH)
68-
cmake_policy(VERSION 3.5)
6968
add_subdirectory("${FABM_SOURCE_DIR}" external/fabm/code)
70-
cmake_policy(POP)
7169
mark_as_advanced(CLEAR FABM_BASE)
7270
endif()
7371
endif()
7472

73+
# The GOTM part does not work as it runs into recursion issues.
74+
if(USE_GOTM)
75+
mark_as_advanced(FORCE GOTM_PREFIX GOTM_BASE)
76+
77+
if(GOTM_PREFIX)
78+
find_package(gotm REQUIRED CONFIG HINTS "${GOTM_PREFIX}" NO_DEFAULT_PATH)
79+
mark_as_advanced(CLEAR GOTM_PREFIX)
80+
else()
81+
# Determine GOTM_BASE
82+
if(NOT DEFINED GOTM_BASE)
83+
if(DEFINED ENV{GOTM_BASE})
84+
set(GOTM_BASE $ENV{GOTM_BASE})
85+
else()
86+
set(GOTM_BASE "${CMAKE_CURRENT_LIST_DIR}/external/gotm/code")
87+
endif()
88+
endif()
89+
90+
message(STATUS "Using GOTM_BASE=${GOTM_BASE}")
91+
92+
# Use separate variable to locate GOTM source
93+
find_path(GOTM_SOURCE_DIR src/gotm/gotm.F90
94+
HINTS "${GOTM_BASE}"
95+
DOC "Path to GOTM source directory."
96+
NO_CMAKE_FIND_ROOT_PATH
97+
)
7598

99+
if(NOT GOTM_SOURCE_DIR)
100+
message(FATAL_ERROR "Could not find GOTM source at or near ${GOTM_BASE}")
101+
endif()
102+
103+
# Safely set policy for variable overrides
104+
cmake_policy(PUSH)
105+
cmake_policy(SET CMP0079 NEW)
106+
107+
set(GOTM_USE_FABM NOT ${USE_FABM} CACHE BOOL "Toggle FABM in GOTM" FORCE)
108+
109+
add_subdirectory("${GOTM_SOURCE_DIR}" external/gotm/code)
110+
111+
cmake_policy(POP)
112+
113+
mark_as_advanced(CLEAR GOTM_BASE)
114+
endif()
115+
endif()
76116

77117

118+
include(ConfigureGETM)
78119

79120
include(GitVersion)
80121
include(FindESMF)

cmake/ConfigureGETM.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ConfigureGETM.cmake - Complete GETM configuration and integration
2+
# Usage: include(ConfigureGETM)
3+
# configure_getm()
4+
#
5+
# Required variables:
6+
# USE_GETM - Boolean to enable GETM
7+
# USE_FABM - Boolean for FABM configuration (used to toggle GETM_USE_FABM)
8+
#
9+
# Optional variables:
10+
# GETM_PREFIX - Path to pre-built GETM installation
11+
# GETM_BASE - Path to GETM source base directory
12+
13+
function(configure_getm)
14+
if(NOT USE_GETM)
15+
return()
16+
endif()
17+
18+
mark_as_advanced(FORCE GETM_PREFIX GETM_BASE)
19+
20+
if(GETM_PREFIX)
21+
find_package(GETM REQUIRED CONFIG HINTS "${GETM_PREFIX}" NO_DEFAULT_PATH)
22+
mark_as_advanced(CLEAR GETM_PREFIX)
23+
else()
24+
# Determine GETM_BASE
25+
if(NOT DEFINED GETM_BASE)
26+
if(DEFINED ENV{GETM_BASE})
27+
set(GETM_BASE $ENV{GETM_BASE})
28+
else()
29+
set(GETM_BASE "${CMAKE_CURRENT_LIST_DIR}/external/getm/code")
30+
endif()
31+
endif()
32+
message(STATUS "Using GETM_BASE=${GETM_BASE}")
33+
34+
# Use separate variable to locate GETM source
35+
find_path(GETM_SOURCE_DIR src/getm/main.F90
36+
HINTS "${GETM_BASE}"
37+
DOC "Path to GETM source directory."
38+
NO_CMAKE_FIND_ROOT_PATH
39+
)
40+
41+
if(NOT GETM_SOURCE_DIR)
42+
message(FATAL_ERROR "Could not find GETM source at or near ${GETM_BASE}")
43+
endif()
44+
45+
set(GETM_USE_FABM NOT ${USE_FABM} CACHE BOOL "Toggle FABM in GETM" FORCE)
46+
47+
# Determine the directory containing the CMakeLists.txt for GETM
48+
set(GETM_CMAKE_DIR "")
49+
set(GETM_BINARY_DIR "external/getm/code")
50+
51+
# Check if CMakeLists.txt exists in the root of GETM_SOURCE_DIR
52+
if(EXISTS "${GETM_SOURCE_DIR}/CMakeLists.txt")
53+
set(GETM_CMAKE_DIR "${GETM_SOURCE_DIR}")
54+
message(STATUS "Found GETM CMakeLists.txt in root: ${GETM_SOURCE_DIR}")
55+
# Check if CMakeLists.txt exists in the src subdirectory
56+
elseif(EXISTS "${GETM_SOURCE_DIR}/src/CMakeLists.txt")
57+
set(GETM_CMAKE_DIR "${GETM_SOURCE_DIR}/src")
58+
set(GETM_BINARY_DIR "external/getm/code/src")
59+
message(STATUS "Found GETM CMakeLists.txt in src: ${GETM_SOURCE_DIR}/src")
60+
else()
61+
message(FATAL_ERROR "Could not find CMakeLists.txt in GETM source directory: ${GETM_SOURCE_DIR}")
62+
endif()
63+
64+
# Add the subdirectory with the correct paths
65+
add_subdirectory("${GETM_CMAKE_DIR}" "${GETM_BINARY_DIR}")
66+
67+
mark_as_advanced(CLEAR GETM_BASE)
68+
endif()
69+
endfunction()
70+
71+
# Convenience macro that calls the function if USE_GETM is set
72+
macro(configure_getm_if_enabled)
73+
if(USE_GETM)
74+
configure_getm()
75+
endif()
76+
endmacro()

0 commit comments

Comments
 (0)