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

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

Merged
merged 1 commit into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -234,7 +234,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 @@ -250,7 +250,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 @@ -306,12 +306,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
71 changes: 22 additions & 49 deletions config/cmake/HDF5UseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ macro (READ_SOURCE SOURCE_START SOURCE_END RETURN_VAR)
endmacro ()

set (RUN_OUTPUT_PATH_DEFAULT ${CMAKE_BINARY_DIR})
if (NOT CMAKE_VERSION VERSION_LESS "3.14.0")
if (HDF5_REQUIRED_LIBRARIES)
set (CMAKE_REQUIRED_LIBRARIES "${HDF5_REQUIRED_LIBRARIES}")
endif ()
else ()
# The provided CMake Fortran macros don't provide a general compile/run function
# so this one is used.
#-----------------------------------------------------------------------------
macro (FORTRAN_RUN FUNCTION_NAME SOURCE_CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR1 RETURN_VAR)
macro (FORTRAN_RUN FUNCTION_NAME SOURCE_CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR1 RETURN_VAR RETURN_OUTPUT_VAR)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
message (VERBOSE "Detecting Fortran ${FUNCTION_NAME}")
endif ()
Expand All @@ -52,7 +47,9 @@ macro (FORTRAN_RUN FUNCTION_NAME SOURCE_CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR1
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler1.f90
LINK_LIBRARIES "${HDF5_REQUIRED_LIBRARIES}"
RUN_OUTPUT_VARIABLE OUTPUT_VAR
)
set (${RETURN_OUTPUT_VAR} ${OUTPUT_VAR})

if (${COMPILE_RESULT_VAR})
set(${RETURN_VAR} ${RUN_RESULT_VAR})
Expand Down Expand Up @@ -81,7 +78,6 @@ macro (FORTRAN_RUN FUNCTION_NAME SOURCE_CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR1
set(${RETURN_VAR} ${COMPILE_RESULT_VAR})
endif ()
endmacro ()
endif ()
#-----------------------------------------------------------------------------
# Check to see C_LONG_DOUBLE is available

Expand Down Expand Up @@ -130,25 +126,20 @@ endif ()
#-----------------------------------------------------------------------------

READ_SOURCE ("PROGRAM FC_AVAIL_KINDS" "END PROGRAM FC_AVAIL_KINDS" SOURCE_CODE)
if (NOT CMAKE_VERSION VERSION_LESS "3.14.0")
check_fortran_source_runs (${SOURCE_CODE} FC_AVAIL_KINDS_RESULT SRC_EXT f90)
else ()
FORTRAN_RUN ("REAL and INTEGER KINDs"
"${SOURCE_CODE}"
XX
YY
FC_AVAIL_KINDS_RESULT
PROG_OUTPUT
)
endif ()

# dnl The output from the above program will be:
# dnl -- LINE 1 -- valid integer kinds (comma seperated list)
# dnl -- LINE 2 -- valid real kinds (comma seperated list)
# dnl -- LINE 3 -- max decimal precision for reals
# dnl -- LINE 4 -- number of valid integer kinds
# dnl -- LINE 5 -- number of valid real kinds

file (READ "${RUN_OUTPUT_PATH_DEFAULT}/pac_fconftest.out" PROG_OUTPUT)
#
# Convert the string to a list of strings by replacing the carriage return with a semicolon
string (REGEX REPLACE "\n" ";" PROG_OUTPUT "${PROG_OUTPUT}")

Expand Down Expand Up @@ -196,20 +187,14 @@ foreach (KIND ${VAR})
"
PROGRAM main
USE ISO_C_BINDING
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stderr=>ERROR_UNIT
IMPLICIT NONE
INTEGER (KIND=${KIND}) a
OPEN(8,FILE='pac_validIntKinds.${KIND}.out',FORM='formatted')
WRITE(8,'(I0)') ${FC_SIZEOF_A}
CLOSE(8)
WRITE(stderr,'(I0)') ${FC_SIZEOF_A}
END
"
)
if (NOT CMAKE_VERSION VERSION_LESS "3.14.0")
check_fortran_source_runs (${PROG_SRC_${KIND}} VALIDINTKINDS_RESULT_${KIND} SRC_EXT f90)
else ()
FORTRAN_RUN("INTEGER KIND SIZEOF" ${PROG_SRC_${KIND}} XX YY VALIDINTKINDS_RESULT_${KIND})
endif ()
file (READ "${RUN_OUTPUT_PATH_DEFAULT}/pac_validIntKinds.${KIND}.out" PROG_OUTPUT1)
FORTRAN_RUN("INTEGER KIND SIZEOF" ${PROG_SRC_${KIND}} XX YY VALIDINTKINDS_RESULT_${KIND} PROG_OUTPUT1)
string (REGEX REPLACE "\n" "" PROG_OUTPUT1 "${PROG_OUTPUT1}")
set (pack_int_sizeof "${pack_int_sizeof} ${PROG_OUTPUT1},")
endforeach ()
Expand Down Expand Up @@ -245,22 +230,16 @@ foreach (KIND ${VAR} )
"
PROGRAM main
USE ISO_C_BINDING
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stderr=>ERROR_UNIT
IMPLICIT NONE
REAL (KIND=${KIND}) a
OPEN(8,FILE='pac_validRealKinds.${KIND}.out',FORM='formatted')
WRITE(8,'(I0)') ${FC_SIZEOF_A}
CLOSE(8)
WRITE(stderr,'(I0)') ${FC_SIZEOF_A}
END
"
)
if (NOT CMAKE_VERSION VERSION_LESS "3.14.0")
check_fortran_source_runs (${PROG_SRC2_${KIND}} VALIDREALKINDS_RESULT_${KIND} SRC_EXT f90)
else ()
FORTRAN_RUN ("REAL KIND SIZEOF" ${PROG_SRC2_${KIND}} XX YY VALIDREALKINDS_RESULT_${KIND})
endif ()
file (READ "${RUN_OUTPUT_PATH_DEFAULT}/pac_validRealKinds.${KIND}.out" PROG_OUTPUT1)
string (REGEX REPLACE "\n" "" PROG_OUTPUT1 "${PROG_OUTPUT1}")
set (pack_real_sizeof "${pack_real_sizeof} ${PROG_OUTPUT1},")
FORTRAN_RUN ("REAL KIND SIZEOF" ${PROG_SRC2_${KIND}} XX YY VALIDREALKINDS_RESULT_${KIND} PROG_OUTPUT2)
string (REGEX REPLACE "\n" "" PROG_OUTPUT2 "${PROG_OUTPUT2}")
set (pack_real_sizeof "${pack_real_sizeof} ${PROG_OUTPUT2},")
endforeach ()

if (pack_real_sizeof STREQUAL "")
Expand Down Expand Up @@ -293,35 +272,29 @@ set (PROG_SRC3
"
PROGRAM main
USE ISO_C_BINDING
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stderr=>ERROR_UNIT
IMPLICIT NONE
INTEGER a
REAL b
DOUBLE PRECISION c
OPEN(8,FILE='pac_sizeof_native_kinds.out',FORM='formatted')
WRITE(8,*) ${FC_SIZEOF_A}
WRITE(8,*) kind(a)
WRITE(8,*) ${FC_SIZEOF_B}
WRITE(8,*) kind(b)
WRITE(8,*) ${FC_SIZEOF_C}
WRITE(8,*) kind(c)
CLOSE(8)
WRITE(stderr,*) ${FC_SIZEOF_A}
WRITE(stderr,*) kind(a)
WRITE(stderr,*) ${FC_SIZEOF_B}
WRITE(stderr,*) kind(b)
WRITE(stderr,*) ${FC_SIZEOF_C}
WRITE(stderr,*) kind(c)
END
"
)
if (NOT CMAKE_VERSION VERSION_LESS "3.14.0")
check_fortran_source_runs (${PROG_SRC3} PAC_SIZEOF_NATIVE_KINDS_RESULT SRC_EXT f90)
else ()
FORTRAN_RUN ("SIZEOF NATIVE KINDs" ${PROG_SRC3} XX YY PAC_SIZEOF_NATIVE_KINDS_RESULT)
endif ()
file (READ "${RUN_OUTPUT_PATH_DEFAULT}/pac_sizeof_native_kinds.out" PROG_OUTPUT3)
FORTRAN_RUN ("SIZEOF NATIVE KINDs" ${PROG_SRC3} XX YY PAC_SIZEOF_NATIVE_KINDS_RESULT PROG_OUTPUT3)
# dnl The output from the above program will be:
# dnl -- LINE 1 -- sizeof INTEGER
# dnl -- LINE 2 -- kind of INTEGER
# dnl -- LINE 3 -- sizeof REAL
# dnl -- LINE 4 -- kind of REAL
# dnl -- LINE 5 -- sizeof DOUBLE PRECISION
# dnl -- LINE 6 -- kind of DOUBLE PRECISION

#
# Convert the string to a list of strings by replacing the carriage return with a semicolon
string (REGEX REPLACE "\n" ";" PROG_OUTPUT3 "${PROG_OUTPUT3}")

Expand Down
21 changes: 10 additions & 11 deletions m4/aclocal_fc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ END PROGRAM PROG_FC_C_LONG_DOUBLE_EQ_C_DOUBLE

!---- START ----- Determine the available KINDs for REALs and INTEGERs
PROGRAM FC_AVAIL_KINDS
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stderr=>ERROR_UNIT
IMPLICIT NONE
INTEGER :: ik, jk, k, kk, max_decimal_prec
INTEGER :: prev_rkind, num_rkinds = 1, num_ikinds = 1
INTEGER, DIMENSION(1:10) :: list_ikinds = -1
INTEGER, DIMENSION(1:10) :: list_rkinds = -1
LOGICAL :: new_kind

OPEN(8, FILE='pac_fconftest.out', FORM='formatted')

! Find integer KINDs
list_ikinds(num_ikinds)=SELECTED_INT_KIND(1)
DO ik = 2, 36
Expand All @@ -103,11 +102,11 @@ PROGRAM FC_AVAIL_KINDS
ENDDO

DO k = 1, num_ikinds
WRITE(8,'(I0)', ADVANCE='NO') list_ikinds(k)
WRITE(stderr,'(I0)', ADVANCE='NO') list_ikinds(k)
IF(k.NE.num_ikinds)THEN
WRITE(8,'(A)',ADVANCE='NO') ','
WRITE(stderr,'(A)',ADVANCE='NO') ','
ELSE
WRITE(8,'()')
WRITE(stderr,'()')
ENDIF
ENDDO

Expand Down Expand Up @@ -140,17 +139,17 @@ PROGRAM FC_AVAIL_KINDS
ENDDO prec

DO k = 1, num_rkinds
WRITE(8,'(I0)', ADVANCE='NO') list_rkinds(k)
WRITE(stderr,'(I0)', ADVANCE='NO') list_rkinds(k)
IF(k.NE.num_rkinds)THEN
WRITE(8,'(A)',ADVANCE='NO') ','
WRITE(stderr,'(A)',ADVANCE='NO') ','
ELSE
WRITE(8,'()')
WRITE(stderr,'()')
ENDIF
ENDDO

WRITE(8,'(I0)') max_decimal_prec
WRITE(8,'(I0)') num_ikinds
WRITE(8,'(I0)') num_rkinds
WRITE(stderr,'(I0)') max_decimal_prec
WRITE(stderr,'(I0)') num_ikinds
WRITE(stderr,'(I0)') num_rkinds
END PROGRAM FC_AVAIL_KINDS
!---- END ----- Determine the available KINDs for REALs and INTEGERs

Expand Down
Loading