From 686c28bb5a90f63767152e07be595971e9803235 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 30 Jan 2025 08:47:35 -0500 Subject: [PATCH] v12: Updated FMS Handling --- CHANGELOG.md | 8 +- external_libraries/FindBaselibs.cmake | 102 +++++++++++++++++--------- 2 files changed, 75 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd1857c..69a2752d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/external_libraries/FindBaselibs.cmake b/external_libraries/FindBaselibs.cmake index 11b75115..bb3a503e 100644 --- a/external_libraries/FindBaselibs.cmake +++ b/external_libraries/FindBaselibs.cmake @@ -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)