[CMake] How to get current directory of the included files

Eduard Bloch edi at gmx.de
Tue Sep 26 10:43:21 EDT 2006


Hello,

I need to add a certain variable and a set of strings in a set of
applications, beeing in different paths. This is required because a
static library is compiled with different settings, therefore the set of
additional libraries varies.

To avoid code duplication and adding the test multiple times, I stored
the code in a .cmake file included into various CMakeLists.txt. The code
works almost as expected, however: I wish to run a test program to
detect a system feature. I need to refer to this test code file in the
included file with the full path (because of Out-of-tree build mode).
But I cannot get this path (directory of the included file) inside of
the included .cmake file itself. ${CMAKE_CURRENT_SOURCE_DIR}/ gives me
the path of the including CMakeLists.txt and not what I need.

What I could do now is using a global var for "config code directory"
set in every CMakeLists.txt before including files, and using this
arbitrary variable in the test code.

But a nicer solution is possible if I could get the path of the included
file somehow and choose the code-directory path relative to it. But how
can I get that path?

Eduard.



More information about the CMake mailing list