Skip to content

Commit 4bff0cc

Browse files
committed
mpi.cmake usable in other projects
1 parent 9d91ae5 commit 4bff0cc

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ enable_testing()
88

99
message(STATUS "CMake ${CMAKE_VERSION} Generator ${CMAKE_GENERATOR}")
1010

11+
# this has checks that can be reused in other projects as well
12+
include(cmake/mpi.cmake)
13+
1114
include(cmake/compilers.cmake)
1215

1316
add_subdirectory(test)

cmake/compilers.cmake

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
include(CheckSourceCompiles)
2-
3-
set(MPI_DETERMINE_LIBRARY_VERSION true)
4-
find_package(MPI REQUIRED COMPONENTS C Fortran)
5-
message(STATUS "MPI Library Version: ${MPI_C_LIBRARY_VERSION_STRING}")
6-
7-
find_file(mpi_f08_mod NAMES mpi_f08.mod
8-
NO_DEFAULT_PATH
9-
HINTS ${MPI_Fortran_INCLUDE_DIRS}
10-
)
11-
12-
message(STATUS "${MPI_Fortran_LIBRARY_VERSION_STRING}")
13-
message(STATUS "MPI libs: ${MPI_Fortran_LIBRARIES}")
14-
message(STATUS "MPI include: ${MPI_Fortran_INCLUDE_DIRS}")
15-
message(STATUS "MPI_f08 module: ${mpi_f08_mod}")
16-
message(STATUS "MPI compile flags: ${MPI_Fortran_COMPILER_FLAGS}")
17-
message(STATUS "MPI link flags: ${MPI_Fortran_LINK_FLAGS}")
18-
19-
if(NOT mpi_f08_mod)
20-
message(WARNING "Fortran MPI ${MPI_Fortran_VERSION} doesn't have MPI-3 Fortran mpi_f08.mod, searched using ${MPI_Fortran_INCLUDE_DIRS}")
21-
endif()
22-
23-
include(${CMAKE_CURRENT_LIST_DIR}/openmpi.cmake)
24-
25-
set(CMAKE_REQUIRED_INCLUDES ${MPI_Fortran_INCLUDE_DIRS})
26-
set(CMAKE_REQUIRED_LIBRARIES ${MPI_Fortran_LIBRARIES})
27-
28-
# sometimes factory FindMPI.cmake doesn't define this
29-
check_source_compiles(Fortran
30-
[=[
31-
program test
32-
use mpi_f08, only : mpi_comm_rank, mpi_real, mpi_comm_world, mpi_init, mpi_finalize
33-
implicit none
34-
call mpi_init
35-
call mpi_finalize
36-
end program
37-
]=]
38-
MPI_Fortran_HAVE_F08_MODULE
39-
)
40-
41-
if(NOT MPI_Fortran_HAVE_F08_MODULE)
42-
message(FATAL_ERROR "Fortran MPI-3 binding not present.")
43-
endif()
44-
45-
461
if(NOT MSVC)
472
add_compile_options(-Wall)
483
endif()

cmake/mpi.cmake

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
include(CheckSourceCompiles)
2+
3+
set(MPI_DETERMINE_LIBRARY_VERSION true)
4+
find_package(MPI REQUIRED COMPONENTS C Fortran)
5+
message(STATUS "MPI Library Version: ${MPI_C_LIBRARY_VERSION_STRING}")
6+
7+
find_file(mpi_f08_mod NAMES mpi_f08.mod
8+
NO_DEFAULT_PATH
9+
HINTS ${MPI_Fortran_INCLUDE_DIRS}
10+
)
11+
12+
message(STATUS "${MPI_Fortran_LIBRARY_VERSION_STRING}")
13+
message(STATUS "MPI libs: ${MPI_Fortran_LIBRARIES}")
14+
message(STATUS "MPI include: ${MPI_Fortran_INCLUDE_DIRS}")
15+
message(STATUS "MPI_f08 module: ${mpi_f08_mod}")
16+
message(STATUS "MPI compile flags: ${MPI_Fortran_COMPILER_FLAGS}")
17+
message(STATUS "MPI link flags: ${MPI_Fortran_LINK_FLAGS}")
18+
19+
if(NOT mpi_f08_mod)
20+
message(WARNING "Fortran MPI ${MPI_Fortran_VERSION} doesn't have MPI-3 Fortran mpi_f08.mod, searched using ${MPI_Fortran_INCLUDE_DIRS}")
21+
endif()
22+
23+
include(${CMAKE_CURRENT_LIST_DIR}/openmpi.cmake)
24+
25+
set(CMAKE_REQUIRED_INCLUDES ${MPI_Fortran_INCLUDE_DIRS})
26+
set(CMAKE_REQUIRED_LIBRARIES ${MPI_Fortran_LIBRARIES})
27+
28+
# sometimes factory FindMPI.cmake doesn't define this
29+
check_source_compiles(Fortran
30+
[=[
31+
program test
32+
use mpi_f08, only : mpi_comm_rank, mpi_real, mpi_comm_world, mpi_init, mpi_finalize
33+
implicit none
34+
call mpi_init
35+
call mpi_finalize
36+
end program
37+
]=]
38+
MPI_Fortran_HAVE_F08_MODULE
39+
)
40+
41+
if(NOT MPI_Fortran_HAVE_F08_MODULE)
42+
message(FATAL_ERROR "Fortran MPI-3 binding not present.")
43+
endif()

0 commit comments

Comments
 (0)