Install DLL from imported package

Hello,

In my project, I use thye package Xerces-C++. So I do :

find_package(XercesC 3.2.5 CONFIG REQUIRED)

if(XercesC_FOUND)
    message(STATUS "@@@@@@@@@@@@@@@@ Xerces found")
    message(STATUS "@@@@@@@@@@@@@@@@ Xerces version: ${XercesC_VERSION}")
    message(STATUS "@@@@@@@@@@@@@@@@ Xerces include dirs: ${XercesC_INCLUDE_DIRS}")
    message(STATUS "@@@@@@@@@@@@@@@@ Xerces libraries: ${XercesC_LIBRARIES}")
else()
    message(FATAL_ERROR "Xerces not found")
endif()

I can link it with my project without any problem :

target_link_libraries(MyProject PRIVATE XercesC::XercesC)

Note I found the value XercesC::XercesC only thanks to the message() command. I didn’t find documentation about this point.

Next, I want to install the Xerces DLLs. I tried several flavors of the install() command, but I fail.

Ie (at the end of the CMakeLists.txt):

install(IMPORTED_RUNTIME_ARTIFACTS XercesC::XercesC
        RUNTIME_DEPENDENCY_SET foo
        RUNTIME)

Here is the log :

  -- @@@@@@@@@@@@@@@@ Xerces found
  -- @@@@@@@@@@@@@@@@ Xerces version: 3.2.5
  -- @@@@@@@@@@@@@@@@ Xerces include dirs: E:/CMake/bin/ExternalDependencies/XercesC-install/x64/Debug/include
  -- @@@@@@@@@@@@@@@@ Xerces libraries: XercesC::XercesC
...
  CMake Error at src/CMakeLists.txt:488 (install):
    install IMPORTED_RUNTIME_ARTIFACTS given target "XercesC::XercesC" which is
    not an executable, library, or module.

Note the code of my project isn’t compiled/linked at all, whereas it is when I remove the install() command (located at the end of the CMakeLists.txt).

What am I supposed to do to install the DLL coming with Xerces ?

XercesC::XercesC is probably UNKNOWN IMPORTED target. I don’t think CMake is able to install such targets (though I also think it be able to guess that it’s a shared library by inspecting IMPORTED_LOCATION property).

I have a working example (tested on OSX only):