@@ -59,12 +59,7 @@ if (BASEDIR)
5959 endif ()
6060 set (BASEDIR "${BASEDIR} " CACHE PATH "Path to installed baselibs" FORCE )
6161else ()
62- ecbuild_warn (
63- "BASEDIR not specified.\n "
64- "If you wish to use Baselibs, please use:\n "
65- " cmake ... -DBASEDIR=<path-to-Baselibs>\n "
66- "or set BASEDIR in your environment.\n\n "
67- "Note that building GEOS-ESM code without Baselibs is unsupported." )
62+ message (STATUS "BASEDIR not set. Baselibs not found. Assume we are using Spack or other methods to provide dependencies" )
6863endif ()
6964
7065if (ESMA_SDF)
@@ -282,42 +277,80 @@ if (Baselibs_FOUND)
282277 endif ()
283278
284279 # - fms_r4
285- set (inc_fms_r4 ${BASEDIR} /FMS/include_r4)
286- set (lib_fms_r4 ${BASEDIR} /FMS/lib/libfms_r4.a)
287- add_library (FMS::fms_r4 STATIC IMPORTED )
288- set_target_properties (FMS::fms_r4 PROPERTIES
289- IMPORTED_LOCATION ${lib_fms_r4}
290- INCLUDE_DIRECTORIES "${inc_fms_r4} "
291- INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r4} "
292- INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
293- INTERFACE_LINK_DIRECTORIES "${BASEDIR} /FMS/lib"
294- )
295- if (FMS_BUILT_WITH_YAML)
296- target_link_libraries (FMS::fms_r4 INTERFACE ${LIBYAML_LIBRARIES} )
297- endif ()
298- add_library (fms_r4 ALIAS FMS::fms_r4 )
299- set (FMS_R4_FOUND TRUE CACHE BOOL "fms_r4 Found" FORCE )
280+ if (FV_PRECISION STREQUAL R4 OR FV_PRECISION STREQUAL R4R8)
281+ # Use find_path and find_library to find the include and library
282+ find_path (FMS_INCLUDE_DIR_R4 NAMES fms.mod PATHS ${BASEDIR} /FMS/include_r4 )
283+ find_library (FMS_LIBRARIES_R4 NAMES fms_r4 PATHS ${BASEDIR} /FMS/lib ${BASEDIR} /FMS/lib64 )
284+ # We also need the path of where the library is for the INTERFACE_LINK_DIRECTORIES
285+ get_filename_component (FMS_LIBRARIES_DIR_R4 ${FMS_LIBRARIES_R4} DIRECTORY )
286+ add_library (FMS::fms_r4 STATIC IMPORTED )
287+ set_target_properties (FMS::fms_r4 PROPERTIES
288+ IMPORTED_LOCATION ${FMS_LIBRARIES_R4}
289+ INCLUDE_DIRECTORIES "${FMS_INCLUDE_DIR_R4} "
290+ INTERFACE_INCLUDE_DIRECTORIES "${FMS_INCLUDE_DIR_R4} "
291+ INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
292+ INTERFACE_LINK_DIRECTORIES "${FMS_LIBRARIES_DIR_R4} "
293+ )
294+ if (FMS_BUILT_WITH_YAML)
295+ target_link_libraries (FMS::fms_r4 INTERFACE ${LIBYAML_LIBRARIES} )
296+ endif ()
297+ # We will set FMS_R4_FOUND if both FMS_LIBRARIES_R4 and FMS_INCLUDE_DIR_R4 are found
298+ # and are valid files and directories respectively
299+ if (EXISTS ${FMS_LIBRARIES_R4} AND IS_DIRECTORY ${FMS_INCLUDE_DIR_R4} )
300+ message (STATUS "Found FMS::fms_r4: ${FMS_LIBRARIES_R4} " )
301+ message (STATUS "FMS::fms_r4 include directory: ${FMS_INCLUDE_DIR_R4} " )
302+ set (FMS_R4_FOUND TRUE CACHE BOOL "fms_r4 Found" FORCE )
303+ else ()
304+ message (FATAL_ERROR "FMS::fms_r4 not found" )
305+ endif ()
306+ endif ()
300307
301308 # - fms_r8
302- set (inc_fms_r8 ${BASEDIR} /FMS/include_r8)
303- set (lib_fms_r8 ${BASEDIR} /FMS/lib/libfms_r8.a)
304- add_library (FMS::fms_r8 STATIC IMPORTED )
305- set_target_properties (FMS::fms_r8 PROPERTIES
306- IMPORTED_LOCATION ${lib_fms_r8}
307- INCLUDE_DIRECTORIES "${inc_fms_r8} "
308- INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r8} "
309- INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
310- INTERFACE_LINK_DIRECTORIES "${BASEDIR} /FMS/lib"
311- )
312- if (FMS_BUILT_WITH_YAML)
313- target_link_libraries (FMS::fms_r8 INTERFACE ${LIBYAML_LIBRARIES} )
314- endif ()
315- add_library (fms_r8 ALIAS FMS::fms_r8 )
316- set (FMS_R8_FOUND TRUE CACHE BOOL "fms_r8 Found" FORCE )
309+ if (FV_PRECISION STREQUAL R8 OR FV_PRECISION STREQUAL R4R8)
310+ # Use find_path and find_library to find the include and library
311+ find_path (FMS_INCLUDE_DIR_R8 NAMES fms.mod PATHS ${BASEDIR} /FMS/include_r8 )
312+ find_library (FMS_LIBRARIES_R8 NAMES fms_r8 PATHS ${BASEDIR} /FMS/lib ${BASEDIR} /FMS/lib64 )
313+ # We also need the path of where the library is for the INTERFACE_LINK_DIRECTORIES
314+ get_filename_component (FMS_LIBRARIES_DIR_R8 ${FMS_LIBRARIES_R8} DIRECTORY )
315+ add_library (FMS::fms_r8 STATIC IMPORTED )
316+ set_target_properties (FMS::fms_r8 PROPERTIES
317+ IMPORTED_LOCATION ${FMS_LIBRARIES_R8}
318+ INCLUDE_DIRECTORIES "${FMS_INCLUDE_DIR_R8} "
319+ INTERFACE_INCLUDE_DIRECTORIES "${FMS_INCLUDE_DIR_R8} "
320+ INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
321+ INTERFACE_LINK_DIRECTORIES "${FMS_LIBRARIES_DIR_R8} "
322+ )
323+ if (FMS_BUILT_WITH_YAML)
324+ target_link_libraries (FMS::fms_r8 INTERFACE ${LIBYAML_LIBRARIES} )
325+ endif ()
326+ # We will set FMS_R8_FOUND if both FMS_LIBRARIES_R8 and FMS_INCLUDE_DIR_R8 are found
327+ # and are valid files and directories respectively
328+ if (EXISTS ${FMS_LIBRARIES_R8} AND IS_DIRECTORY ${FMS_INCLUDE_DIR_R8} )
329+ message (STATUS "Found FMS::fms_r8: ${FMS_LIBRARIES_R8} " )
330+ message (STATUS "FMS::fms_r8 include directory: ${FMS_INCLUDE_DIR_R8} " )
331+ set (FMS_R8_FOUND TRUE CACHE BOOL "fms_r8 Found" FORCE )
332+ else ()
333+ message (FATAL_ERROR "FMS::fms_r8 not found" )
334+ endif ()
335+ endif ()
317336
318- if (FMS_R4_FOUND AND FMS_R8_FOUND)
319- set (FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE )
320- endif ()
337+ if (FV_PRECISION STREQUAL R4R8)
338+ # We will set FMS_FOUND if both fms_r4 and fms_r8 are found
339+ # and are valid files and directories respectively
340+ if (FMS_R4_FOUND AND FMS_R8_FOUND)
341+ set (FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE )
342+ endif ()
343+ elseif (FV_PRECISION STREQUAL R4)
344+ if (FMS_R4_FOUND)
345+ set (FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE )
346+ endif ()
347+ elseif (FV_PRECISION STREQUAL R8)
348+ if (FMS_R8_FOUND)
349+ set (FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE )
350+ endif ()
351+ else ()
352+ message (FATAL_ERROR "FMS Detection failed in odd way" )
353+ endif ()
321354
322355 if (FMS_FOUND)
323356 set (FMS_DIR ${BASEDIR} /FMS CACHE PATH "Path to FMS" FORCE )
0 commit comments