title: Using CMAKE_DEBUG_POSTFIX with exported targets
body: <p>When I use <code>set(CMAKE_DEBUG_POSTFIX "d")</code>, the build and install targets work as expected. But in the <code>libfooTargets-debug.cmake</code> file with the exported targets, there is a path to <code>libfoo</code> and not <code>libfood</code>.</p>
  
  <p>I exported the targets like this:</p>
  
  <pre><code>install(TARGETS libfoo EXPORT libfoo-targets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)
  install(EXPORT libfoo-targets FILE libfooTargets.cmake DESTINATION ${CMAKE_INSTALL_PREFIX})
  </code></pre>
  
  <p>which creates and installs <code>libfooTargets.cmake</code> and <code>libfooTargets-debug.cmake</code> when building in debug mode, and <code>libfooTargets.cmake</code> and <code>libfooTargets-release.cmake</code> when building in release mode.</p>
  
  <p>Both <code>libfooTargets-release.cmake</code> and <code>libfooTargets-debug.cmake</code> reference the name without a postfix as:</p>
  
  <pre><code>list(APPEND _IMPORT_CHECK_FILES_FOR_libfoo "${_IMPORT_PREFIX}/lib/libfoo.lib" )
  </code></pre>
  
  <p>and thus a program linking against the debug target still uses the release-build library and I would need to install release and debug versions into different folders to be able to link against the debug target.</p>
  
  <p>How can I get the exported targets to work with a debug postfix?</p>
  
  <hr>
  
  <p>I could of course try to change the library name depending on <code>CMAKE_RELEASE_TYPE</code> or a <code>CONFIGURATION</code> generator expression, but this will probably break the multi-configuration features in MSVC and other IDEs supporting different targets and seems not to work in the sense of how the exported targets feature is meant to simplify and unify the build.</p>
  
  <p>I suspect that the <code>install(EXPORT ...)</code> command somehow drops the <code>CMAKE_DEBUG_POSTFIX</code> or does not implement it for generating the <code>libfooTargets-{release,debug}.cmake</code> files, but possibly I overlooked how to make this variable visible to the generator of the exported targets or something like this.</p>
  
  <hr>
  
  <p>All target code</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.11.1)
  project(foo)
  include(CMakePackageConfigHelpers)
  set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
  set(CMAKE_DEBUG_POSTFIX "d")
  
  # ...
  
  add_library(libfoo STATIC somesource.cpp someheader.h)
  target_include_directories(libfoo PUBLIC
           $&lt;INSTALL_INTERFACE:include&gt;
          $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include&gt;
  )
  target_link_libraries(libfoo
          somelibrary
  )
  target_include_directories (libfoo PUBLIC
          somelibrary_header_dirs
  )
  install(TARGETS libfoo EXPORT libfoo-targets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)
  install(EXPORT libfoo-targets FILE libfooTargets.cmake DESTINATION ${CMAKE_INSTALL_PREFIX})
  
  configure_package_config_file(libfooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libfooConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX})
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfooConfig.cmake DESTINATION ${CMAKE_INSTALL_PREFIX})
  install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
  </code></pre>
  
  <p>The platform is a Windows 10 with cmake 3.11.1 and MSVC 2015. Of course the most general solution is probably the best one.</p>