# How to print location of Qt5 component library?

**URL:** <https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462>\
**Category:** Code\
**Created:** [January 7, 2020, 5:28pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462 "2020-01-07T17:28:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 7, 2020, 5:28pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/1 "2020-01-07T17:28:44Z")

</div>

CMake code

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

```

results in informative output like

```auto
-- 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

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

```

only yields

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

```

How to print the actual path of the Qt5Core library?

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [January 7, 2020, 5:56pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/2 "2020-01-07T17:56:00Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 7, 2020, 6:04pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/3 "2020-01-07T18:04:11Z")

</div>

Results in an empty string.

CMake code:

```auto
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):

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

```

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [January 7, 2020, 6:17pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/4 "2020-01-07T18:17:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 7, 2020, 6:21pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/5 "2020-01-07T18:21:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [January 7, 2020, 6:27pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/6 "2020-01-07T18:27:46Z")

</div>

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

```cmake
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>`.

---

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [January 7, 2020, 6:34pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/7 "2020-01-07T18:34:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [January 7, 2020, 6:47pm UTC](https://discourse.cmake.org/t/how-to-print-location-of-qt5-component-library/462/8 "2020-01-07T18:47:46Z")

</div>

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