title: How to copy a dll from a library into the executable output directory in cmake?
body: <p>My <code>CMakeLists.txt</code> creates several libraries using <code>add_library(MyLib SHARED ${files})</code> the resulting libraries end up in <code>&lt;root&gt;/build/libs/MyLib/[Debug|Release]/</code>
  where root is the directory where the main <code>CMakeLists.txt</code> is.</p>
  
  <p>How can I copy <code>MyLib.dll</code> to the directory where <code>add_executable</code> puts the .exe file in CMake? Note that it is important that the .dll copied is the one under Debug or Release depending the build type. Is this possible?</p>
  
  <pre><code>root/
  |_ build/
  |  |_ Debug/
  |  |  |_ MyApp.exe
  |  |  |_ MyLibd.dll (copied from MyLib/Debug)
  |  |_ Release/
  |  |  |_ MyApp.exe
  |  |  |_ MyLib.dll (copied from MyLib/Release)
  |  |_ libs/
  |     |_ MyLib/
  |        |_ Debug/
  |        |  |_ MyLibd.dll
  |        |_ Release/
  |           |_ MyLib.dll
  |_ libs/
  |  |_ MyLib/
  |     |_ MyLib.cpp
  |     |_ MyLib.hpp
  |     |_ CMakeLists.txt
  |_ CMakeLists
  </code></pre>