[CMake] CMAKE way to get leaf of file path
Michael Hertling
mhertling at online.de
Sun Nov 7 03:49:23 EST 2010
On 11/07/2010 02:07 AM, Russell L. Carter wrote:
>
> Hi there,
> Happy cmake user here. I want to retrieve the leaf name of
> the directory property "PARENT_DIRECTORY". This is really
> a more general cmake question: how do I most efficiently
> manipulate path components of the absolute pathnames that
> cmake uses and returns for many variables?
>
> In the current case, suppose I have
>
> "/home/me/project/src/module/help"
>
> how do I, in the best CMAKE WAY, extract the leaf, "help"?
>
> string(REGEXP) or something like that?
>
> I would love to be able to run a bash script on the full
> path and return just the leaf... can I do that?
You might try STRING(REGEX REPLACE "^.*/([^/]*)\$" "\\1" LEAF ${PATH}),
but also read about FILE(TO_CMAKE_PATH ...), FILE(TO_NATIVE_PATH ...)
and GET_FILENAME_COMPONENT().
Regards,
Michael
PS: Please don't start a new thread by replying to another one.
More information about the CMake
mailing list