As you want a post-build action, there is a CMake command and also the appropriate variables available.
The platform independent command to copy around files with CMake is using CMake itself on the command line:
${CMAKE_COMMAND} -E copy_if_different "${src}" "${dest}"
The "current" configuration can be extracted with generator expressions:
$<CONFIG>
and even directly tested for trueness
$<CONFIG:Debug>
The output directory for a target's binaries (i.e. executables and shared libraries/DLLs) is given with the target property RUNTIME_OUTPUT_DIRECTORY
(and RUNTIME_OUTPUT_DIRECTORY_<CONFIG>
) which are pre-populated with the global variable CMAKE_RUNTIME_OUTPUT_DIRECTORY
(and CMAKE_RUNTIME_OUTPUT_DIRECTORY_<CONFIG>
).
Finally, we can compose the post-build command
add_custom_command(TARGET myTarget POST_BUILD
COMMAND if $<CONFIG:Debug> ("${CMAKE_COMMAND}" -E copy_if_different "${path_to_dependent_dll}/dependent.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}")
COMMAND if $<CONFIG:Release> ("${CMAKE_COMMAND}" -E copy_if_different "${path_to_dependent_dll}/dependent.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}")
COMMENT "Copying dependent DLL"
)