Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell CMake to use relative paths

Tags:

cmake

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?

like image 476
nowox Avatar asked Aug 24 '17 08:08

nowox


1 Answers

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?
like image 71
Florian Avatar answered Sep 22 '22 02:09

Florian