Repository: opencv
Issue: Building plugins does not add them to the target runtime DLLs
Labels: category: build/install,incomplete

<!--
If you have a question rather than reporting a bug please go to https://forum.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 4.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2017
-->

- OpenCV => 4.5.4
- Operating System / Platform => Windows 11
- Compiler => Visual Studio 2019

##### Detailed description

I am not sure if this is the expected behavior or not, but building plugins does not add them to any target's runtime DLLs.
This makes installation of the plugins pretty tedious on Windows.
I am assuming the plugins are linked to their respective module.
This is a bit confusing and has cost me quite some time to understand why my Windows build was miles slower than the Linux build (plus the fact that a missing plugin at runtime fails silently unless some environment variables are set).
Setting their `IMPORTED_LOCATION` and `IMPORTED_IMPLIB` properties would allow the following code to work:

```cmake
target_link_libraries(foo opencv_core opencv_videoio opencv_highgui opencv_imgproc opencv_imgcodecs)
install(FILES $<TARGET_RUNTIME_DLLS:foo> DESTINATION bin)
```

Which is the method I currently use to deploy my application. I am not sure of the current way to do it, besides straight up copying the contents of the install directory. Thinking about it, this would not work either because I am building `opencv_core_parallel_tbb` separately and they are not installed alongside OpenCV by default.

I am not a CMake expert, so I am not sure if this would be the correct way to do it.

##### Steps to reproduce

Nothing to really reproduce I guess
<!-- to add code example fence it with triple backticks and optional file extension
    ```.cpp
    // C++ code example
    ```
 or attach as .txt or .zip file
-->

##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with questions without a real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found any solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to the latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only the latest release for each branch.
   The ticket is closed if the problem is not reproduced with the modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as an archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->