diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2abc7e..a9f380f7 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 af6ec851..06205545 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 d2a2cba4..38c0aa13 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)