summaryrefslogtreecommitdiff
path: root/Modules/FindHDF5.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/FindHDF5.cmake')
-rw-r--r--Modules/FindHDF5.cmake155
1 files changed, 151 insertions, 4 deletions
diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
index c9d15984d..0a92c7140 100644
--- a/Modules/FindHDF5.cmake
+++ b/Modules/FindHDF5.cmake
@@ -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
^^^^^
@@ -125,11 +137,14 @@ The following variables can be set to guide the search for HDF5 libraries and in
Set ``true`` to skip trying to find ``hdf5-config.cmake``.
#]=======================================================================]
-# This module is maintained by Will Dicharry <wdicharry@stellarscience.com>.
-
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)
@@ -197,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)
@@ -346,6 +359,7 @@ function( _HDF5_invoke_compiler language output_var return_value_var version_var
# wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python
execute_process(
COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} ${test_file}
+ WORKING_DIRECTORY ${scratch_dir}
RESULT_VARIABLE return_value
)
if(return_value)
@@ -354,6 +368,7 @@ function( _HDF5_invoke_compiler language output_var return_value_var version_var
else()
execute_process(
COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} ${test_file}
+ WORKING_DIRECTORY ${scratch_dir}
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE return_value
@@ -971,6 +986,138 @@ 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 ()
+
+ 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 ()
+ add_library("hdf5::${hdf5_target_name}" UNKNOWN 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 ()
+ add_library("hdf5::${hdf5_target_name}" UNKNOWN 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}")