CMake: Ensure pnetcdf links to MPI, libm

This commit is contained in:
Peter Hill 2024-01-24 10:39:06 +00:00
parent 4835e43f33
commit e88dc9c8e6
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
2 changed files with 14 additions and 7 deletions

View File

@ -615,6 +615,13 @@ if(ENABLE_LIBXML2)
endif()
endif(ENABLE_LIBXML2)
################################
# MPI
################################
if(ENABLE_PARALLEL4 OR HDF5_PARALLEL)
find_package(MPI REQUIRED)
endif()
################################
# Parallel IO
################################
@ -622,13 +629,6 @@ if(ENABLE_PNETCDF)
find_package(PNETCDF 1.6.0 REQUIRED)
endif()
################################
# MPI
################################
if(ENABLE_PARALLEL4 OR HDF5_PARALLEL OR ENABLE_PNETCDF)
find_package(MPI REQUIRED)
endif()
################################
# Doxygen
################################

View File

@ -63,9 +63,16 @@ find_package_handle_standard_args(PNETCDF
)
if (PNETCDF_FOUND AND NOT TARGET PNETCDF::PNETCDF)
find_package(MPI REQUIRED)
add_library(PNETCDF::PNETCDF UNKNOWN IMPORTED)
set_target_properties(PNETCDF::PNETCDF PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES MPI::MPI_C
IMPORTED_LOCATION "${PNETCDF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${PNETCDF_INCLUDE_DIR}"
)
find_library(MATH_LIBRARY m)
if (MATH_LIBRARY)
set_target_properties(PNETCDF::PNETCDF PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES ${MATH_LIBRARY})
endif()
endif()