title: How can I add both libs and dlls to a project in cmake?
body: <p>We have a fairly large project divided into various subprojects (in visual studio this a solution with several projects). Some of the subprojects depend on an external library that supplies a set of libs to link against. The folder structure is similar to this:</p>
  
  <pre><code>root
      external
          thing-with-libs
             inc
             libs
                thinger.lib
      proj1
      proj2
      proj3
  </code></pre>
  
  <p>Where, say, proj1 and proj2 both link about thing-with-libs.</p>
  
  <p>To accomplish this, we have root/external/thing-with-libs/CMakeLists.txt that looks similar to this:</p>
  
  <pre><code>project (ThingWithLibs)
  set (lib_dir "${CMAKE_CURRENT_SOURCE_DIR}/libs")
  add_library(ThingWithLibs STATIC IMPORTED GLOBAL)
  set_target_properties(ThingWithLibs PROPERTIES IMPORTED_LOCATION_DEBUG ${lib_dir}/ThingWithLibs_D.lib)
  </code></pre>
  
  <p>Then, in proj1's and proj2's CMakeLists.txt, we use <code>target_link_libraries (ThingWithLibs)</code>. This adds the dependency on ThingWithLibs and everything works.</p>
  
  <p>Now, in the latest drop of ThingWithLibs, there are both dlls and libs. We need to statically link against the libs and dynamically link against the dlls. The new structure of ThingWithLibs is:</p>
  
  <pre><code>thing-with-libs
      inc
      libs
          thinger.lib
      dlls
          thinger.dll
  </code></pre>
  
  <p>So now we need proj1 and proj2 to both statically link against thinger.lib, but we also need thinger.dll to be copied to our bin directory at some point during the build. I believe I can solve this with a post-build step to copy the dll, but I have only been able to get that to work as a post-build step in proj1 and proj2, not as a post-build step for ThingWithLibs. It seems better to have ThingWithLibs know everything there is to know about using ThingWithLibs, so I'd rather have that CMakeLists.txt file deal with the copy.</p>
  
  <p>Perhaps related, perhaps unrelated, there is no visual studio project for ThingWithLibs--cmake doesn't create one. My current guess is that the reason we don't get the post-build step of copying to work when in ThingWithLibs' CMakeLists.txt is because, with no visual studio project, there isn't anything to perform the post-build step.</p>
  
  <p>Have other people solved this problem? Thank you.</p>