GEOS-ESM / ESMA_cmake

Custom CMake macros for the GEOS Earth System Model
Apache License 2.0
4 stars 9 forks source link

Add FindESMF.cmake for Spack builds #345

Closed mathomp4 closed 9 months ago

mathomp4 commented 9 months ago

Testing of Spack and GEOS (in collaboration with @climbfuji) found that GEOSgcm itself needs FindESMF.cmake when building with mainline Spack. GEOS-Baselibs builds do not need this because ESMA_cmake "knows" where the module is in a Baselibs install of ESMF. But with spack, this is not known. This is perhaps not the most elegant solution but it works.

The ESMF spack package does install a cmake/ directory with the file:

    @run_after("install")
    def post_install(self):
        install_tree("cmake", self.prefix.cmake)

but as far as I can see, that path is not exposed via any environment variable in the esmf modulefile produced by spack. Technically, it should always be a cmake/ directory at the same level as bin but no guarantee that is always true.

Note 1: I think spack-stack also provides its own FindESMF.cmake file via CMakeModules but a pure-spack build of GEOS would not have that. Note 2: The FindESMF.cmake file here is identical to the one in MAPL which is the current one provided by ESMF (but different than the one in EMC's repo). Since they are all identical, I don't think we'll screw up CMake, but this could be an issue if at some point they diverge. This probably points to a need to rethink our find packages.

mathomp4 commented 9 months ago

Sigh, yes.

I am not good at remembering things, but isn't it the case that for packages that don't have a cmake find_package implemented in the official cmake distribution, the package itself needs to take care of that? i.e. esmf needs to - upon installation via spack or however else - provide a FindESMF.cmake that can be used? This way you have one and only one version of it, which is the blessed version by the package developers.

The problem is, I tried long ago to do this and I couldn't quite figure it out how to have spack put stuff into a path that CMake would pick up...but I was even worse at spack in those days.

But maybe we could appeal to the ESMF folks for a "blessed" environment variable a la ESMFMKFILE? 🤷🏼

climbfuji commented 9 months ago

Sigh, yes. I am not good at remembering things, but isn't it the case that for packages that don't have a cmake find_package implemented in the official cmake distribution, the package itself needs to take care of that? i.e. esmf needs to - upon installation via spack or however else - provide a FindESMF.cmake that can be used? This way you have one and only one version of it, which is the blessed version by the package developers.

The problem is, I tried long ago to do this and I couldn't quite figure it out how to have spack put stuff into a path that CMake would pick up...but I was even worse at spack in those days.

But maybe we could appeal to the ESMF folks for a "blessed" environment variable a la ESMFMKFILE? 🤷🏼

I can look into this next week. But that shouldn't hold up this PR.

mathomp4 commented 9 months ago

Test show this doesn't seem to affect GEOSgcm at all. I also did a MAPL build with it as well and...it built. So huzzah!