88
88
endif ()
89
89
90
90
if (gfortran_compiler )
91
+ set (OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
91
92
set (CMAKE_REQUIRED_FLAGS "-fcoarray=single -ffree-form" )
92
93
endif ()
93
94
include (CheckFortranSourceCompiles )
@@ -99,7 +100,8 @@ CHECK_Fortran_SOURCE_COMPILES("
99
100
end program
100
101
" Check_Simple_Coarray_Fortran_Source_Compiles )
101
102
if (gfortran_compiler )
102
- unset (CMAKE_REQUIRED_FLAGS )
103
+ set (CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS} )
104
+ unset (OLD_REQUIRED_FLAGS )
103
105
endif ()
104
106
105
107
@@ -108,17 +110,37 @@ endif()
108
110
#----------------------------------------------------------------------------
109
111
110
112
# If the user passes FC=mpif90 etc. check and prefer that location
111
- get_filename_component ( FTN_MPI_DIR "${CMAKE_Fortran_COMPILER} "
113
+ get_filename_component ( FTN_COMPILER_NAME "${CMAKE_Fortran_COMPILER} "
114
+ NAME )
115
+ get_filename_component ( C_COMPILER_NAME "${CMAKE_C_COMPILER} "
116
+ NAME )
117
+ get_filename_component ( FTN_COMPILER_DIR "${CMAKE_Fortran_COMPILER} "
112
118
REALPATH )
113
- get_filename_component ( C_MPI_DIR "${CMAKE_C_COMPILER} "
119
+ get_filename_component ( C_COMPILER_DIR "${CMAKE_C_COMPILER} "
114
120
REALPATH )
115
- set ( MPI_HOME "${MPI_HOME} " "${FTN_MPI_DIR} /.." "${C_MPI_DIR} /.." )
116
121
117
- # Check the install.sh defaut mpich installation directories
118
- set ( MPI_HOME "${MPI_HOME} " "${CMAKE_SOURCE_DIR} /prerequisites/installations/mpich/3.1.4" "${CMAKE_SOURCE_DIR} /prerequisites/installations/mpich/*" )
122
+ if (FTN_COMPILER_NAME MATCHES '^[mM][pP][iI]' )
123
+ set (MPI_Fortran_COMPILER "${CMAKE_Fortran_COMPILER} " )
124
+ endif ()
125
+ if (C_COMPILER_NAME MATCHES '^[mM][pP][iI]' )
126
+ set (MPI_C_COMPILER "${CMAKE_C_COMPILER} " )
127
+ endif ()
128
+
129
+ find_package ( MPI )
130
+
131
+ if ( (NOT MPI_C_FOUND ) OR (NOT MPI_Fortran_FOUND ) )
132
+ find_program (MY_MPI_EXEC NAMES mpirun mpiexec lamexec srun
133
+ PATHS "${CMAKE_SOURCE_DIR/prerequisites/installations/mpich/3.1.4}" "${CMAKE_SOURCE_DIR} /prerequisites/installations/mpich/*" ENV PATH
134
+ HINTS "${FTN_COMPILER_DIR} " "${C_COMPILER_DIR} "
135
+ PATH_SUFFIXES bin )
136
+ set ( MPI_HOME "${MPI_HOME} " "${MY_MPI_EXEC} " "${MY_MPI_EXEC} /.." )
137
+ find_package ( MPI REQUIRED )
138
+ endif ()
119
139
120
- find_package ( MPI REQUIRED )
121
140
141
+ #----------------
142
+ # Setup MPI flags
143
+ #----------------
122
144
set (CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS} )
123
145
set (CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS} )
124
146
set (CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS} )
0 commit comments