Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
climbfuji opened this issue Apr 9, 2024 · 1 comment · May be fixed by #71

Comments

@climbfuji
Copy link
Collaborator

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?

@climbfuji
Copy link
Collaborator Author

Actually, looking at ESMF's own findESMF.cmake, they already have something like this, just with shared being the default (which makes sense, since this is more common nowadays). See attached screenshot for a diff ouf our (develop) findESMF.cmake an the esmf-8.6.0 findESMF.cmake.

It think we should get rid of findESMF.cmake in CMakeModules and make sure the spack package is configured correctly to point cmake to the version provided by ESMF itself.

@climbfuji climbfuji changed the title Provide switch to choose between ESMF static and shared? Provide switch to choose between ESMF static and shared? No, better to use ESMF's own findESMF.cmake? Apr 9, 2024
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 a pull request may close this issue.

1 participant