Skip to content

Commit

Permalink
v12: Updated FMS Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mathomp4 committed Jan 30, 2025
1 parent 083180f commit 686c28b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 35 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

[4.11.0] - 2025-01-03
## [4.12.0] - 2025-01-30

### Changed

- Reworked FMS detection to better handle the different `FV_PRECISION` cases in `FindBaselibs.cmake`

## [4.11.0] - 2025-01-03

### Changed

Expand Down
102 changes: 68 additions & 34 deletions external_libraries/FindBaselibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -281,43 +281,77 @@ if (Baselibs_FOUND)
message(STATUS "LIBYAML_LIBRARIES: ${LIBYAML_LIBRARIES}")
endif ()

# - fms_r4
set (inc_fms_r4 ${BASEDIR}/FMS/include_r4)
set (lib_fms_r4 ${BASEDIR}/FMS/lib/libfms_r4.a)
add_library(FMS::fms_r4 STATIC IMPORTED)
set_target_properties(FMS::fms_r4 PROPERTIES
IMPORTED_LOCATION ${lib_fms_r4}
INCLUDE_DIRECTORIES "${inc_fms_r4}"
INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r4}"
INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/FMS/lib"
)
if (FMS_BUILT_WITH_YAML)
target_link_libraries(FMS::fms_r4 INTERFACE ${LIBYAML_LIBRARIES})
endif ()
add_library(fms_r4 ALIAS FMS::fms_r4)
set(FMS_R4_FOUND TRUE CACHE BOOL "fms_r4 Found" FORCE)
if (FV_PRECISION STREQUAL R4 OR FV_PRECISION STREQUAL R4R8)
# - fms_r4
set (inc_fms_r4 ${BASEDIR}/FMS/include_r4)
set (lib_fms_r4 ${BASEDIR}/FMS/lib/libfms_r4.a)
add_library(FMS::fms_r4 STATIC IMPORTED)
set_target_properties(FMS::fms_r4 PROPERTIES
IMPORTED_LOCATION ${lib_fms_r4}
INCLUDE_DIRECTORIES "${inc_fms_r4}"
INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r4}"
INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/FMS/lib"
)
if (FMS_BUILT_WITH_YAML)
target_link_libraries(FMS::fms_r4 INTERFACE ${LIBYAML_LIBRARIES})
endif ()
#add_library(fms_r4 ALIAS FMS::fms_r4)
# We will set FMS_R4_FOUND if both lib_fms_r4 and inc_fms_r4 are found
# and are valid files and directories respectively
if (EXISTS ${lib_fms_r4} AND IS_DIRECTORY ${inc_fms_r4})
message(STATUS "Found FMS::fms_r4: ${lib_fms_r4}")
message(STATUS "FMS::fms_r4 include directory: ${inc_fms_r4}")
set(FMS_R4_FOUND TRUE CACHE BOOL "fms_r8 Found" FORCE)
else ()
message(FATAL_ERROR "FMS::fms_r8 not found")
endif()
endif()

# - fms_r8
set (inc_fms_r8 ${BASEDIR}/FMS/include_r8)
set (lib_fms_r8 ${BASEDIR}/FMS/lib/libfms_r8.a)
add_library(FMS::fms_r8 STATIC IMPORTED)
set_target_properties(FMS::fms_r8 PROPERTIES
IMPORTED_LOCATION ${lib_fms_r8}
INCLUDE_DIRECTORIES "${inc_fms_r8}"
INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r8}"
INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/FMS/lib"
)
if (FMS_BUILT_WITH_YAML)
target_link_libraries(FMS::fms_r8 INTERFACE ${LIBYAML_LIBRARIES})
endif ()
add_library(fms_r8 ALIAS FMS::fms_r8)
set(FMS_R8_FOUND TRUE CACHE BOOL "fms_r8 Found" FORCE)
if (FV_PRECISION STREQUAL R8 OR FV_PRECISION STREQUAL R4R8)
set (inc_fms_r8 ${BASEDIR}/FMS/include_r8)
set (lib_fms_r8 ${BASEDIR}/FMS/lib/libfms_r8.a)
add_library(FMS::fms_r8 STATIC IMPORTED)
set_target_properties(FMS::fms_r8 PROPERTIES
IMPORTED_LOCATION ${lib_fms_r8}
INCLUDE_DIRECTORIES "${inc_fms_r8}"
INTERFACE_INCLUDE_DIRECTORIES "${inc_fms_r8}"
INTERFACE_LINK_LIBRARIES "NetCDF::NetCDF_Fortran;MPI::MPI_Fortran"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/FMS/lib"
)
if (FMS_BUILT_WITH_YAML)
target_link_libraries(FMS::fms_r8 INTERFACE ${LIBYAML_LIBRARIES})
endif ()
#add_library(fms_r8 ALIAS FMS::fms_r8)
# We will set FMS_R8_FOUND if both lib_fms_r8 and inc_fms_r8 are found
# and are valid files and directories respectively
if (EXISTS ${lib_fms_r8} AND IS_DIRECTORY ${inc_fms_r8})
message(STATUS "Found FMS::fms_r8: ${lib_fms_r8}")
message(STATUS "FMS::fms_r8 include directory: ${inc_fms_r8}")
set(FMS_R8_FOUND TRUE CACHE BOOL "fms_r8 Found" FORCE)
else ()
message(FATAL_ERROR "FMS::fms_r8 not found")
endif()
endif()

if (FMS_R4_FOUND AND FMS_R8_FOUND)
set(FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE)
endif ()
if (FV_PRECISION STREQUAL R4R8)
# We will set FMS_FOUND if both fms_r4 and fms_r8 are found
# and are valid files and directories respectively
if (FMS_R4_FOUND AND FMS_R8_FOUND)
set(FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE)
endif()
elseif (FV_PRECISION STREQUAL R4)
if (FMS_R4_FOUND)
set(FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE)
endif()
elseif (FV_PRECISION STREQUAL R8)
if (FMS_R8_FOUND)
set(FMS_FOUND TRUE CACHE BOOL "FMS Found" FORCE)
endif()
else()
message(FATAL_ERROR "FMS Detection failed in odd way")
endif()

if (FMS_FOUND)
set (FMS_DIR ${BASEDIR}/FMS CACHE PATH "Path to FMS" FORCE)
Expand Down

0 comments on commit 686c28b

Please sign in to comment.