CMake resolves path to itself, breaks upgrades where symlinks are in the path
This came up in discussions of an issue for a snap user. The snap system installs packages to a versioned directory and uses a symlink to the current version. When you run cmake
, it resolves the path to itself, removing symlinks. This results in a path like /snap/cmake/513/bin/cmake
instead of /snap/cmake/current/bin/cmake
. When the snap is updated, the path CMake stores in its build files still point to the old location, which might not even be there any more. If the user triggers a build after CMake is updated and they don't run cmake
from the now changed path first, their build can break due to the old path no longer being valid.
From a quick look just now, it seems the logic for this is in cmSystemTools::FindCMakeResources()
, where the base path is computed like this:
exe_dir =
cmSystemTools::GetFilenamePath(cmSystemTools::GetRealPath(exe_path));
There has been some work in recent years to try to keep symlinks in paths to the source and build directory. I'd argue we should be doing the same thing for this base path to the CMake base install location too.