Installing versioned Qt libraries with namelinks on Linux

I have a Linux build of Qt where each library has a fully-versioned name with symlinks representing shorter version numbers:

lrwxrwxrwx 1 username username 20 Sep 20 2019 libQt5Core.so -> libQt5Core.so.5.12.5
lrwxrwxrwx 1 username username 20 Sep 20 2019 libQt5Core.so.5 -> libQt5Core.so.5.12.5
lrwxrwxrwx 1 username username 20 Sep 20 2019 libQt5Core.so.5.12 -> libQt5Core.so.5.12.5
-rwxr-xr-x 1 username username 76960984 Sep 20 2019 libQt5Core.so.5.12.5

When I link to it from my application and use ‘ldd’ on the resulting executable, I see that it’s looking for the libQt5Core.so.5 namelink.

So, now I want to install the libraries on another computer; I’ll put them in the same directory as my application’s executable, and set LD_LIBRARY_PATH to tell it where to look for the Qt libraries.
However, I can’t work out how to do this. I want to create my installation package using CPack, and the first stage of this is to use CMake to install the various libraries into a location from where CPack can use the Qt Installer Framework to put everything together.

Looking at the CMake documentation, the proper way to do this ought to be “install(TARGETS …”, which will then install the namelinks alongside the file itself. But I can’t get this to work. I can load Qt5::Core etc. as targets well enough:

find_package(Qt5 COMPONENTS Core Gui Widgets Designer Test REQUIRED PATHS "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5" NO_DEFAULT_PATH)
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
list(GET QT_CORE_INCLUDE_DIRS 0 QT_CORE_MAIN_INCLUDE_DIR)
get_filename_component(QT_MAIN_DIR ${QT_CORE_MAIN_INCLUDE_DIR}/.. ABSOLUTE)
message("-- Using the build of Qt located at ${QT_MAIN_DIR}")

…thereby confirming that I’ve found Qt and loaded Qt5::Core, Qt5::Gui etc. as targets, which I then go and use in various ways that work just fine.

However, if in the same file I then add:

install(TARGETS Qt5::Core Qt5::Gui Qt5::Widgets
        LIBRARY
        DESTINATION myInstallDirectory)	

…then at configuration time I get the error:

install TARGETS given target "Qt5::Core" which does not exist

I presume this must be because ‘find_package’ loads the targets at configuration time, whilst ‘install’ runs at installation time by which time the library details will have been forgotten; but how do I combat that?

The only other mechanism I can see for copying a file along with its symlinks is file(COPY … DESTINATION … FOLLOW_SYMLINK_CHAIN), but the documentation say that this will be executed at configuration time not at installation time.

So what am I doing wrong? Is there a ‘proper’ way to install a Qt library with its namelinks?

Solved: see here.