diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index f0b649eaf..2057a513a 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -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 ################################ diff --git a/cmake/modules/FindPNETCDF.cmake b/cmake/modules/FindPNETCDF.cmake index 0bba33560..a147494db 100644 --- a/cmake/modules/FindPNETCDF.cmake +++ b/cmake/modules/FindPNETCDF.cmake @@ -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()