So I have:
get_filename_component(a_dir ${some_file} PATH)
get_filename_component(a_last_dir ${a_dir} NAME)
In which a_last_dir should return the lowest level of my directory and a_dir should return my full directory.
Anyway I can make a_second_last_dir possible?? To return the second-lower level of the full directory?
Turning my comments into an answer
You can use
get_filename_component()
by appending../..
.I understand your current solution to look like this:
Which gives
a_second_last_dir = dir
as an output.You can get the same output with:
The intermediate
a_second_dir
path could be an invalid/non-existing path (sinceCMAKE_CURRENT_SOURCE_DIR
is prefixed), but I think it does not matter here.If you want it to be a correct absolute path, you should prefix the correct base dir yourself (or see CMake 3.4 which introduced
BASE_DIR
option toget_filename_component(... ABSOLUTE)
).