CMAKE_CFG_INTDIR and file(INSTALL)

When attempting to use an install line of the following form with the NSIS package generator:

add_custom_command(
      OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/outfile
      COMMAND gen_file ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/outfile
      DEPENDS gen_file
      )
install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/outfile DESTINATION data)

I’m getting the following error and I’m not sure how to interpret it:

CMake Error at C:/project/build/cmake_install.cmake:65 (file):
   file INSTALL cannot find
   "C:/project/build/$(Configuration)/outfile":
   File exists.

The configuration is Release, and if I look in the release directory the file is indeed present - what is this error referring to? (The same build, by the way, does work with Release configuration of the Ninja Multi-Config generator on Linux…)

${CMAKE_CFG_INTDIR} expands to $(Configuration) under VS. $(Configuration) is a Visual Studio User macro and is thus only interpreted correctly when VS is interpreting the path. The arguments to install() are instead interpreted by CMake at install time (they are embedded in cmake_install.cmake), and so $(Configuration) is just a literal string in that context.

Since install() supports generator expressions in the source arguments, you can use a suitable genex there instead:

install(FILES ${CMAKE_BINARY_DIR}/$<CONFIG>/outfile DESTINATION data)