Skip to content

v5: Split external library configuration out of FindBaselibs.cmake - #560

Open
mathomp4 wants to merge 7 commits into
developfrom
feature/v5-external-libs
Open

v5: Split external library configuration out of FindBaselibs.cmake#560
mathomp4 wants to merge 7 commits into
developfrom
feature/v5-external-libs

Conversation

@mathomp4

@mathomp4 mathomp4 commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Move NetCDF/HDF5/ESMF/FMS dependency-target creation out of FindBaselibs.cmake into two new files:
    • external_libraries/ConfigureBaselibs.cmake: creates targets from a Baselibs install
    • external_libraries/ConfigureExternalLibraries.cmake: creates the same targets via find_package() for Spack or other non-Baselibs package managers
  • FindBaselibs.cmake now only detects BASEDIR and sets Baselibs_FOUND
  • esma.cmake automatically include()s the right one (ConfigureBaselibs or ConfigureExternalLibraries) based on Baselibs_FOUND, right after include(FindBaselibs)
  • Updated CHANGELOG.md under [Unreleased]

This mirrors #559 (feature/v4-external-libs targeting release/v4), adapted for v5's single-precision FMS::fms target (no FMS::fms_r4/FMS::fms_r8 split, no FV_PRECISION-based component selection in find_package(FMS ...)).

Because the dispatch now lives in esma.cmake, downstream projects (like GEOSgcm) don't need to add anything to their top-level CMakeLists.txt. The only change needed there is to remove the old inline Spack/non-Baselibs block, e.g.:

find_package(MPI)

include(esma)

# Remove this whole block -- ConfigureBaselibs/ConfigureExternalLibraries
# is now included automatically by esma.cmake based on Baselibs_FOUND.
# if (NOT Baselibs_FOUND)
#   find_package(NetCDF REQUIRED C Fortran)
#   ...
# endif ()

ecbuild_declare_project()

Fixes since initial version

  • Guard the historical ZLIB::zlib alias creation with if(NOT TARGET ZLIB::zlib) in ConfigureExternalLibraries.cmake; some ZLIB providers (e.g. zlib-ng's CMake config package) already export a target with that exact name.
  • In ConfigureExternalLibraries.cmake, only look for FMS via find_package when FV_PRECISION is defined. Library projects like MAPL don't use FMS and don't set FV_PRECISION, so they're no longer forced to have it installed. This mirrors the existing FV_PRECISION convention already used in ConfigureBaselibs.cmake for the Baselibs case.
  • In ConfigureBaselibs.cmake, enforce a minimum ESMF version (matching ConfigureExternalLibraries.cmake) by checking ESMF_VERSION explicitly, since Baselibs' esmf.mk has no CMake-style version string for find_package() to check.
  • Added an ESMA_ESMF_MIN_VERSION variable (default 8.6.1), settable by a downstream project before include(esma), so projects with stricter ESMF requirements (e.g. MAPL3 needing 9.0.0) don't need their own version-guard boilerplate.

Test plan

  • Being tested against a GEOSgcm branch with the old inline Spack block removed

Move NetCDF/HDF5/ESMF/FMS dependency-target creation out of
FindBaselibs.cmake into two new files:

- ConfigureBaselibs.cmake: creates targets from a Baselibs install
- ConfigureExternalLibraries.cmake: creates the same targets via
  find_package() for Spack or other non-Baselibs package managers

FindBaselibs.cmake now only detects BASEDIR and sets Baselibs_FOUND.
The top-level project includes whichever configuration file matches
Baselibs_FOUND, removing the need to duplicate the non-Baselibs
find_package() calls in every project's CMakeLists.txt.

This mirrors the same split done on release/v4
(feature/v4-external-libs), adapted for v5's single-precision
FMS::fms target (no FMS::fms_r4/fms_r8 split, no FV_PRECISION-based
component selection).
@mathomp4
mathomp4 requested a review from a team as a code owner July 27, 2026 14:09
@github-actions

Copy link
Copy Markdown

This PR is being prevented from merging because you have not added one of our required labels: 0 diff, 0 diff trivial, Non 0-diff, 0 diff structural, 0-diff trivial, Not 0-diff, 0-diff, automatic, 0-diff uncoupled, github_actions. Please add one so that the PR can be merged.

mathomp4 added 6 commits July 27, 2026 10:14
Rather than requiring every top-level project's CMakeLists.txt to
include(ConfigureBaselibs) or include(ConfigureExternalLibraries)
based on Baselibs_FOUND, do it automatically in esma.cmake right
after FindBaselibs is included. Top-level projects that previously
had an inline 'if (NOT Baselibs_FOUND) ... endif()' block for Spack
support can simply remove it.
Some ZLIB providers (e.g. zlib-ng's CMake config package used by
certain Spack stacks) already export a target literally named
ZLIB::zlib, causing the unconditional add_library(... ALIAS ...) call
to fail with 'target already exists'. Guard it like the ESMF aliases.
Projects like MAPL don't use FMS, so don't require it via find_package
when the project hasn't set FV_PRECISION. This mirrors the existing
convention already used in ConfigureBaselibs.cmake for the Baselibs
case.
Baselibs' esmf.mk has no CMake-style version string, so find_package()
cannot enforce a minimum version the way ConfigureExternalLibraries.cmake
does. Check ESMF_VERSION explicitly instead so Baselibs and Spack builds
enforce the same 8.6.1 minimum.
Instead of hardcoding an 8.6.1 minimum in both ConfigureBaselibs.cmake
and ConfigureExternalLibraries.cmake, consult a single
ESMA_ESMF_MIN_VERSION variable that esma.cmake defaults to 8.6.1 if
unset. Downstream projects with stricter requirements (e.g. MAPL3
needing ESMF 9.0.0) can now just set(ESMA_ESMF_MIN_VERSION 9.0.0)
before include(esma) instead of writing their own version-guard
boilerplate for both the Baselibs and Spack cases.
@mathomp4 mathomp4 changed the title Split external library configuration out of FindBaselibs.cmake v5: Split external library configuration out of FindBaselibs.cmake Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant