From 834569258036688ca939bd6d29aafe500636d5ad Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 11 Jun 2024 11:07:22 +0200 Subject: [PATCH] Fix MPI support Signed-off-by: Cristian Le --- CMakeLists.txt | 5 ++++- cmake/Wannier90Config.cmake.in | 16 ++++++++++++++++ src/CMakeLists.txt | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2abc7e3..a9f380f70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,10 @@ set(Wannier90_MPI ${WANNIER90_WITH_MPI}) find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) if (WANNIER90_MPI) - find_package(MPI REQUIRED) + find_package(MPI REQUIRED COMPONENTS Fortran) + if (NOT MPI_Fortran_HAVE_F08_MODULE) + message(SEND_ERROR "mpi_f08 module is required for building Wannier90 with MPI") + endif () endif () #[=============================================================================[ diff --git a/cmake/Wannier90Config.cmake.in b/cmake/Wannier90Config.cmake.in index af6ec851c..062055458 100644 --- a/cmake/Wannier90Config.cmake.in +++ b/cmake/Wannier90Config.cmake.in @@ -4,5 +4,21 @@ ## Define basic variables set(Wannier90_MPI @WANNIER90_MPI@) +## Include dependencies +include(CMakeFindDependencyMacro) +if (Wannier90_MPI) + # Note: In the future the MPI support can be converted to an (optional) package component. + # This would however require a breaking change in the library definition + find_dependency(MPI COMPONENTS Fortran) + if (NOT MPI_Fortran_FOUND OR NOT MPI_Fortran_HAVE_F08_MODULE) + message(WARNING + "Wannier90 was built and packaged with MPI, but the system does not have compatible MPI support.\n" + "This is an issue with the packager of Wannier90." + ) + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) + return() + endif () +endif () + ## Parse find_package request include(${CMAKE_CURRENT_LIST_DIR}/Wannier90Targets.cmake) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d2a2cba42..38c0aa13b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,10 @@ target_sources(Wannier90_lib ${CMAKE_Fortran_MODULE_DIRECTORY}/w90_library.mod ) if (WANNIER90_MPI) - target_link_libraries(Wannier90_lib PRIVATE MPI::MPI_Fortran) + target_link_libraries(Wannier90_lib PUBLIC MPI::MPI_Fortran) + target_compile_definitions(Wannier90_lib PRIVATE + MPI08 MPI + ) endif () add_subdirectory(postw90)