Skip to content

Commit

Permalink
Update to the latest version of FindESMF.cmake as per ESMF repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
theurich committed May 15, 2024
1 parent b7b66d6 commit f1061f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ESMF_HelloWorld_CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ project(ESMF_HelloWorld_CMake
add_executable(ESMF_HelloWorld ESMF_HelloWorld.F90)

# Executable depends on ESMF
target_link_libraries(ESMF_HelloWorld ESMF)
target_link_libraries(ESMF_HelloWorld ESMF::ESMF)
15 changes: 12 additions & 3 deletions ESMF_HelloWorld_CMake/cmake/FindESMF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,22 @@ if(EXISTS ${ESMFMKFILE})
message(WARNING "Static ESMF library (libesmf.a) not found in \
${ESMF_LIBSDIR}. Try setting USE_ESMF_STATIC_LIBS=OFF")
endif()
add_library(ESMF STATIC IMPORTED)
if(NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF STATIC IMPORTED)
endif()
else()
find_library(ESMF_LIBRARY_LOCATION NAMES esmf PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH)
if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND")
message(WARNING "ESMF library not found in ${ESMF_LIBSDIR}.")
endif()
add_library(ESMF UNKNOWN IMPORTED)
if(NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF UNKNOWN IMPORTED)
endif()
endif()

# Add ESMF as an alias to ESMF::ESMF for backward compatibility
if(NOT TARGET ESMF)
add_library(ESMF ALIAS ESMF::ESMF)
endif()

# Add ESMF include directories
Expand All @@ -126,7 +135,7 @@ if(EXISTS ${ESMFMKFILE})
ESMF_F90COMPILEPATHS
VERSION_VAR ESMF_VERSION)

set_target_properties(ESMF PROPERTIES
set_target_properties(ESMF::ESMF PROPERTIES
IMPORTED_LOCATION "${ESMF_LIBRARY_LOCATION}"
INTERFACE_INCLUDE_DIRECTORIES "${ESMF_INCLUDE_DIRECTORIES}"
INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}")
Expand Down

0 comments on commit f1061f2

Please sign in to comment.