8888endif ()
8989
9090if (gfortran_compiler)
91+ set (OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
9192 set (CMAKE_REQUIRED_FLAGS "-fcoarray=single -ffree-form" )
9293endif ()
9394include (CheckFortranSourceCompiles)
@@ -99,7 +100,8 @@ CHECK_Fortran_SOURCE_COMPILES("
99100 end program
100101" Check_Simple_Coarray_Fortran_Source_Compiles)
101102if (gfortran_compiler)
102- unset (CMAKE_REQUIRED_FLAGS)
103+ set (CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS} )
104+ unset (OLD_REQUIRED_FLAGS)
103105endif ()
104106
105107
@@ -108,17 +110,37 @@ endif()
108110#----------------------------------------------------------------------------
109111
110112# 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} "
112118 REALPATH )
113- get_filename_component ( C_MPI_DIR "${CMAKE_C_COMPILER} "
119+ get_filename_component ( C_COMPILER_DIR "${CMAKE_C_COMPILER} "
114120 REALPATH )
115- set ( MPI_HOME "${MPI_HOME} " "${FTN_MPI_DIR} /.." "${C_MPI_DIR} /.." )
116121
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 ()
119139
120- find_package ( MPI REQUIRED )
121140
141+ #----------------
142+ # Setup MPI flags
143+ #----------------
122144set (CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS} )
123145set (CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS} )
124146set (CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS} )
0 commit comments