Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github #969 Use stdout instead of file for configure check #1089

Merged
merged 7 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions config/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ endif ()
# so this one is used.
#-----------------------------------------------------------------------------
set (RUN_OUTPUT_PATH_DEFAULT ${CMAKE_BINARY_DIR})
macro (C_RUN FUNCTION_NAME SOURCE_CODE RETURN_VAR)
macro (C_RUN FUNCTION_NAME SOURCE_CODE RETURN_VAR RETURN_OUTPUT_VAR)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
message (VERBOSE "Detecting C ${FUNCTION_NAME}")
endif ()
Expand All @@ -248,7 +248,7 @@ macro (C_RUN FUNCTION_NAME SOURCE_CODE RETURN_VAR)
RUN_OUTPUT_VARIABLE OUTPUT_VAR
)

set (${RETURN_VAR} ${OUTPUT_VAR})
set (${RETURN_OUTPUT_VAR} ${OUTPUT_VAR})

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
message (VERBOSE "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
Expand Down Expand Up @@ -304,12 +304,11 @@ set (PROG_SRC
#define C_LDBL_DIG DECIMAL_DIG\n\
#else\n\
#define C_LDBL_DIG LDBL_DIG\n\
#endif\n\nint main() {\nFILE *pFile = fopen(\"pac_Cconftest.out\",\"w\")\\\;\nfprintf(pFile, \"\\%d\\\;\\%d\\\;\", C_LDBL_DIG, C_FLT128_DIG)\\\;\n\nreturn 0\\\;\n}\n
#endif\n\nint main() {\nprintf(\"\\%d\\\;\\%d\\\;\", C_LDBL_DIG, C_FLT128_DIG)\\\;\n\nreturn 0\\\;\n}\n
"
)

C_RUN ("maximum decimal precision for C" ${PROG_SRC} PROG_RES)
file (READ "${RUN_OUTPUT_PATH_DEFAULT}/pac_Cconftest.out" PROG_OUTPUT4)
C_RUN ("maximum decimal precision for C" ${PROG_SRC} PROG_RES PROG_OUTPUT4)
message (STATUS "Testing maximum decimal precision for C - ${PROG_OUTPUT4}")

# dnl The output from the above program will be:
Expand Down
65 changes: 29 additions & 36 deletions m4/aclocal_fc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ AC_DEFUN([PAC_PROG_FC_ISO_FORTRAN_ENV],[
AC_MSG_CHECKING([if Fortran compiler supports intrinsic module ISO_FORTRAN_ENV])
TEST_SRC="`sed -n '/PROGRAM PROG_FC_ISO_FORTRAN_ENV/,/END PROGRAM PROG_FC_ISO_FORTRAN_ENV/p' $srcdir/m4/aclocal_fc.f90`"
AC_LINK_IFELSE([$TEST_SRC],[AC_MSG_RESULT([yes])
HAVE_ISO_FORTRAN_ENV="yes"],
HAVE_ISO_FORTRAN_ENV="yes"],
[AC_MSG_RESULT([no])])
])

Expand All @@ -79,7 +79,7 @@ AC_DEFUN([PAC_PROG_FC_SIZEOF],[
AC_MSG_CHECKING([if Fortran compiler supports intrinsic SIZEOF])
TEST_SRC="`sed -n '/PROGRAM PROG_FC_SIZEOF/,/END PROGRAM PROG_FC_SIZEOF/p' $srcdir/m4/aclocal_fc.f90`"
AC_LINK_IFELSE([$TEST_SRC],[AC_MSG_RESULT([yes])
HAVE_SIZEOF_FORTRAN="yes"],
HAVE_SIZEOF_FORTRAN="yes"],
[AC_MSG_RESULT([no])])
])

Expand All @@ -90,7 +90,7 @@ AC_DEFUN([PAC_PROG_FC_C_SIZEOF],[
AC_MSG_CHECKING([if Fortran compiler supports intrinsic C_SIZEOF])
TEST_SRC="`sed -n '/PROGRAM PROG_FC_C_SIZEOF/,/END PROGRAM PROG_FC_C_SIZEOF/p' $srcdir/m4/aclocal_fc.f90`"
AC_LINK_IFELSE([$TEST_SRC], [AC_MSG_RESULT([yes])
HAVE_C_SIZEOF_FORTRAN="yes"],
HAVE_C_SIZEOF_FORTRAN="yes"],
[AC_MSG_RESULT([no])])
])

Expand All @@ -101,7 +101,7 @@ AC_DEFUN([PAC_PROG_FC_STORAGE_SIZE],[
AC_MSG_CHECKING([if Fortran compiler supports intrinsic STORAGE_SIZE])
TEST_SRC="`sed -ne '/PROGRAM PROG_FC_STORAGE_SIZE/,/END PROGRAM PROG_FC_STORAGE_SIZE/p' $srcdir/m4/aclocal_fc.f90`"
AC_LINK_IFELSE([$TEST_SRC], [AC_MSG_RESULT([yes])
HAVE_STORAGE_SIZE_FORTRAN="yes"],
HAVE_STORAGE_SIZE_FORTRAN="yes"],
[AC_MSG_RESULT([no])])

])
Expand All @@ -114,7 +114,7 @@ AC_DEFUN([PAC_PROG_FC_HAVE_C_LONG_DOUBLE],[
TEST_SRC=""
TEST_SRC="`sed -n '/PROGRAM PROG_FC_HAVE_C_LONG_DOUBLE/,/END PROGRAM PROG_FC_HAVE_C_LONG_DOUBLE/p' $srcdir/m4/aclocal_fc.f90`"
AC_LINK_IFELSE([$TEST_SRC], [AC_MSG_RESULT([yes])
HAVE_C_LONG_DOUBLE_FORTRAN="yes"],
HAVE_C_LONG_DOUBLE_FORTRAN="yes"],
[AC_MSG_RESULT([no])])
])

Expand Down Expand Up @@ -146,8 +146,8 @@ AC_DEFUN([PAC_PROG_FC_HAVE_F2003_REQUIREMENTS],[
dnl -------------------------------------------------------------------------
dnl AC_F9X_MODS()
dnl
dnl Check how F9X handles modules. This macro also checks which
dnl command-line option to use to include the module once it's built.
dnl Check how F9X handles modules. This macro also checks which
dnl command-line option to use to include the module once it's built.
dnl
AC_DEFUN([AC_F9X_MODS],
[AC_MSG_CHECKING(what $FC does with modules)
Expand Down Expand Up @@ -241,9 +241,9 @@ dnl Change to the Fortran 90 language
dnl Try link a simple MPI program.
AC_MSG_CHECKING([whether a simple MPI-IO Fortran program can be linked])
AC_LINK_IFELSE([$TEST_SRC],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([unable to link a simple MPI-IO Fortran program])])
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([unable to link a simple MPI-IO Fortran program])])

dnl Change to the C language
AC_LANG_POP(Fortran)
Expand Down Expand Up @@ -271,32 +271,32 @@ AC_RUN_IFELSE([$TEST_SRC],
dnl -- LINE 5 -- number of valid real kinds

pac_validIntKinds="`sed -n '1p' pac_fconftest.out`"
pac_validRealKinds="`sed -n '2p' pac_fconftest.out`"
pac_validRealKinds="`sed -n '2p' pac_fconftest.out`"
PAC_FC_MAX_REAL_PRECISION="`sed -n '3p' pac_fconftest.out`"
AC_DEFINE_UNQUOTED([PAC_FC_MAX_REAL_PRECISION], $PAC_FC_MAX_REAL_PRECISION, [Define Fortran Maximum Real Decimal Precision])

PAC_FC_ALL_INTEGER_KINDS="{`echo $pac_validIntKinds`}"
PAC_FC_ALL_REAL_KINDS="{`echo $pac_validRealKinds`}"

PAC_FORTRAN_NUM_INTEGER_KINDS="`sed -n '4p' pac_fconftest.out`"
H5CONFIG_F_NUM_IKIND="INTEGER, PARAMETER :: num_ikinds = `echo $PAC_FORTRAN_NUM_INTEGER_KINDS`"
H5CONFIG_F_IKIND="INTEGER, DIMENSION(1:num_ikinds) :: ikind = (/`echo $pac_validIntKinds`/)"
H5CONFIG_F_NUM_RKIND="INTEGER, PARAMETER :: num_rkinds = `sed -n '5p' pac_fconftest.out`"
H5CONFIG_F_RKIND="INTEGER, DIMENSION(1:num_rkinds) :: rkind = (/`echo $pac_validRealKinds`/)"
H5CONFIG_F_NUM_IKIND="INTEGER, PARAMETER :: num_ikinds = `echo $PAC_FORTRAN_NUM_INTEGER_KINDS`"
H5CONFIG_F_IKIND="INTEGER, DIMENSION(1:num_ikinds) :: ikind = (/`echo $pac_validIntKinds`/)"
H5CONFIG_F_NUM_RKIND="INTEGER, PARAMETER :: num_rkinds = `sed -n '5p' pac_fconftest.out`"
H5CONFIG_F_RKIND="INTEGER, DIMENSION(1:num_rkinds) :: rkind = (/`echo $pac_validRealKinds`/)"

AC_DEFINE_UNQUOTED([H5CONFIG_F_NUM_RKIND], $H5CONFIG_F_NUM_RKIND, [Define number of valid Fortran REAL KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_NUM_IKIND], $H5CONFIG_F_NUM_IKIND, [Define number of valid Fortran INTEGER KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_RKIND], $H5CONFIG_F_RKIND, [Define valid Fortran REAL KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_IKIND], $H5CONFIG_F_IKIND, [Define valid Fortran INTEGER KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_NUM_RKIND], $H5CONFIG_F_NUM_RKIND, [Define number of valid Fortran REAL KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_NUM_IKIND], $H5CONFIG_F_NUM_IKIND, [Define number of valid Fortran INTEGER KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_RKIND], $H5CONFIG_F_RKIND, [Define valid Fortran REAL KINDs])
AC_DEFINE_UNQUOTED([H5CONFIG_F_IKIND], $H5CONFIG_F_IKIND, [Define valid Fortran INTEGER KINDs])

AC_MSG_CHECKING([for Number of Fortran INTEGER KINDs])
AC_MSG_RESULT([$PAC_FORTRAN_NUM_INTEGER_KINDS])
AC_MSG_CHECKING([for Fortran INTEGER KINDs])
AC_MSG_RESULT([$PAC_FC_ALL_INTEGER_KINDS])
AC_MSG_CHECKING([for Fortran REAL KINDs])
AC_MSG_RESULT([$PAC_FC_ALL_REAL_KINDS])
AC_MSG_CHECKING([for Fortran REALs maximum decimal precision])
AC_MSG_RESULT([$PAC_FC_MAX_REAL_PRECISION])
AC_MSG_CHECKING([for Fortran REAL KINDs])
AC_MSG_RESULT([$PAC_FC_ALL_REAL_KINDS])
AC_MSG_CHECKING([for Fortran REALs maximum decimal precision])
AC_MSG_RESULT([$PAC_FC_MAX_REAL_PRECISION])
else
AC_MSG_RESULT([Error])
AC_MSG_ERROR([No output from Fortran test program!])
Expand Down Expand Up @@ -402,9 +402,9 @@ rm -f pac_fconftest.out
DOUBLE PRECISION c
OPEN(8, FILE='pac_fconftest.out', FORM='formatted')
WRITE(8,*) $FC_SIZEOF_A
WRITE(8,*) KIND(a)
WRITE(8,*) $FC_SIZEOF_B
WRITE(8,*) KIND(b)
WRITE(8,*) KIND(a)
WRITE(8,*) $FC_SIZEOF_B
WRITE(8,*) KIND(b)
WRITE(8,*) $FC_SIZEOF_C
WRITE(8,*) KIND(c)
CLOSE(8)
Expand Down Expand Up @@ -458,19 +458,12 @@ rm -f pac_Cconftest.out
#define C_LDBL_DIG LDBL_DIG
#endif
],[[
FILE * pFile;
pFile = fopen("pac_Cconftest.out","w");
fprintf(pFile, "%d\n%d\n", C_LDBL_DIG, C_FLT128_DIG);
fprintf(stderr, "%d\n%d\n", C_LDBL_DIG, C_FLT128_DIG);
]])
])
AC_RUN_IFELSE([],[
if test -s pac_Cconftest.out ; then
LDBL_DIG="`sed -n '1p' pac_Cconftest.out`"
FLT128_DIG="`sed -n '2p' pac_Cconftest.out`"
else
AC_MSG_ERROR([No output from C decimal precision program!])
fi
rm -f pac_Cconftest.out
LDBL_DIG=$(./conftest$EXEEXT 2>&1 | sed -n '1p')
FLT128_DIG=$(./conftest$EXEEXT 2>&1 | sed -n '2p')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this fails? the error check was removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the values will be empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it fails during build instead of in configure with probably an obscure error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check in configure was only that the file existed and sed could read the file. It didn't check values.
We can add a configure-time check that the values are non-zero?

],[
AC_MSG_ERROR([C program fails to build or run!])
],[])
Expand Down