Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path to the currently included cmake file in a function?

Tags:

cmake

suppose I have this:

#root/CMakeLists.txt
include(folder/file.cmake)
foo()

and

#root/folder/file.cmake
function(foo)
    message(${SOME_SPECIAL_CMAKE_VARIABLE})
endfunction()

And I want to get path/to/root/folder printed. I tried these 2 but they don't get me what I want: CMAKE_CURRENT_LIST_DIR or CMAKE_CURRENT_SOURCE_DIR.

So is there a cmake variable that will get me what I want?

Or is there a way to get the full path to file.cmake so I can atleast get it's path that way?

like image 570
onqtam Avatar asked Oct 31 '22 07:10

onqtam


1 Answers

I ended up caching the CMAKE_CURRENT_LIST_DIR variable when the file is included outside of the function and later I use the cached value inside the function - based on the comments of my question.

like image 64
onqtam Avatar answered Nov 23 '22 23:11

onqtam