symlink in leading path: No rule to make target
I have the directory /local/$USER symlinked to $HOME/local, because HOME is mounted on a network share (not by my choice), while /local/
USER is mounted on a local disk. I usually call cmake from a working directory such as HOME/local/myproject. However, some of my scripts resolve the path and then call cmake from the working directory /local/
USER/myproject. The following example shows how this can produce a build error:
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(CmakeSymlinkTest)
add_custom_target(build ALL DEPENDS build.stamp)
add_custom_command(OUTPUT build.stamp COMMAND cat <input.txt >build.stamp DEPENDS input.txt)
$ echo test >input.txt
$ ln -s . symdir
$ cd symdir
$ cmake .
$ cmake --build .
[ this build succeeds ]
$ cd "$(pwd -P)"
$ cmake .
$ cmake --build .
gmake[2]: *** No rule to make target `symdir/build.stamp', needed by `CMakeFiles/build'. Stop.
gmake[1]: *** [CMakeFiles/build.dir/all] Error 2
gmake: *** [all] Error 2
The generated build.make references "build.stamp" for the target, but "symdir/build.stamp" for the build dependency:
$ grep 'build\.stamp' CMakeFiles/build.dir/build.make
CMakeFiles/build: symdir/build.stamp
build.stamp: symdir/input.txt
As a workaround, I have to call "cmake ." twice:
$ cd symdir
$ cmake .
$ cmake --build .
$ cd "$(pwd -P)"
$ cmake .
$ cmake .
$ cmake --build .
[ this build succeeds ]