Skip to content
Open
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
97 changes: 57 additions & 40 deletions config/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -891,65 +891,82 @@ endmacro ()
# Check for complex number support
#-----------------------------------------------------------------------------
message (STATUS "Checking if complex number support is available")
CHECK_INCLUDE_FILE (complex.h ${HDF_PREFIX}_HAVE_COMPLEX_H)
if (${HDF_PREFIX}_HAVE_COMPLEX_H)
set (H5_HAVE_C99_COMPLEX_NUMBERS 1)

HDF_CHECK_TYPE_SIZE ("float _Complex" ${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX)
HDF_CHECK_TYPE_SIZE ("double _Complex" ${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX)
HDF_CHECK_TYPE_SIZE ("long double _Complex" ${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX)

if (MSVC AND NOT ${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX AND NOT ${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX
AND NOT ${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX)
# If using MSVC, the _Complex types (if available) are _Fcomplex, _Dcomplex and _Lcomplex.
# The standard types are checked for first in case MSVC uses them in the future or in case
# the compiler used is simulating MSVC and uses the standard types.
cmake_push_check_state ()
list (APPEND CMAKE_EXTRA_INCLUDE_FILES complex.h)
HDF_CHECK_TYPE_SIZE ("_Fcomplex" ${HDF_PREFIX}_SIZEOF__FCOMPLEX)
HDF_CHECK_TYPE_SIZE ("_Dcomplex" ${HDF_PREFIX}_SIZEOF__DCOMPLEX)
HDF_CHECK_TYPE_SIZE ("_Lcomplex" ${HDF_PREFIX}_SIZEOF__LCOMPLEX)
cmake_pop_check_state ()
if (${HDF_PREFIX}_SIZEOF__FCOMPLEX AND ${HDF_PREFIX}_SIZEOF__DCOMPLEX AND
${HDF_PREFIX}_SIZEOF__FCOMPLEX)
set (${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX}_SIZEOF__FCOMPLEX}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved setting the final size macro variables to as late as possible and updated the check below to avoid issues with mixing up when a particular type of complex numbers are available

CACHE INTERNAL "SizeOf for float _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF__DCOMPLEX}
CACHE INTERNAL "SizeOf for double _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF__LCOMPLEX}
CACHE INTERNAL "SizeOf for long double _Complex" FORCE)

unset (H5_HAVE_C99_COMPLEX_NUMBERS)

# Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
# support is not available
HDF_FUNCTION_TEST (HAVE_STDC_NO_COMPLEX)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this check to be first, as it is a standalone check that can tell us early if complex number support isn't available

if (NOT H5_HAVE_STDC_NO_COMPLEX)
CHECK_INCLUDE_FILE (complex.h ${HDF_PREFIX}_HAVE_COMPLEX_H)
if (${HDF_PREFIX}_HAVE_COMPLEX_H)
# Check for C99 complex number types first
HDF_CHECK_TYPE_SIZE ("float _Complex" ${HDF_PREFIX}_SIZEOF_C99_FLOAT_COMPLEX)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the variable names for these size checks so they aren't mixed with the final names used by the macros in H5pubconf.h

HDF_CHECK_TYPE_SIZE ("double _Complex" ${HDF_PREFIX}_SIZEOF_C99_DOUBLE_COMPLEX)
HDF_CHECK_TYPE_SIZE ("long double _Complex" ${HDF_PREFIX}_SIZEOF_C99_LONG_DOUBLE_COMPLEX)

if (${HDF_PREFIX}_SIZEOF_C99_FLOAT_COMPLEX AND
${HDF_PREFIX}_SIZEOF_C99_DOUBLE_COMPLEX AND
${HDF_PREFIX}_SIZEOF_C99_LONG_DOUBLE_COMPLEX)
set (h5_have_c99_complex_numbers 1)
endif ()
endif ()

if (${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX AND ${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX AND
${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX)
# Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
# support is not available
HDF_FUNCTION_TEST (HAVE_STDC_NO_COMPLEX)
# If using MSVC, the _Complex types (if available) are currently _Fcomplex,
# _Dcomplex and _Lcomplex. The standard types are checked for first in case
# MSVC uses them in the future or in case the compiler used is simulating
# MSVC and uses the standard types.
if (MSVC AND NOT h5_have_c99_complex_numbers)
cmake_push_check_state ()
list (APPEND CMAKE_EXTRA_INCLUDE_FILES complex.h)
HDF_CHECK_TYPE_SIZE ("_Fcomplex" ${HDF_PREFIX}_SIZEOF__FCOMPLEX)
HDF_CHECK_TYPE_SIZE ("_Dcomplex" ${HDF_PREFIX}_SIZEOF__DCOMPLEX)
HDF_CHECK_TYPE_SIZE ("_Lcomplex" ${HDF_PREFIX}_SIZEOF__LCOMPLEX)
cmake_pop_check_state ()

if (${HDF_PREFIX}_SIZEOF__FCOMPLEX AND
${HDF_PREFIX}_SIZEOF__DCOMPLEX AND
${HDF_PREFIX}_SIZEOF__LCOMPLEX)
set (h5_have_msvc_complex_numbers 1)
endif ()
endif ()

if (NOT H5_HAVE_STDC_NO_COMPLEX)
if (h5_have_c99_complex_numbers OR h5_have_msvc_complex_numbers)
# Compile simple test program with complex numbers
HDF_FUNCTION_TEST (HAVE_COMPLEX_NUMBERS)

if (H5_HAVE_COMPLEX_NUMBERS)
if (H5_HAVE_C99_COMPLEX_NUMBERS)
# Set values for macros used by HDF5
if (h5_have_c99_complex_numbers)
# Note here that the public macro is all-caps
set (H5_HAVE_C99_COMPLEX_NUMBERS 1)

set (${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX}_SIZEOF_C99_FLOAT_COMPLEX}
CACHE INTERNAL "SizeOf for float _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF_C99_DOUBLE_COMPLEX}
CACHE INTERNAL "SizeOf for double _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF_C99_LONG_DOUBLE_COMPLEX}
CACHE INTERNAL "SizeOf for long double _Complex" FORCE)

message (STATUS "Using C99 complex number types")
else ()
set (${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX ${${HDF_PREFIX}_SIZEOF__FCOMPLEX}
CACHE INTERNAL "SizeOf for float _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF__DCOMPLEX}
CACHE INTERNAL "SizeOf for double _Complex" FORCE)
set (${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX ${${HDF_PREFIX}_SIZEOF__LCOMPLEX}
CACHE INTERNAL "SizeOf for long double _Complex" FORCE)

message (STATUS "Using MSVC complex number types")
endif ()
else ()
message (STATUS "Complex number support has been disabled since a simple test program couldn't be compiled and linked")
endif ()
else ()
message (STATUS "Complex number support has been disabled since __STDC_NO_COMPLEX__ is defined")
message (STATUS "Complex number support has been disabled since the C types were not found")
endif ()
else ()
message (STATUS "Complex number support has been disabled since the C types were not found")
message (STATUS "Complex number support has been disabled since the complex.h header was not found")
endif ()
else ()
message (STATUS "Complex number support has been disabled since the complex.h header was not found")
message (STATUS "Complex number support has been disabled since __STDC_NO_COMPLEX__ is defined")
endif ()

#-----------------------------------------------------------------------------
Expand Down
Loading