Ninja Generator does not generate absolute paths
The Ninja generator behaves differently from the Makefile generator. With Ninja relative paths are used instead of absolutes, which means that tools evaluating the compiler output (vim, emacs, ...) cannot jump to the correct location, unless the CWD is the build folder. This is quiet annoying because in the nomal workflow using such tools the CWD as a source dir, not the build dir. Also the paths in generated debug info is not correct which may cause troubles when debugging or analyzing core dumps.
I captured the output of the same helloworld program using "make VERBOSE=1" and "ninja -v" to show the difference:
ninja output:
[1/2] /usr/bin/gcc -g -MMD -MT CMakeFiles/helloworld.dir/main.c.o -MF CMakeFiles/helloworld.dir/main.c.o.d -o CMakeFiles/helloworld.dir/main.c.o -c ../main.c
FAILED: /usr/bin/gcc -g -MMD -MT CMakeFiles/helloworld.dir/main.c.o -MF CMakeFiles/helloworld.dir/main.c.o.d -o CMakeFiles/helloworld.dir/main.c.o -c ../main.c
../main.c: In function ‘main’:
../main.c:6:5: error: ‘x’ undeclared (first use in this function)
x
^
../main.c:6:5: note: each undeclared identifier is reported only once for each function it appears in
../main.c:7:5: error: expected ‘;’ before ‘return’
return 0;
^
ninja: build stopped: subcommand failed.
make output:
/usr/bin/cmake -H/home/gergap/tmp/helloworld -B/home/gergap/tmp/helloworld/bldmake --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/gergap/tmp/helloworld/bldmake/CMakeFiles /home/gergap/tmp/helloworld/bldmake/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/gergap/tmp/helloworld/bldmake'
make -f CMakeFiles/helloworld.dir/build.make CMakeFiles/helloworld.dir/depend
make[2]: Entering directory '/home/gergap/tmp/helloworld/bldmake'
cd /home/gergap/tmp/helloworld/bldmake && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/gergap/tmp/helloworld /home/gergap/tmp/helloworld /home/gergap/tmp/helloworld/bldmake /home/gergap/tmp/helloworld/bldmake /home/gergap/tmp/helloworld/bldmake/CMakeFiles/helloworld.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/gergap/tmp/helloworld/bldmake'
make -f CMakeFiles/helloworld.dir/build.make CMakeFiles/helloworld.dir/build
make[2]: Entering directory '/home/gergap/tmp/helloworld/bldmake'
[ 50%] Building C object CMakeFiles/helloworld.dir/main.c.o
/usr/bin/gcc -o CMakeFiles/helloworld.dir/main.c.o -c /home/gergap/tmp/helloworld/main.c
/home/gergap/tmp/helloworld/main.c: In function ‘main’:
/home/gergap/tmp/helloworld/main.c:6:5: error: ‘x’ undeclared (first use in this function)
x
^
/home/gergap/tmp/helloworld/main.c:6:5: note: each undeclared identifier is reported only once for each function it appears in
/home/gergap/tmp/helloworld/main.c:7:5: error: expected ‘;’ before ‘return’
return 0;
^
CMakeFiles/helloworld.dir/build.make:62: recipe for target 'CMakeFiles/helloworld.dir/main.c.o' failed
make[2]: *** [CMakeFiles/helloworld.dir/main.c.o] Error 1
make[2]: Leaving directory '/home/gergap/tmp/helloworld/bldmake'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/helloworld.dir/all' failed
make[1]: *** [CMakeFiles/helloworld.dir/all] Error 2
make[1]: Leaving directory '/home/gergap/tmp/helloworld/bldmake'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
This issue was already reported in 2013, see https://public.kitware.com/Bug/print_bug_page.php?bug_id=13894 but the provided patch was reverted.
I'm looking forward to get this fixed. The only workaround I know for the moment is to use Make instead of Ninja.