[CMake] CMake ignores out-of-tree build path after having been run in the source directory?

Chris Smowton chris at smowton.net
Sat Apr 11 06:05:30 EDT 2015


Just finished figuring out why CMake was behaving strangely for me:

Originally I built out of tree:

mkdir build
cd build
cmake ../src

However at some point it appears I screwed up and typed 'cmake' in /src

Thereafter cmake was ignoring the build path and writing all Makefiles 
in /src; I would try to change something using cmake ../src 
-DMYVAR=MYVALUE, but the change would be mysteriously ignored... because 
it was ignoring the cwd /build and updating /src/Makefile, whilst I was 
using /build/Makefile.

Is it ever valid to build in-tree and also build out-of-tree from the 
same source tree? If so then it probably shouldn't ignore the (cwd) 
build path like that. If not then it should be a fatal error or at least 
a warning that your out of tree build is not actually being updated. In 
other words, it is a tricky trap that "cmake ../src" /might/ mean 
"update the Makefiles in ../src" or /might/ mean "update the Makefiles 
in the current directory using the CMakeLists.txt in ../src"

At the moment you get:

Build files have been written to: /src

Which does indicate the problem, but because the message is routine and 
so I ignore it every day, I didn't notice it for quite some time.

Chris


More information about the CMake mailing list