Skip to content

Commit

Permalink
Link to imported target MPI::MPI_Fortran in test for MPI_IN_PLACE
Browse files Browse the repository at this point in the history
Overriding `CMAKE_Fortran_COMPILER` doesn't have an effect for `try_run`.
Instead, link to the imported target `MPI::MPI_Fortran` which should
contain all settings that are needed to build a Fortran file using MPI
functions.
Also, check if compilation of the test program failed.
  • Loading branch information
mmuetzel committed Aug 28, 2024
1 parent c929797 commit c8e0aec
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions cmake/Modules/testMPIcapabilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

if(CMAKE_CROSSCOMPILING)
# assume it is working
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${CMAKE_Fortran_COMPILER} -- assuming yes")
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${MPI_Fortran_COMPILER} -- assuming yes")
set(CHECK_MPI_IN_PLACE_RUN_ERROR OFF)
set(CHECK_MPI_IN_PLACE_COMPILE ON)
else()

set(save_CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER})
set(CMAKE_Fortran_COMPILER ${MPI_Fortran_COMPILER})
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${CMAKE_Fortran_COMPILER}")
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${MPI_Fortran_COMPILER}")

file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testMPI_IN_PLACE.f90
"
Expand All @@ -38,17 +37,14 @@ else()
END PROGRAM TEST_MPI_IN_PLACE
")
try_run(CHECK_MPI_IN_PLACE_RUN_ERROR CHECK_MPI_IN_PLACE_COMPILE ${CMAKE_BINARY_DIR}
SOURCES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testMPI_IN_PLACE.f90)
SOURCES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testMPI_IN_PLACE.f90
LINK_LIBRARIES MPI::MPI_Fortran)
endif()

if(CHECK_MPI_IN_PLACE_RUN_ERROR)
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${CMAKE_Fortran_COMPILER} -- no")
if(CHECK_MPI_IN_PLACE_RUN_ERROR OR NOT CHECK_MPI_IN_PLACE_COMPILE)
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${MPI_Fortran_COMPILER} -- no")
set(ELMER_BROKEN_MPI_IN_PLACE ON CACHE INTERNAL "")
else()
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${CMAKE_Fortran_COMPILER} -- yes")
message(STATUS "Checking whether MPI_IN_PLACE is supported with ${MPI_Fortran_COMPILER} -- yes")
set(ELMER_BROKEN_MPI_IN_PLACE OFF CACHE INTERNAL "")
endif()

if(NOT CMAKE_CROSSCOMPILING)
set(CMAKE_Fortran_COMPILER ${save_CMAKE_Fortran_COMPILER})
endif()

0 comments on commit c8e0aec

Please sign in to comment.