CMAKE - getting a path using get_filename_component

I have a path and i would like to get the path starting from a specific path This is my current path The above outputs this I would like it to just display the path starting from the last level it should only show the path after the folder pilot so it should show something

I have a path and i would like to get the path starting from a specific path This is my current path

 macro(MY_MACRO base) foreach(ITEM ${ARGN}) get_filename_component(ITEM_PATH ${ITEM} DIRECTORY) get_filename_component(ITEM_EXT ${ITEM} EXT) source_group("${ITEM_PATH}" FILES ${ITEM}) MESSAGE ("${ITEM_PATH}") endforeach() endmacro() 

The above outputs this

/Users/admin/main/project/module/pilot/pilot/src/proA /Users/admin/main/project/module/pilot/guide/src/proB 

I would like it to just display the path starting from the last level it should only show the path after the folder pilot so it should show something like this

pilot/src/proA guide/src/proB 

Not the full path

1

1 Answer

Command file(RELATIVE_PATH) computes relative path. Usage is straightforward:

file(RELATIVE_PATH ITEM_PATH_REL # Output variable "/Users/admin/main/project/module/pilot" # Base directory ${ITEM_PATH} # Absolute path to the file ) message("Relative path: ${ITEM_PATH_REL}") 
2

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoanFoaG6Fd36OnKSao5VitKbA06KloGWRYr2iwMdmrKyhnpx6qLHTZp2ipJWjrq6xjJympqifo7KvwA%3D%3D

 Share!