Skip to content

Add support for build tree symlink inside source tree

Brad King requested to merge brad.king/cmake:symlink-build-under-source into master

Since !6148 (merged), both the Ninja and Makefile generators pass source files and include directories to the compiler as absolute paths. However, in some other contexts within generated build systems, we generate paths that may be relative or absolute. In these contexts, we prefer relative paths, but avoid them when they contain a ../ sequence that leaves both the build tree and the source tree:

  • When the build tree is outside of the source tree, all paths to the source tree are absolute.

  • When the build tree is inside the source tree, we previously assumed that it is a real directory such that exiting the build tree with ../ enters the source tree. This allowed paths to the source tree to be relative to the build tree.

In the latter case, we previously did not support using a symbolic link inside the source tree to point at the build tree. This is because relative paths to the source tree would be generated with ../ sequences leaving the build tree, but they would jump to the parent of the real build tree, which is not the source tree.

Fix this by requiring that ../ sequences stay inside the build tree even if its path appears to be inside the source tree. When the build tree is inside the source tree, all paths to the source tree are now absolute. For consistency, this applies regardless of whether the path to the build tree contains a symbolic link.

Fixes: #21819 (closed)

Merge request reports