How to tell CMake to use relative paths

2019-01-15 21:21发布

问题:

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?

回答1:

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

  • CMake FAQ: Why does CMake use full paths, or can I copy my build tree?
  • How do I move my folders created by CMake?


标签: cmake