Skip to content

Provide switch to choose between ESMF static and shared? No, better to use ESMF's own findESMF.cmake? #70

@climbfuji

Description

@climbfuji

We are running into problems with JEDI-UFS where we get the "usual" double-free corruption because code gets linked against ESMF shared and ESMF static due to all the complicated dependencies for JEDI-UFS.

I can work around this by modifying findESMF.cmake like this, following precedence from the cmake default findHDF5.cmake:

--- /Users/heinzell/prod/spack-stack-1.7.0/envs/unified-env/install/apple-clang/13.1.6/jedi-cmake-1.4.0-mskpdnp/share/jedicmake/Modules/FindESMF.cmake.original	2024-04-09 09:26:09.000000000 -0600
+++ /Users/heinzell/prod/spack-stack-1.7.0/envs/unified-env/install/apple-clang/13.1.6/jedi-cmake-1.4.0-mskpdnp/share/jedicmake/Modules/FindESMF.cmake	2024-04-09 15:02:00.000000000 -0600
@@ -90,19 +90,12 @@
   endforeach()
   set(ESMF_F90COMPILEPATHS ${tmp})

-  # Look for static library, if not found try dynamic library
-  find_library(esmf_lib NAMES libesmf.a PATHS ${ESMF_LIBSDIR})
-  if(esmf_lib MATCHES "esmf_lib-NOTFOUND")
-    unset(esmf_lib)
-    message(STATUS "Static ESMF library not found, searching for dynamic library instead")
-    find_library(esmf_lib NAMES esmf_fullylinked libesmf.so PATHS ${ESMF_LIBSDIR})
-    if(esmf_lib MATCHES "esmf_lib-NOTFOUND")
-      unset(esmf_lib)
-      message(STATUS "Neither the dynamic nor the static ESMF library was found")
-    else()
-      set(_library_type SHARED)
-    endif()
+  # Look for static library by default unless user specifies ESMF_USE_SHARED_LIBRARIES
+  if(ESMF_USE_SHARED_LIBRARIES)
+    find_library(esmf_lib NAMES esmf_fullylinked${CMAKE_SHARED_LIBRARY_SUFFIX} libesmf${CMAKE_SHARED_LIBRARY_SUFFIX} PATHS ${ESMF_LIBSDIR})
+    set(_library_type SHARED)
   else()
+    find_library(esmf_lib NAMES libesmf${CMAKE_STATIC_LIBRARY_SUFFIX} PATHS ${ESMF_LIBSDIR})
     set(_library_type STATIC)
   endif()

The default for ESMF will still be to look for a static ESMF library, but it will fail if it doesn't find it (i.e. it will not automatically fall back to look for the shared library). When the user sets ESMF_USE_SHARED_LIBRARIES in CMakeLists.txt, then the same is true for the shared library.

Would that be an ok modification? Should we also propose this for the ESMF repo?

What is the prospect of getting rid of findESMF.py here and always use the one that comes with ESMF?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions