summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-08-18 14:27:23 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-08-18 14:27:29 (GMT)
commit44fac4a34e47702a42d5035ca2a8faef28b78736 (patch)
tree2d6f42b95781aa9705752f9d1e3c11543d7ccd7e /Modules
parentf6290f024c8bc63905168e51edc5692756b36c0d (diff)
parent5eff2740174a96b4038ab33ef5627b31a96c6758 (diff)
downloadCMake-44fac4a34e47702a42d5035ca2a8faef28b78736.zip
CMake-44fac4a34e47702a42d5035ca2a8faef28b78736.tar.gz
CMake-44fac4a34e47702a42d5035ca2a8faef28b78736.tar.bz2
Merge topic 'findhdf5-targets'
5eff274017 FindHDF5: Remove VTK library type detection a8e0a6b3e4 FindHDF5: Port changes from VTK Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Ben Boeckel <ben.boeckel@kitware.com> Merge-request: !5129
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindHDF5.cmake151
1 files changed, 149 insertions, 2 deletions
diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
index 7c9664d..0a92c71 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
^^^^^
@@ -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,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}")