8

If I make my project I can see this:

[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
/cygdrive/c/users/me/Home/bin/iccarm  /cygdrive/c/users/me/Home/sandbox/iar/hello.c  -I/cygdrive/c/users/me/Home/sandbox/iar/foo -I/cygdrive/c/users/me/Home/inc   -o CMakeFiles/hello.dir/hello.c.obj

Since I always call make inside my build directory, why not using relative path for the sake of readability and compatibility across operating systems?

[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
iccarm  hello.c -Ifoo -Iinc -o CMakeFiles/hello.dir/hello.c.obj

Is it much better isn't it?

Is there a way to force CMake to use relative paths as much as possible?

nowox
  • 25,978
  • 39
  • 143
  • 293

2 Answers2

12

CMake does always use absolute paths. It's part of the concept. Therefore you can't move the generated build environment files nor can you e.g. bring them under source control or make the verbose output prettier (you could just play a little with the rule messages like here).

There once was CMAKE_USE_RELATIVE_PATHS, but the documentation reveals:

This variable has no effect. The partially implemented effect it had in previous releases was removed in CMake 3.4.

References

Florian
  • 39,996
  • 9
  • 133
  • 149
  • 1
    So it means `CMake` will not work properly on Cygwin. That a very sad news. I am wondering why they removed `CMAKE_USE_RELATIVE_PATHS` it was just perfect... – nowox Aug 24 '17 at 13:25
  • @nowox Cygwin only works with the `cygwin` version of CMake. It will not work with the Windows version. And I think it was removed because it caused so many issues (CMake bugtracker was full of it). – Florian Aug 24 '17 at 13:41
  • which was removed? The windows version or the Cygwin version? The main issue with absolute paths is that if you use a tool chain built for Windows, the compiler is expecting windows paths. It works with Cygwin as long as the paths are relative but once you get absolute paths you have to write a bind script that replace the ugly /cygwin/c/ things with C:\... I would be nice if CMake had an option to do this on the fly – nowox Aug 24 '17 at 13:45
  • @nowox Sorry, I meant the `CMAKE_USE_RELATIVE_PATHS` variable was removed because it had to many issues. – Florian Aug 24 '17 at 14:14
  • 4
    Well, having absolute paths is right pain to me. I can't move my source directory? How is that an advantage? – noelicus Sep 13 '18 at 10:48
0

CMakes gets the paths from the CMake generator. Using other generators like Ninja, produces relative paths by default.

You can use the -G option while running the cmake generation command. Example:

cmake .... -G Ninja

You can also export compile commands which will be useful in navigating your files in most editors.