-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmpi.cmake
More file actions
65 lines (51 loc) · 1.52 KB
/
Copy pathmpi.cmake
File metadata and controls
65 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function(check_mpi)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_FLAGS)
# --- test Fortran MPI
set(CMAKE_REQUIRED_LIBRARIES MPI::MPI_Fortran Threads::Threads)
include(CheckFortranSourceCompiles)
if(NOT DEFINED MPI_Fortran_OK)
message(STATUS "Fortran MPI:
Libs: ${MPI_Fortran_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
Include: ${MPI_Fortran_INCLUDE_DIRS}
MPIexec: ${MPIEXEC_EXECUTABLE}"
)
endif()
check_fortran_source_compiles("use mpi
integer :: i
call mpi_init(i)
call mpi_finalize(i)
end" MPI_Fortran_OK SRC_EXT F90)
if(NOT MPI_Fortran_OK)
message(FATAL_ERROR "MPI_Fortran not working. Please use 'cmake -Dmpi=off' option")
endif()
# --- test C MPI
set(CMAKE_REQUIRED_LIBRARIES MPI::MPI_C Threads::Threads)
include(CheckCSourceCompiles)
if(NOT DEFINED MPI_C_OK)
message(STATUS "C MPI:
Libs: ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
Include: ${MPI_C_INCLUDE_DIRS}"
)
endif()
check_c_source_compiles("
#include <mpi.h>
#ifndef NULL
#define NULL 0
#endif
int main(void) {
MPI_Init(NULL, NULL);
MPI_Finalize();
return 0;}
" MPI_C_OK)
if(NOT MPI_C_OK)
message(FATAL_ERROR "MPI_C not working. Please use 'cmake -Dmpi=off' option")
endif()
endfunction(check_mpi)
if(NOT TARGET MPI::MPI_C OR NOT TARGET MPI::MPI_Fortran)
find_package(MPI COMPONENTS C Fortran REQUIRED)
endif()
# NOTE: to make this not REQUIRED means making a 2nd target that is used instead of MPI::MPI_Fortran directly
# this is because the imported targets cannot be overwritten from find_package attempt
find_package(Threads)
check_mpi()