cmState::Directory::ComputeRelativePathTopBinary() should not execute Windows specific bits on anything else (e.g. Linux)
We are bootstrapping Linux distribution on a new architecture (riscv64) and we recently added a build of CMake. At this point our rootfs boots with "root" account and HOME is "/". We are building RPM based Fedora distribution. rpm-build defines: %_topdir %{getenv:HOME}/rpmbuild
and in this case we get //rpmbuild
as %_topdir
.
The following Windows specific bit is triggered in cmState::Directory::ComputeRelativePathTopBinary()
756 // The current working directory on Windows cannot be a network
757 // path. Therefore relative paths cannot work when the binary tree
758 // is a network path.
759 if (result.size() < 2 || result.substr(0, 2) != "//") {
760 this->DirectoryState->RelativePathTopBinary = result;
761 } else {
762 this->DirectoryState->RelativePathTopBinary = "";
763 }
CMake ends up calling Make targets with prefixes //rpmbuild/BUILD/<package_name>/build/<make_rule_name>
.
E.g.,
make -f CMakeFiles/Makefile2 //rpmbuild/BUILD/nss-pem-1.0.2/build/all
make[1]: Entering directory '/rpmbuild/BUILD/nss-pem-1.0.2/build'
make[1]: *** No rule to make target '//rpmbuild/BUILD/nss-pem-1.0.2/build/all'. Stop.
The problem is that then it cannot find the rule.
If one sets --define "_topdir /rpmbuild"
for rpm-build it makes CMake work.
TL;DR Windows specific bit should be protected by Windows specific guards.