Skip to content

Ninja generator creates scripts for multi-command actions

Roger Leigh requested to merge rleigh/cmake:ninja-cmd into master

Closes #15612 (closed)

This avoids exceeding the maximum length of command lines. For the common case where the command is two commands or less, the existing behaviour is retained, and the commands are run in place. For three or more, a script containing the commands is generated and run instead. The script has the name of the target plus the build phase the action runs in. The custom command also includes a short hash of the full filename path to avoid name clashes.

I've tested this with hdf5 1.10.1 and develop, which were previously failing to build with Ninja on Windows when run from a build directory with a long path.

Testing: Run Ninja with a project using multiple commands. Look in CMakeFiles for the scripts/batch files and check their contents. The hdf5 1.10.1 source I used makes scripts for the "post-build2" and "utility". For other actions, you can tweak the logic in BuildCommandScript so that it makes scripts for all actions, not just with >2 commands. Then run ninja to build and invoke all the scripts.

This is the first time I've worked on the Ninja generator, so this might require further work. Hopefully it's a reasonable start though!

Merge request reports