Skip to content

v4: Split external library configuration out of FindBaselibs.cmake - #559

Open
mathomp4 wants to merge 7 commits into
release/v4from
feature/v4-external-libs
Open

v4: Split external library configuration out of FindBaselibs.cmake#559
mathomp4 wants to merge 7 commits into
release/v4from
feature/v4-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]

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.
@mathomp4
mathomp4 requested a review from a team as a code owner July 27, 2026 14:04
@mathomp4 mathomp4 added 0 diff The changes in this pull request have verified to be zero-diff with the target branch. Contingent - DNA Do Not Approve (DNA). These changes are contingent on other PRs labels Jul 27, 2026
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.
@mathomp4 mathomp4 removed the Contingent - DNA Do Not Approve (DNA). These changes are contingent on other PRs label Jul 27, 2026
mathomp4 added 5 commits July 27, 2026 12:04
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 v4: 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

0 diff The changes in this pull request have verified to be zero-diff with the target branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant