Ninja Multi-config: POST_BUILD command script not respecting ${CONFIGURATION}
Problem:
When using Ninja (or Ninja Multi-config) generator, and the POST_BUILD command-line exceeds some threshold (as defined in https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/cmLocalNinjaGenerator.cxx#L485) the said command-line is written to a file instead. On Windows that would be post-build.bat
(https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/cmLocalNinjaGenerator.cxx#L426).
In such case of a long command-line, when the Ninja Multi-config is used, and this file contains ${CONFIGURATION}
variable (as defined by CMAKE_CFG_INTDIR
- https://cmake.org/cmake/help/latest/variable/CMAKE_CFG_INTDIR.html), the ${CONFIGURATION}
variable is not expanded and produces errors when invoked through the Windows shell during the build-time.
This problem doesn't exist if the POST_BUILD command-line doesn't exceed the threshold (probably because then it's directly a part of impl-.ninja and is expanded correctly)
--
For example:
Use ${CMAKE_CFG_INTDIR}
when defining add_custom_command(... POST_BUILD ...
, and make sure it's a sufficiently long command.
Expected behavior:
Having post-build.bat
file called with a paramter allowing the shell to expand the ${CONFIGURATION} variable
Actual behavior:
post-build.bat
contains "${CONFIGURATION}" string which is not expandable by the Windows shell and produces build-time errors
--
Tested with CMake 3.19/Windows 10/Ninja Multi-config/clang-cl (but I don't see anything that would change it in master
).
See also: #22123 (closed)