nowox
nowox

Reputation: 29126

How to tell CMake to use relative paths

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?

Upvotes: 9

Views: 13408

Answers (2)

Florian
Florian

Reputation: 43030

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

Upvotes: 11

Mina Ghobrial
Mina Ghobrial

Reputation: 305

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.

Upvotes: 0

Related Questions