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