Copying created shared libraries

A common alternative solution to Windows’ lack of something like RPATH is to set the output directory of all executables and shared libraries to the same location. It isn’t always feasible (and personally I dislike it, since the clutter is considerable for large projects), but if it suits your situation, that is probably the simplest way to get easily debuggable binaries. Projects taking this approach typically set CMAKE_RUNTIME_OUTPUT_DIRECTORY sufficiently high in their directory structure to capture all the executables and shared libraries the project defines. You would also need to check how this might affect dependencies also built by the project. Another wrinkle is test executables - sometimes there could be very many of these, and you might not want them mixed in with the non-test executables.

I generally discourage copying around DLLs in POST_BUILD rules. You end up with multiple copies of your DLLs littered around your build directory and it’s easy to end up using an out-of-date DLL. As you’ve discovered, it isn’t always easy to get the DLLs you want copied, and it gets combinatorially worse the more executables you have that need your DLLs. Furthermore, you may also need to copy around PDBs (I don’t recall if that’s needed or not). Given the downsides, if you can avoid copying DLLs around like this, that would be better.