title: CMake - Alternative to generator expression for build output directory?
body: <p>I have a cmake build system gone wild. Before supporting IDEs, everything was ok.</p>
  
  <p>I need to copy files (shaders in this case) to the build directory. They need to be copied when they've changed, regardless of whether the main target is built or not.</p>
  
  <p>I had success before, as I could add a custom command with <code>${CMAKE_CURRENT_BINARY_DIR}</code>, add dependencies later and everything was fine.</p>
  
  <p>The problem is, when using a generator expression for the command output, it creates a dependency from my custom command to the main target. This means adding a dependency backwards (which is needed to trigger the copy) throws an error because of cyclic dependencies.</p>
  
  <p>This is what I have so far, which doesn't work because the custom target (thus custom command) is not triggered when the main target doesn't need rebuilding.</p>
  
  <pre><code>set(SHADER_IN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders)
  file(GLOB_RECURSE SHADERS "${SHADER_IN_DIR}/*.glsl")
  
  add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E make_directory $&lt;TARGET_FILE_DIR:${PROJECT_NAME}&gt;/shaders/)
  
  set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/.stamps)
  add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
      COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR})
  
  set(STAMP_FILES "")
  foreach(SHADER ${SHADERS})
      get_filename_component(SHADER_FILENAME ${SHADER} NAME)
  
      set(STAMP_FILE ${STAMP_DIR}/${SHADER_FILENAME}.stamp)
  
      add_custom_command(
          OUTPUT ${STAMP_FILE}
          COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE}
          COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SHADER} $&lt;TARGET_FILE_DIR:${PROJECT_NAME}&gt;/shaders/${SHADER_FILENAME}
          DEPENDS ${SHADER}
      )
  
      list(APPEND STAMP_FILES ${STAMP_FILE})
  endforeach()
  
  add_custom_target(Shaders
      SOURCES ${SHADERS}
      DEPENDS ${STAMP_FILES})
  
  # Need to add dependency here! But I can't :(
  </code></pre>
  
  <p>So, is there any other way to get what output directory will be used in an IDE? All "solutions" I've read to force building a target have failed (they pretty much all rely on <code>add_dependencies</code>).</p>
  
  <p>Thank you for saving my sanity.</p>