diff options
author | Larry Knox <lrknox@hdfgroup.org> | 2020-10-16 22:47:27 (GMT) |
---|---|---|
committer | Larry Knox <lrknox@hdfgroup.org> | 2020-10-16 22:47:27 (GMT) |
commit | db30c2da68ece4a155e9e50c28ec16d6057509b2 (patch) | |
tree | 1d36f673c36dfee71c266bba39511da21ecc782e /config/cmake_ext_mod/HDFUseFortran.cmake | |
parent | 5b9cf732caab9daa6ed1e00f2df4f5a792340196 (diff) | |
parent | 2e2b87d1cbdee3b919e6e5cba6c5ecd1b9434434 (diff) | |
download | hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.zip hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.tar.gz hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.tar.bz2 |
Merge HDF5 1.10.7 release files into 1.10/masterhdf5-1_10_7
Diffstat (limited to 'config/cmake_ext_mod/HDFUseFortran.cmake')
-rw-r--r-- | config/cmake_ext_mod/HDFUseFortran.cmake | 179 |
1 files changed, 99 insertions, 80 deletions
diff --git a/config/cmake_ext_mod/HDFUseFortran.cmake b/config/cmake_ext_mod/HDFUseFortran.cmake index 1cce918..0a6a092 100644 --- a/config/cmake_ext_mod/HDFUseFortran.cmake +++ b/config/cmake_ext_mod/HDFUseFortran.cmake @@ -16,6 +16,11 @@ enable_language (Fortran) set (HDF_PREFIX "H5") +if (NOT CMAKE_VERSION VERSION_LESS "3.14.0") + include (CheckFortranSourceRuns) + include (CheckFortranSourceCompiles) +endif () + #------------------------------------------------------------------------------- # Fix Fortran flags if we are compiling staticly on Windows using # Windows_MT.cmake from config/cmake/UserMacros @@ -42,71 +47,15 @@ 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}") -#----------------------------------------------------------------------------- -# The provided CMake Fortran macros don't provide a general check function -# so this one is used for a sizeof test. -#----------------------------------------------------------------------------- -macro (CHECK_FORTRAN_FEATURE FUNCTION CODE VARIABLE) - message (STATUS "Testing Fortran ${FUNCTION}") - if (HDF5_REQUIRED_LIBRARIES) - set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${HDF5_REQUIRED_LIBRARIES}") - else () - set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) - endif () - file (WRITE - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f90 - "${CODE}" - ) - TRY_COMPILE (RESULT_VAR - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f90 - CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" - OUTPUT_VARIABLE OUTPUT - ) - -# message (STATUS "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") -# message (STATUS "Test result ${OUTPUT}") -# message (STATUS "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") - - if (${RESULT_VAR}) - set (${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}") - 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") - set (${VARIABLE} 0 CACHE INTERNAL "Have Fortran function ${FUNCTION}") - 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 () -endmacro () - -#----------------------------------------------------------------------------- -# Configure Checks which require Fortran compilation must go in here -# not in the main ConfigureChecks.cmake files, because if the user has -# no Fortran compiler, problems arise. -# -# Be careful with leading spaces here, do not remove them. -#----------------------------------------------------------------------------- - -# Check for Non-standard extension intrinsic function SIZEOF -set (${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF FALSE) -CHECK_FORTRAN_FEATURE(sizeof +#test code source +set (SIZEOF_CODE " PROGRAM main i = sizeof(x) END PROGRAM " - ${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF ) - -# Check for F2008 standard intrinsic function C_SIZEOF -set (${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF FALSE) -CHECK_FORTRAN_FEATURE(c_sizeof +set (C_SIZEOF_CODE " PROGRAM main USE ISO_C_BINDING @@ -115,11 +64,8 @@ CHECK_FORTRAN_FEATURE(c_sizeof result = c_sizeof(a) END PROGRAM " - ${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF ) - -# Check for F2008 standard intrinsic function STORAGE_SIZE -CHECK_FORTRAN_FEATURE(storage_size +set (STORAGE_SIZE_CODE " PROGRAM main INTEGER :: a @@ -127,22 +73,15 @@ CHECK_FORTRAN_FEATURE(storage_size result = storage_size(a) END PROGRAM " - ${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE ) - -# Check for F2008 standard intrinsic module "ISO_FORTRAN_ENV" -set (${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV FALSE) -CHECK_FORTRAN_FEATURE(ISO_FORTRAN_ENV +set (ISO_FORTRAN_ENV_CODE " PROGRAM main USE, INTRINSIC :: ISO_FORTRAN_ENV END PROGRAM " - ${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV ) - -set (${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE FALSE) -CHECK_FORTRAN_FEATURE(RealIsNotDouble +set (REALISNOTDOUBLE_CODE " MODULE type_mod INTERFACE h5t @@ -165,14 +104,8 @@ CHECK_FORTRAN_FEATURE(RealIsNotDouble CALL h5t(d) END PROGRAM main " - ${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE ) - -#----------------------------------------------------------------------------- -# Checks if the ISO_C_BINDING module meets all the requirements -#----------------------------------------------------------------------------- -set (${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING FALSE) -CHECK_FORTRAN_FEATURE(iso_c_binding +set (ISO_C_BINDING_CODE " PROGRAM main USE iso_c_binding @@ -184,9 +117,95 @@ CHECK_FORTRAN_FEATURE(iso_c_binding ptr = C_LOC(ichr(1:1)) END PROGRAM " - ${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING ) +if (NOT CMAKE_VERSION VERSION_LESS "3.14.0") + 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) +else () + #----------------------------------------------------------------------------- + # The provided CMake Fortran macros don't provide a general check function + # so this one is used for a sizeof test. + #----------------------------------------------------------------------------- + macro (CHECK_FORTRAN_FEATURE FUNCTION CODE VARIABLE) + message (STATUS "Testing Fortran ${FUNCTION}") + if (HDF5_REQUIRED_LIBRARIES) + set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES + "-DLINK_LIBRARIES:STRING=${HDF5_REQUIRED_LIBRARIES}") + else () + set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) + endif () + file (WRITE + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f90 + "${CODE}" + ) + TRY_COMPILE (RESULT_VAR + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f90 + CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" + OUTPUT_VARIABLE OUTPUT + ) + + # message (STATUS "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") + # message (STATUS "Test result ${OUTPUT}") + # message (STATUS "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") + + if (${RESULT_VAR}) + set (${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}") + 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") + set (${VARIABLE} 0 CACHE INTERNAL "Have Fortran function ${FUNCTION}") + 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 () + endmacro () + + #----------------------------------------------------------------------------- + # Configure Checks which require Fortran compilation must go in here + # not in the main ConfigureChecks.cmake files, because if the user has + # no Fortran compiler, problems arise. + # + # Be careful with leading spaces here, do not remove them. + #----------------------------------------------------------------------------- + + # Check for Non-standard extension intrinsic function SIZEOF + set (${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF FALSE) + CHECK_FORTRAN_FEATURE(sizeof_code ${SIZEOF_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF) + + # Check for F2008 standard intrinsic function C_SIZEOF + set (${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF FALSE) + CHECK_FORTRAN_FEATURE(c_sizeof_code ${C_SIZEOF_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF) + + # Check for F2008 standard intrinsic function STORAGE_SIZE + CHECK_FORTRAN_FEATURE(storage_size_code ${STORAGE_SIZE_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE) + + # Check for F2008 standard intrinsic module "ISO_FORTRAN_ENV" + set (${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV FALSE) + CHECK_FORTRAN_FEATURE(iso_fortran_env_code ${ISO_FORTRAN_ENV_CODE} ${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV) + + set (${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE FALSE) + CHECK_FORTRAN_FEATURE(realisnotdouble_code ${REALISNOTDOUBLE_CODE} ${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE) + + #----------------------------------------------------------------------------- + # Checks if the ISO_C_BINDING module meets all the requirements + #----------------------------------------------------------------------------- + set (${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING FALSE) + CHECK_FORTRAN_FEATURE(iso_c_binding_code ${ISO_C_BINDING_CODE} ${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING) +endif () + #----------------------------------------------------------------------------- # Add debug information (intel Fortran : JB) #----------------------------------------------------------------------------- |