[CMake] cmake deletes cache when source patch contains symlink to complier directory

Russell Yanofsky russ at yanofsky.org
Wed Nov 25 11:35:48 EST 2009


(I tried to create a Mantis bug, but Mantis won't let me log in, and
when I try to reset the password, I see "This account is protected. You
are not allowed to access this until the account protection is lifted."
I tried creating a completely new account, and I see the same message
with that.)

Simple set of steps to reproduce this bug:

        mkdir /usr/bug_test
        ln -s /usr test_symlink
        cd test_symlink/bug_test
        echo "project(test)" > CMakeLists.txt
        cmake -DCMAKE_C_COMPILER=/usr/bin/gcc .
        cmake .

The bug is that the second CMake command outputs:

        You have changed variables that require your cache to be
        deleted. Configure will be re-run and you may have to reset some
        variables.

This warning is invalid because no variables were changed, and it is a
problem because after CMake deletes the cache, the configuration can be
hosed.

The reason why for the warning and CMake deleting the cache on the
second invocation is that the first invocation incorrectly saves
different CMAKE_C_COMPILER paths to CMakeCache.txt and
CMakeFiles/CMakeCCompiler.cmake files. The CMakeCCompiler file has the
original path:

        SET(CMAKE_C_COMPILER "/usr/bin/gcc")

But the cache looks something like:

        CMAKE_C_COMPILER:FILEPATH=/home/russ/test_symlink/bin/gcc

The reason for the discrepency is that cache path gets transformed with
the SystemTools::CollapseFullPath function, while the CCompiler path
uses the original path specified on the command line.

This bug is difficult to work around because the
SystemTools::CollapseFullPath uses logic that resolves symlinks in
reverse, which is something that would require some path crawling
outside of CMake.

I think a safe and straightforward fix would be to make cmake use
SystemTools::CollapseFullPath for the path it writes to
CMakeFiles/CMakeCCompiler.cmake, but I didn't see an obvious way of
implementing this, because the file is generated by CMake code, and not
C++ code. I wonder if it makes sense to expose the CollapseFullPath
function to CMake scripts so CMake code can use it.

This bug just started happening for me recently, after my project layout
changed, but I tested with a few CMake versions and the behavior is the
same in CMake 2.8.0, 2.6.4, 2.6.2, and 2.6.0.

I do want to say thanks to CMake developers for making this powerful and
well thought-out tool. I've had my share of learning experiences with
CMake but given complexity of what CMake does, I've been amazed to never
have encountered any real bugs until now, and this bug just seems like
an unhandled corner case.

- Russ



More information about the CMake mailing list