Skip to content

Commit

Permalink
add in m4 macro to check if cray module output flag is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Mulhall authored and Ryan Mulhall committed Jul 25, 2024
1 parent 77382e3 commit 209c498
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ if test "$enable_code_coverage" = yes; then
fi
AM_CONDITIONAL(COV, [test "$enable_code_coverage" = yes])


# Require netCDF
GX_FC_CHECK_MOD([netcdf], [], [], [AC_MSG_ERROR([Can't find the netCDF Fortran module. Set CPPFLAGS/FCFLAGS])])
GX_FORTRAN_SEARCH_LIBS([nf90_create], [netcdff], [use netcdf], [iret = nf90_create('foo.nc', 1, ncid)], [],
[AC_MSG_ERROR([Can't find the netCDF Fortran library. Set LDFLAGS/LIBS])])


# Check if we get a floating point exception with netcdf
# this will only get triggered if you have FPE traps enabled via FCFLAGS
AC_MSG_CHECKING([if HDF5 version causes floating point exceptions with set flags])
Expand All @@ -273,6 +275,10 @@ if test $hdf5_fpe_bug = yes; then
NetCDF must be built with a HDF5 version other than 1.14.3 to support floating point exception traps.])
fi

rm test.nc

# Check if we need a flag to not capitalize module output (needed with cray compiler)
GX_FC_MOD_CASE_FLAG([FCFLAGS="$FCFLAGS $FC_MOD_CASE_FLAG"])

# Check if Fortran compiler has the Class, Character array assign bug
GX_FC_CLASS_CHAR_ARRAY_BUG_CHECK()
Expand Down
54 changes: 54 additions & 0 deletions m4/gx_fortran_options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# GX_FC_CRAY_POINTER_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
# GX_FC_INTERNAL_FILE_NML()
# GX_FC_CHECK_MOD(module-name, [only], [action-if-found], [action-if-not-found])
# GX_FC_MOD_OUTPUT_CASE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
#
# DESCRIPTION
#
Expand Down Expand Up @@ -405,3 +406,56 @@ AC_DEFUN([_GX_FORTRAN_PP_SRCEXT_POP], [
AS_VAR_SET_IF([_gx_fortran_pp_srcext_save], [ac_ext=${_gx_fortran_pp_srcext_save}], [ac_ext="f"])
unset _gx_fortran_pp_srcext_save
])# _GX_FORTRAN_PP_SRCEXT_POP


# GX_FC_MOD_CASE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
# -----------------------------------------------------------------------------
# Checks if the output .mod files are in uppercase by default.
# This has only been seen with cray compiler. A flag is required to disable the uppercase output
# and instead follow the case of the module name as written in the source file.
#
# Sets the variable FC_MOD_CASE_FLAG to hold the flag that disables the behavior.
#
AC_DEFUN([GX_FC_MOD_CASE_FLAG],[
AC_LANG_PUSH([Fortran])
AC_FC_SRCEXT(F90)
AC_CACHE_CHECK([if Fortran flag needed for module output case], [gx_cv_fc_mod_case_flag],[
gx_cv_fc_mod_case_flag="unknown"
gx_mod_case_flag_FCFLAGS_save=$FCFLAGS
FCFLAGS="$gx_mod_case_flag_FCFLAGS_save -c"
AC_COMPILE_IFELSE([[module foo
end module foo]],
[],
AC_MSG_ERROR(["Failed to compile test module with -c"]))
# if output .mod file is capitalized, add the flag and check that it works
if test -f "FOO.mod"; then
FCFLAGS="$gx_mod_case_flag_FCFLAGS_save -c -ef"
AC_COMPILE_IFELSE([[module foo
end module mod]],
[])
if test -f "foo.mod"; then
gx_cv_fc_mod_case_flag="-ef"
fi
else
gx_cv_fc_mod_case_flag="notneeded"
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
FCFLAGS=$gx_mod_case_flag_FCFLAGS_save
])
if test "x$gx_cv_fc_mod_case_flag" = "xunknown"; then
m4_default([$2],
[AC_MSG_ERROR([No working flag found to disable .mod filename capitalization])])
elif test "x$gx_cv_fc_mod_case_flag" != "notneeded"; then
AC_DEFINE([NEEDS_MOD_OUTPUT_CASE_FLAG], 1,
[Define to 1 if your Fortran compiler requires a flag to match case of module names])
FC_MOD_CASE_FLAG=$gx_cv_fc_mod_case_flag
$1
fi
AC_LANG_POP([Fortran])
AC_SUBST([FC_MOD_CASE_FLAG])
])

0 comments on commit 209c498

Please sign in to comment.