title: CMake not automatically copying DLL
body: <p>I have a project with three binaries that I'm building with CMake. One is an executable and two are DLLs. Only one of the DLLs is being automatically copied by CMake to the executable's build directory; the other one isn't. The DLL being copied automatically is a C++/CLI DLL and the one that isn't is a native DLL, but links to expat which is a DLL external to my project.</p>
  
  <p>The four CMakeLists.txt files are below (with names changed).</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
  project(my_project VERSION 0.1)
  
  find_package(EXPAT REQUIRED)
  add_library(expat INTERFACE IMPORTED)
  set_target_properties(
      expat
      PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}"
  )
  
  add_subdirectory(my_exe)
  add_subdirectory(my_managed_dll)
  add_subdirectory(my_dll_using_expat)
  </code></pre>
  
  <p>my_exe/CMakeLists.txt:</p>
  
  <pre><code>set(
      SOURCES
      ...
  )
  
  add_executable(my_exe ${SOURCES})
  
  target_compile_definitions(my_exe PRIVATE _UNICODE)
  target_include_directories(
      my_exe
      PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include"
      PRIVATE include
  )
  target_link_libraries(my_exe my_managed_dll my_dll_using_expat)
  
  configure_file(include/version.in.h include/version.h ESCAPE_QUOTES @ONLY)
  
  add_custom_command(
      TARGET my_exe POST_BUILD
      COMMAND "${CMAKE_COMMAND}" -E copy
          "$&lt;TARGET_FILE_DIR:my_managed_dll&gt;/my_managed_dll.dll.config"
          "$&lt;TARGET_FILE_DIR:my_exe&gt;/my_exe.exe.config"
  )
  
  # Had to add this to also copy expat DLL.
  add_custom_command(
      TARGET my_exe POST_BUILD
      COMMAND "${CMAKE_COMMAND}" -E copy_if_different
          "$&lt;TARGET_FILE_DIR:my_dll_using_expat&gt;/expat.dll"
          "$&lt;TARGET_FILE_DIR:my_exe&gt;"
  )
  </code></pre>
  
  <p>my_managed_dll/CMakeLists.txt:</p>
  
  <pre><code>set(
      SOURCES
      ...
  )
  
  add_library(my_managed_dll SHARED ${SOURCES})
  
  target_compile_options(my_managed_dll PRIVATE /clr /EHa)
  
  # We need to remove this flag for CLR support to work.
  string(REPLACE /RTC1 "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  
  target_compile_definitions(my_managed_dll PRIVATE _UNICODE)
  target_include_directories(my_managed_dll PUBLIC include PRIVATE src)
  
  add_custom_command(
      TARGET my_managed_dll POST_BUILD
      COMMAND "${CMAKE_COMMAND}" -E copy
          "${CMAKE_CURRENT_SOURCE_DIR}/src/my_managed_dll.config"
          "$&lt;TARGET_FILE_DIR:my_exe&gt;/my_exe.dll.config"
  )
  </code></pre>
  
  <p>my_dll_using_expat/CMakeLists.txt:</p>
  
  <pre><code>set(
      SOURCES
      ...
  )
  
  add_library(my_dll_using_expat SHARED ${SOURCES})
  
  target_compile_definitions(my_dll_using_expat PRIVATE _UNICODE)
  target_include_directories(
      my_dll_using_expat
      PUBLIC include
      PUBLIC ${EXPAT_INCLUDE_DIRS}
      PRIVATE src
  )
  target_link_libraries(my_dll_using_expat ${EXPAT_LIBRARIES})
  
  add_custom_command(
      TARGET my_dll_using_expat POST_BUILD
      COMMAND "${CMAKE_COMMAND}" -E copy_if_different
          "${EXPAT_INCLUDE_DIR}/../bin/expat.dll"
          "$&lt;TARGET_FILE_DIR:my_dll_using_expat&gt;"
  )
  </code></pre>