Skip to content

Shorten object name even if still longer than CMAKE_OBJECT_PATH_MAX

Nick Little requested to merge nicklaus.little/cmake:shorter-obj into master

The generated object file name may be too long even when the source file name is well within the limits of the operating system. This can happen because the object file name is based on the path to the build directory plus the absolute path of the source, which can result in very long file paths. CMake gets around this in most cases by substituting some portion of the object file path with an MD5 sum. However, if the resulting path would still be too long, CMake does not substitute the MD5 sum even if the resulting path would be shorter.

When the object file is placed into the generated build files, in at least some cases (the "Ninja Multi-Config" generator), the path is relativized to make it shorter. In a lot of cases, the resulting path would have been short enough if the MD5 sum substitution had occurred even though the initial resulting path was too long. For example, here is a path that was generated before this change which is over the 260 Windows file path limit:


Here is the path generated when the MD5 sum is substituted, which is significantly shorter and able to be handled by the operating system easily:


This change will cause the MD5 sum substitution to occur anytime the resulting path will be shorter even if the resulting file path will still exceed the CMAKE_OBJECT_PATH_MAX length. The cmLocalGeneratorShortenObjectName() function still returns false if the resulting path exceeds the CMAKE_OBJECT_PATH_MAX length, so a warning will still be issued if the path is too long. The resulting path is just less likely to cause an issue when using some generators.

Edited by Brad King

Merge request reports