Skip to content

Makefiles: Re-implement makefile target path escaping and quoting

Brad King requested to merge brad.king/cmake:makefile-target-special into master

Previously we used cmSystemTools::ConvertToOutputPath which internally used KWSys methods

  • SystemTools::ConvertToUnixOutputPath
  • SystemTools::ConvertToWindowsOutputPath

These were written in very early days of CMake and have some limitations:

  • They do not encode all characters. E.g. # is left out.
  • They attempt to do some path cleanup and handle existing quotes. These days CMake has clean unquoted paths already.
  • They attempted to encode paths both for makefile targets and for shell command lines. The latter use has mostly been replaced.
  • Choosing between the two methods depends on a global variable! Several code paths in CMake have to copy the global generator's member ForceUnixPaths variable over to the cmSystemTools global.

Factor out makefile target path escaping and quoting into a new ConvertToMakefilePath method. Re-implement the new method to drop use of those old methods. Compute suitable makefile target path escaping and quoting via local logic. Add support for more characters like '#'.

This fixes the IncludeDirectories test coverage of special chars so enable it for Makefiles.

Fixes: #20555 (closed)

Merge request reports