2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
## Check for non-standard extenstion quadmath.h
|
|
|
|
|
|
|
|
CHECK_INCLUDE_FILES(quadmath.h C_HAVE_QUADMATH)
|
|
|
|
|
|
|
|
if (${C_HAVE_QUADMATH})
|
|
|
|
set(HAVE_QUADMATH 1)
|
|
|
|
else ()
|
|
|
|
set(HAVE_QUADMATH 0)
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# This file provides functions for HDF5 specific Fortran support.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
ENABLE_LANGUAGE (Fortran)
|
|
|
|
|
|
|
|
# The provided CMake Fortran macros don't provide a general compile/run function
|
|
|
|
# so this one is used.
|
|
|
|
#-----------------------------------------------------------------------------
|
2017-03-02 04:47:53 +08:00
|
|
|
macro (FORTRAN_RUN FUNCTION CODE RUN_RESULT_VAR1 COMPILE_RESULT_VAR RETURN)
|
2016-07-19 02:37:17 +08:00
|
|
|
#
|
2017-01-11 07:09:53 +08:00
|
|
|
# if (NOT DEFINED ${RUN_RESULT_VAR})
|
2015-08-11 22:35:30 +08:00
|
|
|
message (STATUS "Detecting Fortran ${FUNCTION}")
|
|
|
|
if (CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
|
|
|
|
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
|
2017-01-11 07:09:53 +08:00
|
|
|
else ()
|
2015-08-11 22:35:30 +08:00
|
|
|
set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
file (WRITE
|
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler1.f90
|
|
|
|
"${CODE}"
|
|
|
|
)
|
|
|
|
TRY_RUN (RUN_RESULT_VAR COMPILE_RESULT_VAR
|
|
|
|
${CMAKE_BINARY_DIR}
|
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler1.f90
|
|
|
|
CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
|
|
|
|
RUN_OUTPUT_VARIABLE OUTPUT
|
|
|
|
)
|
|
|
|
|
|
|
|
set(${RETURN} ${OUTPUT})
|
2017-01-11 07:09:53 +08:00
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
#message ( "Test result1 ${RETURN} ")
|
|
|
|
#message ( "Test result3 ${RESULT} ")
|
|
|
|
#message ( "Test result2 ${CMAKE_MATCH_0} ")
|
|
|
|
#message ( "Test result4 ${CMAKE_MATCH_1} ")
|
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
|
|
|
#message ( "Test result2 ${COMPILE_RESULT_VAR} ")
|
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
|
|
|
#message ( "Test result1 ${RUN_RESULT_VAR} ")
|
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
|
|
|
|
|
|
|
if (${COMPILE_RESULT_VAR})
|
|
|
|
if (${RUN_RESULT_VAR} MATCHES 0)
|
|
|
|
message (STATUS "Testing Fortran ${FUNCTION} - OK")
|
|
|
|
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
|
|
|
"Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n"
|
|
|
|
)
|
|
|
|
else ()
|
|
|
|
message (STATUS "Testing Fortran ${FUNCTION} - Fail")
|
|
|
|
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
|
|
|
"Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2017-01-11 07:09:53 +08:00
|
|
|
# endif ()
|
2017-03-02 04:47:53 +08:00
|
|
|
endmacro ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2016-07-19 02:37:17 +08:00
|
|
|
# Read source line beginning at the line matching Input:"START" and ending at the line matching Input:"END"
|
2017-03-02 04:47:53 +08:00
|
|
|
macro (READ_SOURCE START END RETURN)
|
2017-01-11 07:09:53 +08:00
|
|
|
file (READ "${HDF5_SOURCE_DIR}/m4/aclocal_fc.f90" CODE)
|
|
|
|
string (REGEX MATCH "${START}[\\\t\\\n\\\r[].+]*${END}" CODE ${CODE})
|
|
|
|
set (RETURN "${CODE}")
|
2017-03-02 04:47:53 +08:00
|
|
|
endmacro ()
|
2016-07-19 02:37:17 +08:00
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Check to see C_LONG_DOUBLE is available
|
2016-07-19 02:37:17 +08:00
|
|
|
|
|
|
|
READ_SOURCE("PROGRAM PROG_FC_HAVE_C_LONG_DOUBLE" "END PROGRAM PROG_FC_HAVE_C_LONG_DOUBLE" CODE)
|
2015-08-11 22:35:30 +08:00
|
|
|
CHECK_FORTRAN_FEATURE(c_long_double
|
2016-07-19 02:37:17 +08:00
|
|
|
"${CODE}"
|
2015-08-11 22:35:30 +08:00
|
|
|
FORTRAN_HAVE_C_LONG_DOUBLE
|
|
|
|
)
|
2016-07-19 02:37:17 +08:00
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
if (${FORTRAN_HAVE_C_LONG_DOUBLE})
|
2017-01-11 07:09:53 +08:00
|
|
|
set (FORTRAN_HAVE_C_LONG_DOUBLE 1)
|
2015-08-11 22:35:30 +08:00
|
|
|
else ()
|
2017-01-11 07:09:53 +08:00
|
|
|
set (FORTRAN_HAVE_C_LONG_DOUBLE 0)
|
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
# Check to see C_LONG_DOUBLE is different from C_DOUBLE
|
|
|
|
|
2016-07-19 02:37:17 +08:00
|
|
|
READ_SOURCE("MODULE type_mod" "END PROGRAM PROG_FC_C_LONG_DOUBLE_EQ_C_DOUBLE" CODE)
|
2015-08-11 22:35:30 +08:00
|
|
|
CHECK_FORTRAN_FEATURE(c_long_double
|
2016-07-19 02:37:17 +08:00
|
|
|
"${CODE}"
|
2015-08-11 22:35:30 +08:00
|
|
|
FORTRAN_C_LONG_DOUBLE_IS_UNIQUE
|
|
|
|
)
|
|
|
|
if (${FORTRAN_C_LONG_DOUBLE_IS_UNIQUE})
|
2017-01-11 07:09:53 +08:00
|
|
|
set (FORTRAN_C_LONG_DOUBLE_IS_UNIQUE 1)
|
2015-08-11 22:35:30 +08:00
|
|
|
else ()
|
2017-01-11 07:09:53 +08:00
|
|
|
set (FORTRAN_C_LONG_DOUBLE_IS_UNIQUE 0)
|
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
## Set the sizeof function for use later in the fortran tests
|
2017-01-11 07:09:53 +08:00
|
|
|
if (FORTRAN_HAVE_STORAGE_SIZE)
|
|
|
|
set (FC_SIZEOF_A "STORAGE_SIZE(a, c_size_t)/STORAGE_SIZE(c_char_'a',c_size_t)")
|
|
|
|
set (FC_SIZEOF_B "STORAGE_SIZE(b, c_size_t)/STORAGE_SIZE(c_char_'a',c_size_t)")
|
|
|
|
set (FC_SIZEOF_C "STORAGE_SIZE(c, c_size_t)/STORAGE_SIZE(c_char_'a',c_size_t)")
|
|
|
|
elseif (FORTRAN_HAVE_C_SIZEOF)
|
|
|
|
set (FC_SIZEOF_A "SIZEOF(a)")
|
|
|
|
set (FC_SIZEOF_B "SIZEOF(b)")
|
|
|
|
set (FC_SIZEOF_C "SIZEOF(c)")
|
|
|
|
else ()
|
2015-08-11 22:35:30 +08:00
|
|
|
message (FATAL_ERROR "Fortran compiler requires either intrinsic functions SIZEOF or STORAGE_SIZE")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Determine the available KINDs for REALs and INTEGERs
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2017-03-02 04:47:53 +08:00
|
|
|
READ_SOURCE ("PROGRAM FC_AVAIL_KINDS" "END PROGRAM FC_AVAIL_KINDS" CODE)
|
|
|
|
FORTRAN_RUN ("REAL and INTEGER KINDs"
|
2016-07-19 02:37:17 +08:00
|
|
|
"${CODE}"
|
2015-08-11 22:35:30 +08:00
|
|
|
XX
|
|
|
|
YY
|
|
|
|
PROG_OUTPUT
|
|
|
|
)
|
|
|
|
# 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
|
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
file (READ "${CMAKE_BINARY_DIR}/pac_fconftest.out" PROG_OUTPUT)
|
2015-08-11 22:35:30 +08:00
|
|
|
# Convert the string to a list of strings by replacing the carriage return with a semicolon
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "\n" ";" PROG_OUTPUT "${PROG_OUTPUT}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET PROG_OUTPUT 0 pac_validIntKinds)
|
|
|
|
list (GET PROG_OUTPUT 1 pac_validRealKinds)
|
|
|
|
list (GET PROG_OUTPUT 2 H5_PAC_FC_MAX_REAL_PRECISION)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2016-06-10 04:39:17 +08:00
|
|
|
# If the lists are empty then something went wrong.
|
2017-01-11 07:09:53 +08:00
|
|
|
if (NOT pac_validIntKinds)
|
2016-06-10 04:39:17 +08:00
|
|
|
message (FATAL_ERROR "Failed to find available INTEGER KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
if (NOT pac_validRealKinds)
|
2016-06-10 04:39:17 +08:00
|
|
|
message (FATAL_ERROR "Failed to find available REAL KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
if (NOT H5_PAC_FC_MAX_REAL_PRECISION)
|
2016-06-10 04:39:17 +08:00
|
|
|
message (FATAL_ERROR "No output from Fortran decimal precision program")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (PAC_FC_ALL_INTEGER_KINDS "\{${pac_validIntKinds}\}")
|
|
|
|
set (PAC_FC_ALL_REAL_KINDS "\{${pac_validRealKinds}\}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET PROG_OUTPUT 3 NUM_IKIND)
|
|
|
|
list (GET PROG_OUTPUT 4 NUM_RKIND)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (PAC_FORTRAN_NUM_INTEGER_KINDS "${NUM_IKIND}")
|
2016-09-27 02:27:50 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (H5CONFIG_F_NUM_IKIND "INTEGER, PARAMETER :: num_ikinds = ${NUM_IKIND}")
|
|
|
|
set (H5CONFIG_F_IKIND "INTEGER, DIMENSION(1:num_ikinds) :: ikind = (/${pac_validIntKinds}/)")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2016-09-27 02:27:50 +08:00
|
|
|
message (STATUS "....NUMBER OF INTEGER KINDS FOUND ${PAC_FORTRAN_NUM_INTEGER_KINDS}")
|
2015-10-20 04:32:49 +08:00
|
|
|
message (STATUS "....REAL KINDS FOUND ${PAC_FC_ALL_REAL_KINDS}")
|
|
|
|
message (STATUS "....INTEGER KINDS FOUND ${PAC_FC_ALL_REAL_KINDS}")
|
|
|
|
message (STATUS "....MAX DECIMAL PRECISION ${H5_PAC_FC_MAX_REAL_PRECISION}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Determine the available KINDs for REALs and INTEGERs
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# **********
|
|
|
|
# INTEGERS
|
|
|
|
# **********
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "," ";" VAR "${pac_validIntKinds}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
foreach (KIND ${VAR} )
|
|
|
|
set (PROG_SRC
|
2015-08-11 22:35:30 +08:00
|
|
|
"
|
|
|
|
PROGRAM main
|
|
|
|
USE ISO_C_BINDING
|
|
|
|
IMPLICIT NONE
|
|
|
|
INTEGER (KIND=${KIND}) a
|
|
|
|
WRITE(*,'(I0)') ${FC_SIZEOF_A}
|
|
|
|
END
|
|
|
|
"
|
|
|
|
)
|
|
|
|
FORTRAN_RUN("INTEGER KIND SIZEOF" ${PROG_SRC}
|
|
|
|
XX
|
|
|
|
YY
|
|
|
|
PROG_OUTPUT1
|
|
|
|
)
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "\n" "" PROG_OUTPUT1 "${PROG_OUTPUT1}")
|
|
|
|
set (pack_int_sizeof "${pack_int_sizeof} ${PROG_OUTPUT1},")
|
|
|
|
endforeach ()
|
2016-06-10 04:39:17 +08:00
|
|
|
|
|
|
|
if (pack_int_sizeof STREQUAL "")
|
|
|
|
message (FATAL_ERROR "Failed to find available INTEGER KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
string (STRIP ${pack_int_sizeof} pack_int_sizeof)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#Remove trailing comma
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE ",$" "" pack_int_sizeof "${pack_int_sizeof}")
|
2015-08-11 22:35:30 +08:00
|
|
|
#Remove spaces
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE " " "" pack_int_sizeof "${pack_int_sizeof}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (PAC_FC_ALL_INTEGER_KINDS_SIZEOF "\{${pack_int_sizeof}\}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
message (STATUS "....FOUND SIZEOF for INTEGER KINDs ${PAC_FC_ALL_INTEGER_KINDS_SIZEOF}")
|
2015-08-11 22:35:30 +08:00
|
|
|
# **********
|
|
|
|
# REALS
|
|
|
|
# **********
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "," ";" VAR "${pac_validRealKinds}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#find the maximum kind of the real
|
2017-01-11 07:09:53 +08:00
|
|
|
list (LENGTH VAR LEN_VAR)
|
2017-03-03 02:20:26 +08:00
|
|
|
math (EXPR _LEN "${LEN_VAR}-1")
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET VAR ${_LEN} max_real_fortran_kind)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
foreach (KIND ${VAR} )
|
2017-03-02 04:47:53 +08:00
|
|
|
set (PROG_SRC
|
2015-08-11 22:35:30 +08:00
|
|
|
"
|
|
|
|
PROGRAM main
|
|
|
|
USE ISO_C_BINDING
|
|
|
|
IMPLICIT NONE
|
|
|
|
REAL (KIND=${KIND}) a
|
|
|
|
WRITE(*,'(I0)') ${FC_SIZEOF_A}
|
|
|
|
END
|
|
|
|
"
|
|
|
|
)
|
2017-03-02 04:47:53 +08:00
|
|
|
FORTRAN_RUN ("REAL KIND SIZEOF" ${PROG_SRC}
|
2015-08-11 22:35:30 +08:00
|
|
|
XX
|
|
|
|
YY
|
|
|
|
PROG_OUTPUT1
|
|
|
|
)
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "\n" "" PROG_OUTPUT1 "${PROG_OUTPUT1}")
|
|
|
|
set (pack_real_sizeof "${pack_real_sizeof} ${PROG_OUTPUT1},")
|
|
|
|
endforeach ()
|
2016-06-10 04:39:17 +08:00
|
|
|
|
|
|
|
if (pack_int_sizeof STREQUAL "")
|
|
|
|
message (FATAL_ERROR "Failed to find available REAL KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
string(STRIP ${pack_real_sizeof} pack_real_sizeof)
|
|
|
|
|
|
|
|
#Remove trailing comma
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE ",$" "" pack_real_sizeof "${pack_real_sizeof}")
|
2015-08-11 22:35:30 +08:00
|
|
|
#Remove spaces
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE " " "" pack_real_sizeof "${pack_real_sizeof}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (H5CONFIG_F_RKIND_SIZEOF "INTEGER, DIMENSION(1:num_rkinds) :: rkind_sizeof = (/${pack_real_sizeof}/)")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
message (STATUS "....FOUND SIZEOF for REAL KINDs \{${pack_real_sizeof}\}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (PAC_FC_ALL_REAL_KINDS_SIZEOF "\{${pack_real_sizeof}\}")
|
2015-08-25 03:22:55 +08:00
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
#find the maximum kind of the real
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "," ";" VAR "${pack_real_sizeof}")
|
|
|
|
list (LENGTH VAR LEN_VAR)
|
2017-03-03 02:20:26 +08:00
|
|
|
math (EXPR _LEN "${LEN_VAR}-1")
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET VAR ${_LEN} max_real_fortran_sizeof)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Find sizeof of native kinds
|
|
|
|
#-----------------------------------------------------------------------------
|
2017-03-02 04:47:53 +08:00
|
|
|
FORTRAN_RUN ("SIZEOF NATIVE KINDs"
|
2015-08-11 22:35:30 +08:00
|
|
|
"
|
|
|
|
PROGRAM main
|
|
|
|
USE ISO_C_BINDING
|
|
|
|
IMPLICIT NONE
|
|
|
|
INTEGER a
|
|
|
|
REAL b
|
|
|
|
DOUBLE PRECISION c
|
|
|
|
WRITE(*,*) ${FC_SIZEOF_A}
|
2017-01-11 07:09:53 +08:00
|
|
|
WRITE(*,*) kind(a)
|
|
|
|
WRITE(*,*) ${FC_SIZEOF_B}
|
|
|
|
WRITE(*,*) kind(b)
|
2015-08-11 22:35:30 +08:00
|
|
|
WRITE(*,*) ${FC_SIZEOF_C}
|
|
|
|
WRITE(*,*) kind(c)
|
|
|
|
END
|
|
|
|
"
|
|
|
|
XX
|
|
|
|
YY
|
|
|
|
PROG_OUTPUT
|
|
|
|
)
|
|
|
|
# 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
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "\n" ";" PROG_OUTPUT "${PROG_OUTPUT}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET PROG_OUTPUT 0 PAC_FORTRAN_NATIVE_INTEGER_SIZEOF)
|
|
|
|
list (GET PROG_OUTPUT 1 PAC_FORTRAN_NATIVE_INTEGER_KIND)
|
|
|
|
list (GET PROG_OUTPUT 2 PAC_FORTRAN_NATIVE_REAL_SIZEOF)
|
|
|
|
list (GET PROG_OUTPUT 3 PAC_FORTRAN_NATIVE_REAL_KIND)
|
|
|
|
list (GET PROG_OUTPUT 4 PAC_FORTRAN_NATIVE_DOUBLE_SIZEOF)
|
|
|
|
list (GET PROG_OUTPUT 5 PAC_FORTRAN_NATIVE_DOUBLE_KIND)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_INTEGER_SIZEOF)
|
|
|
|
message (FATAL_ERROR "Failed to find SIZEOF NATIVE INTEGER KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_REAL_SIZEOF)
|
|
|
|
message (FATAL_ERROR "Failed to find SIZEOF NATIVE REAL KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_DOUBLE_SIZEOF)
|
|
|
|
message (FATAL_ERROR "Failed to find SIZEOF NATIVE DOUBLE KINDs for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_INTEGER_KIND)
|
|
|
|
message (FATAL_ERROR "Failed to find KIND of NATIVE INTEGER for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_REAL_KIND)
|
|
|
|
message (FATAL_ERROR "Failed to find KIND of NATIVE REAL for Fortran")
|
2017-03-02 04:47:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
if (NOT PAC_FORTRAN_NATIVE_DOUBLE_KIND)
|
|
|
|
message (FATAL_ERROR "Failed to find KIND of NATIVE DOUBLE for Fortran")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2016-06-10 04:39:17 +08:00
|
|
|
|
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (FORTRAN_SIZEOF_LONG_DOUBLE ${${HDF_PREFIX}_SIZEOF_LONG_DOUBLE})
|
|
|
|
#set (H5_SIZEOF_LONG_DOUBLE ${${HDF_PREFIX}_SIZEOF_LONG_DOUBLE})
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
# remove the invalid kind from the list
|
2017-01-11 07:09:53 +08:00
|
|
|
if (NOT(${SIZEOF___FLOAT128} EQUAL 0))
|
|
|
|
if (NOT(${SIZEOF___FLOAT128} EQUAL ${max_real_fortran_sizeof})
|
|
|
|
AND NOT(${FORTRAN_SIZEOF_LONG_DOUBLE} EQUAL ${max_real_fortran_sizeof})
|
|
|
|
# account for the fact that the C compiler can have 16-byte __float128 and the fortran compiler only has 8-byte doubles,
|
|
|
|
# so we don't want to remove the 8-byte fortran doubles.
|
|
|
|
AND NOT(${PAC_FORTRAN_NATIVE_DOUBLE_SIZEOF} EQUAL ${max_real_fortran_sizeof}))
|
|
|
|
message (WARNING "
|
2015-08-11 22:35:30 +08:00
|
|
|
Fortran REAL(KIND=${max_real_fortran_kind}) is $max_real_fortran_sizeof Bytes, but no corresponding C float type exists of that size
|
|
|
|
!!! Fortran interfaces will not be generated for REAL(KIND=${max_real_fortran_kind}) !!!")
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE ",[0-9]+}" "}" PAC_FC_ALL_REAL_KINDS ${PAC_FC_ALL_REAL_KINDS})
|
|
|
|
string (REGEX REPLACE ",[0-9]+}" "}" PAC_FC_ALL_REAL_KINDS_SIZEOF ${PAC_FC_ALL_REAL_KINDS_SIZEOF})
|
2017-03-03 02:20:26 +08:00
|
|
|
math (EXPR NUM_RKIND "${NUM_RKIND} - 1")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (H5CONFIG_F_NUM_RKIND "INTEGER, PARAMETER :: num_rkinds = ${NUM_RKIND}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "{" "" OUT_VAR ${PAC_FC_ALL_REAL_KINDS})
|
|
|
|
string (REGEX REPLACE "}" "" OUT_VAR ${OUT_VAR})
|
|
|
|
set (H5CONFIG_F_RKIND "INTEGER, DIMENSION(1:num_rkinds) :: rkind = (/${OUT_VAR}/)")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "{" "" OUT_VAR ${PAC_FC_ALL_REAL_KINDS_SIZEOF})
|
|
|
|
string (REGEX REPLACE "}" "" OUT_VAR ${OUT_VAR})
|
|
|
|
set (H5CONFIG_F_RKIND_SIZEOF "INTEGER, DIMENSION(1:num_rkinds) :: rkind_sizeof = (/${OUT_VAR}/)")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
ENABLE_LANGUAGE (C)
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# The provided CMake C macros don't provide a general compile/run function
|
|
|
|
# so this one is used.
|
|
|
|
#-----------------------------------------------------------------------------
|
2017-03-02 04:47:53 +08:00
|
|
|
macro (C_RUN FUNCTION CODE RETURN)
|
2015-08-11 22:35:30 +08:00
|
|
|
message (STATUS "Detecting C ${FUNCTION}")
|
|
|
|
if (CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
|
|
|
|
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
|
2017-01-11 07:09:53 +08:00
|
|
|
else ()
|
2015-08-11 22:35:30 +08:00
|
|
|
set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
file (WRITE
|
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler1.c
|
|
|
|
${CODE}
|
|
|
|
)
|
2015-08-25 00:07:17 +08:00
|
|
|
TRY_RUN (RUN_RESULT_VAR COMPILE_RESULT_VAR
|
2015-08-11 22:35:30 +08:00
|
|
|
${CMAKE_BINARY_DIR}
|
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler1.c
|
|
|
|
CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
|
|
|
|
RUN_OUTPUT_VARIABLE OUTPUT
|
|
|
|
)
|
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (${RETURN} ${OUTPUT})
|
|
|
|
|
2015-08-11 22:35:30 +08:00
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
2015-08-25 00:07:17 +08:00
|
|
|
#message ( "Test COMPILE_RESULT_VAR ${COMPILE_RESULT_VAR} ")
|
2015-08-11 22:35:30 +08:00
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
2015-08-25 00:07:17 +08:00
|
|
|
#message ( "Test RUN_RESULT_VAR ${RUN_RESULT_VAR} ")
|
2015-08-11 22:35:30 +08:00
|
|
|
#message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ")
|
|
|
|
|
|
|
|
if (${COMPILE_RESULT_VAR})
|
2015-08-25 00:07:17 +08:00
|
|
|
if (${RUN_RESULT_VAR} MATCHES 1)
|
2015-08-11 22:35:30 +08:00
|
|
|
set (${RUN_RESULT_VAR} 1 CACHE INTERNAL "Have C function ${FUNCTION}")
|
|
|
|
message (STATUS "Testing C ${FUNCTION} - OK")
|
|
|
|
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
|
|
|
"Determining if the C ${FUNCTION} exists passed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n"
|
|
|
|
)
|
|
|
|
else ()
|
|
|
|
message (STATUS "Testing C ${FUNCTION} - Fail")
|
2015-08-25 00:07:17 +08:00
|
|
|
set (${RUN_RESULT_VAR} 0 CACHE INTERNAL "Have C function ${FUNCTION}")
|
2015-08-11 22:35:30 +08:00
|
|
|
file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
|
|
|
"Determining if the C ${FUNCTION} exists failed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n")
|
|
|
|
endif ()
|
2015-08-25 00:07:17 +08:00
|
|
|
else ()
|
|
|
|
message (FATAL_ERROR "Compilation of C ${FUNCTION} - Failed")
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2017-03-02 04:47:53 +08:00
|
|
|
endmacro ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
set (PROG_SRC
|
2015-08-11 22:35:30 +08:00
|
|
|
"
|
|
|
|
#include <float.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#define CHECK_FLOAT128 ${SIZEOF___FLOAT128}
|
|
|
|
#if CHECK_FLOAT128!=0
|
|
|
|
# if ${HAVE_QUADMATH}!=0
|
|
|
|
#include <quadmath.h>
|
|
|
|
# endif
|
|
|
|
# ifdef FLT128_DIG
|
|
|
|
#define C_FLT128_DIG FLT128_DIG
|
|
|
|
# else
|
|
|
|
#define C_FLT128_DIG 0
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
#define C_FLT128_DIG 0
|
|
|
|
#endif
|
|
|
|
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
2017-01-11 07:09:53 +08:00
|
|
|
#define C_LDBL_DIG DECIMAL_DIG
|
2015-08-11 22:35:30 +08:00
|
|
|
#else
|
|
|
|
#define C_LDBL_DIG LDBL_DIG
|
|
|
|
#endif
|
2015-08-25 00:07:17 +08:00
|
|
|
int main() {
|
2015-08-11 22:35:30 +08:00
|
|
|
printf(\"%d\\\\n%d\\\\n\", C_LDBL_DIG, C_FLT128_DIG)\\\;
|
2015-08-25 00:07:17 +08:00
|
|
|
return 1\\\;
|
2015-08-11 22:35:30 +08:00
|
|
|
}
|
|
|
|
"
|
2017-03-02 04:47:53 +08:00
|
|
|
)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-03-02 04:47:53 +08:00
|
|
|
C_RUN ("maximum decimal precision for C" ${PROG_SRC} PROG_OUTPUT)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
# dnl The output from the above program will be:
|
|
|
|
# dnl -- LINE 1 -- long double decimal precision
|
|
|
|
# dnl -- LINE 2 -- __float128 decimal precision
|
|
|
|
|
|
|
|
# Convert the string to a list of strings by replacing the carriage return with a semicolon
|
2017-01-11 07:09:53 +08:00
|
|
|
string (REGEX REPLACE "\n" ";" PROG_OUTPUT "${PROG_OUTPUT}")
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
list (GET PROG_OUTPUT 0 LDBL_DIG)
|
|
|
|
list (GET PROG_OUTPUT 1 FLT128_DIG)
|
2015-08-11 22:35:30 +08:00
|
|
|
|
2017-01-11 07:09:53 +08:00
|
|
|
if (SIZEOF___FLOAT128 EQUAL 0 OR FLT128_DIG EQUAL 0)
|
|
|
|
set (H5_HAVE_FLOAT128 0)
|
|
|
|
set (SIZEOF___FLOAT128 0)
|
|
|
|
set (H5_PAC_C_MAX_REAL_PRECISION ${LDBL_DIG})
|
2015-08-11 22:35:30 +08:00
|
|
|
else ()
|
|
|
|
set(H5_PAC_C_MAX_REAL_PRECISION ${FLT128_DIG})
|
2017-01-11 07:09:53 +08:00
|
|
|
endif ()
|
2015-08-11 22:35:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Setting definition if there is a 16 byte fortran integer
|
2017-01-11 07:09:53 +08:00
|
|
|
string (FIND ${PAC_FC_ALL_INTEGER_KINDS_SIZEOF} "16" pos)
|
|
|
|
if (${pos} EQUAL -1)
|
|
|
|
set (HAVE_Fortran_INTEGER_SIZEOF_16 0)
|
2015-08-11 22:35:30 +08:00
|
|
|
else ()
|
2017-01-11 07:09:53 +08:00
|
|
|
set (HAVE_Fortran_INTEGER_SIZEOF_16 1)
|
2015-08-11 22:35:30 +08:00
|
|
|
endif ()
|