I have a root cmake project consisting of two subprojects, one is a library, the other are unit tests. Unit tests link to the library.
On Windows, I need to copy all dependend .dll-s for shared builds next to the unit test .exe for it to be able to run.
I do this with the following logic seen here:
Since this is a Qt project, I first run windeployqt which is the recommended way to gather all necessary Qt dependencies.
Then, three remaining dependencies need to be copied, zlib, bz2 and the tested library itself. I do that with custom command and $<TARGET_RUNTIME_DLLS:qztest> (it was incredibly hard to track this down in the first place).
This almost works with a bizarre problem that bz2 is only copied if I run cmake build a second time. What could possibly cause this? Some kind of a race condition? I am all out of ideas.
It is part of the post deploy, defined in cmake/windeployqt.cmake
Now that you mention it, it does seem that bzip is not added into target libraries the same way as zlib is so there might be something about that. I’ll look into it. I think I was too surprised about the fact that it was copied on second build to check if there are any differences from other dependencies that work on first try.