How to print location of Qt5 component library?

CMake code

find_package(HDF5 MODULE REQUIRED COMPONENTS CXX)
message(STATUS "hdf5: VERSION=${HDF5_VERSION}, LIB=${HDF5_LIBRARIES})

results in informative output like

-- hdf5: VERSION=1.10.4, LIB=/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so;/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so

whereas

find_package(Qt5 REQUIRED COMPONENTS Core)
message(STATUS "Qt5: Core=${Qt5Core_LIBRARIES}, Version=${Qt5Core_VERSION}")

only yields

-- Qt5: Core=Qt5::Core, Version=5.12.5

How to print the actual path of the Qt5Core library?

get_property(loc TARGET Qt5::Core PROPERTY IMPORTED_LOCATION)
message(STATUS "${loc}")

Results in an empty string.

CMake code:

find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Network Concurrent)
message(STATUS "Qt5 found lib: Core=${Qt5Core_LIBRARIES} version=${Qt5Core_VERSION}")
get_property(loc TARGET Qt5::Core PROPERTY IMPORTED_LOCATION)
message(STATUS "               Lib=${loc}")

Output (under Linux):

-- Qt5 found lib: Core=Qt5::Core version=5.12.5
--                Lib=

Now that I think about it, I believe the Qt project actually sets IMPORTED_LOCATION_DEBUG and IMPORTED_LOCATION_RELEASE. Try those instead.

I was trying under Linux (to get started), where _$<CONFIG> makes no sense, right?

From the CMake file on my Ubuntu-provided Qt5 package:

macro(_populate_Core_target_properties Configuration LIB_LOCATION IMPLIB_LOCATION)
    set_property(TARGET Qt5::Core APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})

    set(imported_location "${_qt5Core_install_prefix}/lib/x86_64-linux-gnu/${LIB_LOCATION}")
    _qt5_Core_check_file_exists(${imported_location})
    set_target_properties(Qt5::Core PROPERTIES
        "INTERFACE_LINK_LIBRARIES" "${_Qt5Core_LIB_DEPENDENCIES}"
        "IMPORTED_LOCATION_${Configuration}" ${imported_location} # <-- Here
        "IMPORTED_SONAME_${Configuration}" "libQt5Core.so.5"
        # For backward compatibility with CMake < 2.8.12
        "IMPORTED_LINK_INTERFACE_LIBRARIES_${Configuration}" "${_Qt5Core_LIB_DEPENDENCIES}"
    )

endmacro()

(emphasis mine)

So yes, they are setting IMPORTED_LOCATION_$<CONFIG>.

Fails with generator expression $<CONFIG>, but with literal RELEASE it does work under Linux and Windows.

Not surprising. $<CONFIG> isn’t evaluated until generate time, but you are trying to print during configure time.