From b2de6da2f161cde26178e568974fa5ef7f7480fc Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 6 Feb 2017 01:27:56 +0000 Subject: [PATCH] FindHDF5: use import libraries when using hdf5-config.cmake on Windows The `LOCATION` of imported shared libraries on Windows is that of the `.dll`. Use the import library instead to get the `.lib` to be linked. Fixes: #16534 --- Modules/FindHDF5.cmake | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index ae2c7073a8..a85b9ac14b 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -436,8 +436,13 @@ if(NOT HDF5_FOUND) if(HDF5_FIND_DEBUG) message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") endif() - get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) - + # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. + get_target_property(_imported_conf ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_CONFIGURATIONS) + get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) + if (NOT _lang_location) + # no import lib, just try LOCATION + get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() if( _lang_location ) set(HDF5_${_lang}_LIBRARY ${_lang_location}) list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) @@ -445,7 +450,10 @@ if(NOT HDF5_FOUND) set(HDF5_${_lang}_FOUND True) endif() if(FIND_HL) - get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} ) + if (NOT _lang_hl_location) + get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() if( _lang_hl_location ) set(HDF5_${_lang}_HL_LIBRARY ${_lang_hl_location}) list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})