Skip to content

Commit

Permalink
Rework Fortran macros to use the proper code. (#4240)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF authored Mar 26, 2024
1 parent fb12776 commit eacb015
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 102 deletions.
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,6 @@ set (H5_FC_FUNC_ "H5_FC_FUNC_(name,NAME) name ## _")
if (EXISTS "${HDF5_SOURCE_DIR}/fortran" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/fortran")
option (HDF5_BUILD_FORTRAN "Build FORTRAN support" OFF)
if (HDF5_BUILD_FORTRAN)
include (${HDF_RESOURCES_DIR}/HDFUseFortran.cmake)

message (VERBOSE "Fortran compiler ID is ${CMAKE_Fortran_COMPILER_ID}")
include (${HDF_RESOURCES_DIR}/HDFFortranCompilerFlags.cmake)
include (${HDF_RESOURCES_DIR}/HDF5UseFortran.cmake)
Expand Down Expand Up @@ -1147,16 +1145,6 @@ if (EXISTS "${HDF5_SOURCE_DIR}/c++" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/c++")
endif ()
endif ()

#-----------------------------------------------------------------------------
# Check if Fortran's default real is double precision. If it is and HL is
# being built then configure should fail due to bug HDFFV-889.
#-----------------------------------------------------------------------------
if (HDF5_BUILD_FORTRAN AND HDF5_BUILD_HL_LIB)
if (NOT H5_FORTRAN_DEFAULT_REAL_NOT_DOUBLE)
message (FATAL_ERROR " **** Fortran high-level routines are not supported when the default REAL is DOUBLE PRECISION, use HDF5_BUILD_HL_LIB:BOOL=OFF **** ")
endif ()
endif ()

#-----------------------------------------------------------------------------
# Option to build HDF5 Java Library
#-----------------------------------------------------------------------------
Expand Down
16 changes: 2 additions & 14 deletions config/cmake/HDF5UseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,15 @@
# This file provides functions for HDF5 specific Fortran support.
#
#-------------------------------------------------------------------------------
enable_language (Fortran)
include (${HDF_RESOURCES_DIR}/HDFUseFortran.cmake)

set (HDF_PREFIX "H5")
include (CheckFortranFunctionExists)

# Force lowercase Fortran module file names
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ef")
endif ()

include (CheckFortranFunctionExists)

include (CheckFortranSourceRuns)
include (CheckFortranSourceCompiles)

# Read source line beginning at the line matching Input:"START" and ending at the line matching Input:"END"
macro (READ_SOURCE SOURCE_START SOURCE_END RETURN_VAR)
file (READ "${HDF5_SOURCE_DIR}/m4/aclocal_fc.f90" SOURCE_MASTER)
string (REGEX MATCH "${SOURCE_START}[\\\t\\\n\\\r[].+]*${SOURCE_END}" SOURCE_CODE ${SOURCE_MASTER})
set (RETURN_VAR "${SOURCE_CODE}")
endmacro ()

set (RUN_OUTPUT_PATH_DEFAULT ${CMAKE_BINARY_DIR})
# The provided CMake Fortran macros don't provide a general compile/run function
# so this one is used.
Expand Down
96 changes: 20 additions & 76 deletions config/cmake/HDFUseFortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,72 +43,26 @@ file (STRINGS ${CMAKE_BINARY_DIR}/FCMangle.h CONTENTS REGEX "H5_FC_GLOBAL_\\(.*,
string (REGEX MATCH "H5_FC_GLOBAL_\\(.*,.*\\) +(.*)" RESULT ${CONTENTS})
set (H5_FC_FUNC_ "H5_FC_FUNC_(name,NAME) ${CMAKE_MATCH_1}")

#test code source
set (SIZEOF_CODE
"
PROGRAM main
i = sizeof(x)
END PROGRAM
"
)
set (C_SIZEOF_CODE
"
PROGRAM main
USE ISO_C_BINDING
INTEGER(C_INT) :: a
INTEGER(C_SIZE_T) :: result
result = c_sizeof(a)
END PROGRAM
"
)
set (STORAGE_SIZE_CODE
"
PROGRAM main
INTEGER :: a
INTEGER :: result
result = storage_size(a)
END PROGRAM
"
)
set (CHAR_ALLOC
"
PROGRAM main
CHARACTER(:), ALLOCATABLE :: str
END PROGRAM
"
)
set (ISO_FORTRAN_ENV_CODE
"
PROGRAM main
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : atomic_logical_kind
LOGICAL(KIND=atomic_logical_kind) :: state
END PROGRAM
"
)
set (REALISNOTDOUBLE_CODE
"
MODULE type_mod
INTERFACE h5t
MODULE PROCEDURE h5t_real
MODULE PROCEDURE h5t_dble
END INTERFACE
CONTAINS
SUBROUTINE h5t_real(r)
REAL :: r
END SUBROUTINE h5t_real
SUBROUTINE h5t_dble(d)
DOUBLE PRECISION :: d
END SUBROUTINE h5t_dble
END MODULE type_mod
PROGRAM main
USE type_mod
REAL :: r
DOUBLE PRECISION :: d
CALL h5t(r)
CALL h5t(d)
END PROGRAM main
"
)
# Read source line beginning at the line matching Input:"START" and ending at the line matching Input:"END"
macro (READ_SOURCE SOURCE_START SOURCE_END RETURN_VAR)
file (READ "${HDF5_SOURCE_DIR}/m4/aclocal_fc.f90" SOURCE_MASTER)
string (REGEX MATCH "${SOURCE_START}[\\\t\\\n\\\r[].+]*${SOURCE_END}" SOURCE_CODE ${SOURCE_MASTER})
set (RETURN_VAR "${SOURCE_CODE}")
endmacro ()

if (HDF5_REQUIRED_LIBRARIES)
set (CMAKE_REQUIRED_LIBRARIES "${HDF5_REQUIRED_LIBRARIES}")
endif ()

READ_SOURCE("PROGRAM PROG_FC_SIZEOF" "END PROGRAM PROG_FC_SIZEOF" SOURCE_CODE)
check_fortran_source_compiles (${SOURCE_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF SRC_EXT f90)

READ_SOURCE("PROGRAM PROG_FC_C_SIZEOF" "END PROGRAM PROG_FC_C_SIZEOF" SOURCE_CODE)
check_fortran_source_compiles (${SOURCE_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF SRC_EXT f90)

READ_SOURCE("PROGRAM PROG_FC_STORAGE_SIZE" "END PROGRAM PROG_FC_STORAGE_SIZE" SOURCE_CODE)
check_fortran_source_compiles (${SOURCE_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE SRC_EXT f90)

set (ISO_C_BINDING_CODE
"
PROGRAM main
Expand All @@ -122,17 +76,7 @@ set (ISO_C_BINDING_CODE
END PROGRAM
"
)

if (HDF5_REQUIRED_LIBRARIES)
set (CMAKE_REQUIRED_LIBRARIES "${HDF5_REQUIRED_LIBRARIES}")
endif ()
check_fortran_source_compiles (${SIZEOF_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF SRC_EXT f90)
check_fortran_source_compiles (${C_SIZEOF_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF SRC_EXT f90)
check_fortran_source_compiles (${STORAGE_SIZE_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE SRC_EXT f90)
check_fortran_source_compiles (${ISO_FORTRAN_ENV_CODE} ${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV SRC_EXT f90)
check_fortran_source_compiles (${REALISNOTDOUBLE_CODE} ${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE SRC_EXT f90)
check_fortran_source_compiles (${ISO_C_BINDING_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING SRC_EXT f90)
check_fortran_source_compiles (${CHAR_ALLOC} ${HDF_PREFIX}_FORTRAN_HAVE_CHAR_ALLOC SRC_EXT f90)

#-----------------------------------------------------------------------------
# Add debug information (intel Fortran : JB)
Expand Down

0 comments on commit eacb015

Please sign in to comment.