@@ -891,65 +891,82 @@ endmacro ()
891891# Check for complex number support
892892#-----------------------------------------------------------------------------
893893message (STATUS "Checking if complex number support is available" )
894- CHECK_INCLUDE_FILE (complex.h ${HDF_PREFIX} _HAVE_COMPLEX_H)
895- if (${HDF_PREFIX} _HAVE_COMPLEX_H)
896- set (H5_HAVE_C99_COMPLEX_NUMBERS 1)
897-
898- HDF_CHECK_TYPE_SIZE ("float _Complex" ${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX)
899- HDF_CHECK_TYPE_SIZE ("double _Complex" ${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX)
900- HDF_CHECK_TYPE_SIZE ("long double _Complex" ${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX)
901-
902- if (MSVC AND NOT ${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX AND NOT ${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX
903- AND NOT ${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX)
904- # If using MSVC, the _Complex types (if available) are _Fcomplex, _Dcomplex and _Lcomplex.
905- # The standard types are checked for first in case MSVC uses them in the future or in case
906- # the compiler used is simulating MSVC and uses the standard types.
907- cmake_push_check_state ()
908- list (APPEND CMAKE_EXTRA_INCLUDE_FILES complex.h)
909- HDF_CHECK_TYPE_SIZE ("_Fcomplex" ${HDF_PREFIX} _SIZEOF__FCOMPLEX)
910- HDF_CHECK_TYPE_SIZE ("_Dcomplex" ${HDF_PREFIX} _SIZEOF__DCOMPLEX)
911- HDF_CHECK_TYPE_SIZE ("_Lcomplex" ${HDF_PREFIX} _SIZEOF__LCOMPLEX)
912- cmake_pop_check_state ()
913- if (${HDF_PREFIX} _SIZEOF__FCOMPLEX AND ${HDF_PREFIX} _SIZEOF__DCOMPLEX AND
914- ${HDF_PREFIX} _SIZEOF__FCOMPLEX)
915- set (${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX} _SIZEOF__FCOMPLEX}
916- CACHE INTERNAL "SizeOf for float _Complex" FORCE)
917- set (${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF__DCOMPLEX}
918- CACHE INTERNAL "SizeOf for double _Complex" FORCE)
919- set (${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF__LCOMPLEX}
920- CACHE INTERNAL "SizeOf for long double _Complex" FORCE)
921-
922- unset (H5_HAVE_C99_COMPLEX_NUMBERS)
894+
895+ # Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
896+ # support is not available
897+ HDF_FUNCTION_TEST (HAVE_STDC_NO_COMPLEX)
898+ if (NOT H5_HAVE_STDC_NO_COMPLEX)
899+ CHECK_INCLUDE_FILE (complex.h ${HDF_PREFIX} _HAVE_COMPLEX_H)
900+ if (${HDF_PREFIX} _HAVE_COMPLEX_H)
901+ # Check for C99 complex number types first
902+ HDF_CHECK_TYPE_SIZE ("float _Complex" ${HDF_PREFIX} _SIZEOF_C99_FLOAT_COMPLEX)
903+ HDF_CHECK_TYPE_SIZE ("double _Complex" ${HDF_PREFIX} _SIZEOF_C99_DOUBLE_COMPLEX)
904+ HDF_CHECK_TYPE_SIZE ("long double _Complex" ${HDF_PREFIX} _SIZEOF_C99_LONG_DOUBLE_COMPLEX)
905+
906+ if (${HDF_PREFIX} _SIZEOF_C99_FLOAT_COMPLEX AND
907+ ${HDF_PREFIX} _SIZEOF_C99_DOUBLE_COMPLEX AND
908+ ${HDF_PREFIX} _SIZEOF_C99_LONG_DOUBLE_COMPLEX)
909+ set (h5_have_c99_complex_numbers 1)
923910 endif ()
924- endif ()
925911
926- if (${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX AND ${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX AND
927- ${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX)
928- # Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
929- # support is not available
930- HDF_FUNCTION_TEST (HAVE_STDC_NO_COMPLEX)
912+ # If using MSVC, the _Complex types (if available) are currently _Fcomplex,
913+ # _Dcomplex and _Lcomplex. The standard types are checked for first in case
914+ # MSVC uses them in the future or in case the compiler used is simulating
915+ # MSVC and uses the standard types.
916+ if (MSVC AND NOT h5_have_c99_complex_numbers)
917+ cmake_push_check_state ()
918+ list (APPEND CMAKE_EXTRA_INCLUDE_FILES complex.h)
919+ HDF_CHECK_TYPE_SIZE ("_Fcomplex" ${HDF_PREFIX} _SIZEOF__FCOMPLEX)
920+ HDF_CHECK_TYPE_SIZE ("_Dcomplex" ${HDF_PREFIX} _SIZEOF__DCOMPLEX)
921+ HDF_CHECK_TYPE_SIZE ("_Lcomplex" ${HDF_PREFIX} _SIZEOF__LCOMPLEX)
922+ cmake_pop_check_state ()
923+
924+ if (${HDF_PREFIX} _SIZEOF__FCOMPLEX AND
925+ ${HDF_PREFIX} _SIZEOF__DCOMPLEX AND
926+ ${HDF_PREFIX} _SIZEOF__LCOMPLEX)
927+ set (h5_have_msvc_complex_numbers 1)
928+ endif ()
929+ endif ()
931930
932- if (NOT H5_HAVE_STDC_NO_COMPLEX )
931+ if (h5_have_c99_complex_numbers OR h5_have_msvc_complex_numbers )
933932 # Compile simple test program with complex numbers
934933 HDF_FUNCTION_TEST (HAVE_COMPLEX_NUMBERS)
935934
936935 if (H5_HAVE_COMPLEX_NUMBERS)
937- if (H5_HAVE_C99_COMPLEX_NUMBERS)
936+ # Set values for macros used by HDF5
937+ if (h5_have_c99_complex_numbers)
938+ # Note here that the public macro is all-caps
939+ set (H5_HAVE_C99_COMPLEX_NUMBERS 1)
940+
941+ set (${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX} _SIZEOF_C99_FLOAT_COMPLEX}
942+ CACHE INTERNAL "SizeOf for float _Complex" FORCE)
943+ set (${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF_C99_DOUBLE_COMPLEX}
944+ CACHE INTERNAL "SizeOf for double _Complex" FORCE)
945+ set (${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF_C99_LONG_DOUBLE_COMPLEX}
946+ CACHE INTERNAL "SizeOf for long double _Complex" FORCE)
947+
938948 message (STATUS "Using C99 complex number types" )
939949 else ()
950+ set (${HDF_PREFIX} _SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX} _SIZEOF__FCOMPLEX}
951+ CACHE INTERNAL "SizeOf for float _Complex" FORCE)
952+ set (${HDF_PREFIX} _SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF__DCOMPLEX}
953+ CACHE INTERNAL "SizeOf for double _Complex" FORCE)
954+ set (${HDF_PREFIX} _SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX} _SIZEOF__LCOMPLEX}
955+ CACHE INTERNAL "SizeOf for long double _Complex" FORCE)
956+
940957 message (STATUS "Using MSVC complex number types" )
941958 endif ()
942959 else ()
943960 message (STATUS "Complex number support has been disabled since a simple test program couldn't be compiled and linked" )
944961 endif ()
945962 else ()
946- message (STATUS "Complex number support has been disabled since __STDC_NO_COMPLEX__ is defined " )
963+ message (STATUS "Complex number support has been disabled since the C types were not found " )
947964 endif ()
948965 else ()
949- message (STATUS "Complex number support has been disabled since the C types were not found" )
966+ message (STATUS "Complex number support has been disabled since the complex.h header was not found" )
950967 endif ()
951968else ()
952- message (STATUS "Complex number support has been disabled since the complex.h header was not found " )
969+ message (STATUS "Complex number support has been disabled since __STDC_NO_COMPLEX__ is defined " )
953970endif ()
954971
955972#-----------------------------------------------------------------------------
0 commit comments