FindHDF5: Port changes from VTK

This commit is contained in:
Ben Boeckel 2020-06-10 14:27:11 -04:00 committed by Seth R Johnson
parent 7278ab262e
commit a8e0a6b3e4

View File

@ -110,6 +110,18 @@ also be defined. With all components enabled, the following variables will be d
``HDF5_DIFF_EXECUTABLE``
path to the HDF5 dataset comparison tool
With all components enabled, the following targets will be defined:
::
``hdf5::hdf5``
``hdf5::hdf5_hl_cpp``
``hdf5::hdf5_fortran``
``hdf5::hdf5_hl``
``hdf5::hdf5_hl_cpp``
``hdf5::hdf5_hl_fortran``
``hdf5::h5diff``
Hints
^^^^^
@ -128,6 +140,11 @@ The following variables can be set to guide the search for HDF5 libraries and in
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
# We haven't found HDF5 yet. Clear its state in case it is set in the parent
# scope somewhere else. We can't rely on it because different components may
# have been requested for this call.
set(HDF5_FOUND OFF)
# List of the valid HDF5 components
set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran)
@ -195,9 +212,7 @@ macro(_HDF5_remove_duplicates_from_beginning _list_name)
endif()
endmacro()
# Test first if the current compilers automatically wrap HDF5
function(_HDF5_test_regular_compiler_C success version is_parallel)
set(scratch_directory
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5)
@ -971,6 +986,141 @@ if( HDF5_FOUND AND NOT HDF5_DIR)
mark_as_advanced(HDF5_DIR)
endif()
if (HDF5_FOUND)
if (NOT TARGET HDF5::HDF5)
add_library(HDF5::HDF5 INTERFACE IMPORTED)
string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}")
set_target_properties(HDF5::HDF5 PROPERTIES
INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
unset(_hdf5_definitions)
endif ()
include(vtkDetectLibraryType)
foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
if (hdf5_lang STREQUAL "C")
set(hdf5_target_name "hdf5")
elseif (hdf5_lang STREQUAL "CXX")
set(hdf5_target_name "hdf5_cpp")
elseif (hdf5_lang STREQUAL "Fortran")
set(hdf5_target_name "hdf5_fortran")
else ()
continue ()
endif ()
if (NOT TARGET "hdf5::${hdf5_target_name}")
if (HDF5_COMPILER_NO_INTERROGATE)
add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED)
string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}")
set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
else()
if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY")
set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}")
elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY")
set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}")
elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}")
set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}")
else ()
# Error if we still don't have the location.
message(SEND_ERROR
"HDF5 was found, but a different variable was set which contains "
"its location.")
endif ()
vtk_detect_library_type(_hdf5_libtype PATH "${_hdf5_location}")
add_library("hdf5::${hdf5_target_name}" "${_hdf5_libtype}" IMPORTED)
string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}")
if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS)
set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS})
endif ()
set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
IMPORTED_LOCATION "${_hdf5_location}"
IMPORTED_IMPLIB "${_hdf5_location}"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
if (_hdf5_libtype STREQUAL "SHARED")
set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
PROPERTY
INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
elseif (_hdf5_libtype STREQUAL "STATIC")
set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
PROPERTY
INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
endif ()
unset(_hdf5_definitions)
unset(_hdf5_libtype)
unset(_hdf5_location)
endif ()
endif ()
if (NOT HDF5_FIND_HL)
continue ()
endif ()
if (hdf5_lang STREQUAL "C")
set(hdf5_target_name "hdf5_hl")
elseif (hdf5_lang STREQUAL "CXX")
set(hdf5_target_name "hdf5_hl_cpp")
elseif (hdf5_lang STREQUAL "Fortran")
set(hdf5_target_name "hdf5_hl_fortran")
else ()
continue ()
endif ()
if (NOT TARGET "hdf5::${hdf5_target_name}")
if (HDF5_COMPILER_NO_INTERROGATE)
add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED)
string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}")
set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
else()
if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY")
set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}")
elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY")
set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}")
elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}")
set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}")
else ()
# Error if we still don't have the location.
message(SEND_ERROR
"HDF5 was found, but a different variable was set which contains "
"its location.")
endif ()
vtk_detect_library_type(_hdf5_libtype PATH "${_hdf5_location}")
add_library("hdf5::${hdf5_target_name}" "${_hdf5_libtype}" IMPORTED)
string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}")
set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
IMPORTED_LOCATION "${_hdf5_location}"
IMPORTED_IMPLIB "${_hdf5_location}"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
if (_hdf5_libtype STREQUAL "SHARED")
set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
PROPERTY
INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
elseif (_hdf5_libtype STREQUAL "STATIC")
set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
PROPERTY
INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
endif ()
unset(_hdf5_definitions)
unset(_hdf5_libtype)
unset(_hdf5_location)
endif ()
endif ()
endforeach ()
unset(hdf5_lang)
if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff)
add_executable(hdf5::h5diff IMPORTED)
set_target_properties(hdf5::h5diff PROPERTIES
IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}")
endif ()
endif ()
if (HDF5_FIND_DEBUG)
message(STATUS "HDF5_DIR: ${HDF5_DIR}")
message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}")