Can't have build directory as symlink
This seems related to https://cmake.org/Bug/view.php?id=15436 , but I find it is happening for both Makefile generators and the Ninja generator on Linux. This has been confirmed with cmake 2.8.12.2 on Ubuntu 14.04, and cmake 3.5.1 on Ubuntu 16.04.
Steps:
#!/bin/bash
# Simple CMake project
DIRNAME=$(mktemp -d)
echo Project source in $DIRNAME
cd $DIRNAME
cat > hello.c <<DATA
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
DATA
cat > CMakeLists.txt <<DATA
project(hello)
add_executable(hello hello.c)
DATA
# Regular directory in source tree
echo Trying with build as subdirectory
mkdir build
cd build
cmake $DIRNAME
make
if [ "x$?" == "x0" ] ; then
echo Build success
else
echo Build failed
fi
cd ..
rm -rf build
# Symlink in source tree
ANOTHERDIR=$(mktemp -d)
echo Trying with build as symlink to $ANOTHERDIR
ln -s $ANOTHERDIR build
cd build
cmake $DIRNAME
make
if [ "x$?" == "x0" ] ; then
echo Build success
else
echo Build failed
fi
Running the above script is a minimal case that shows the issue.
The output I'm seeing in the symlink case is:
make[2]: *** No rule to make target '../hello.c', needed by 'CMakeFiles/hello.dir/hello.c.o'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/hello.dir/all' failed
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Build failed
Note that at all times absolute paths are provided to cmake, so the relative path is coming from inside cmake. Since the .. inode of the symlinked directory is different to the one of the symlink itself, none of the files can be found.
Much like the reporter of the original bug symlinks are in use to separate an SSD build directory from an NFS source tree, which seems like a useful set up to support.