[CMake] Splitting directory and file.

Michael Wild themiwi at gmail.com
Wed Mar 2 07:51:56 EST 2011


string(REGEX REPLACE "/+$" "" dname "${dname}")

Strips all trailing slashes. But honestly, "man cmake" would have been
way faster and less embarrassing...

HTH

Michael

On 03/02/2011 01:41 PM, Pablo Zurita wrote:
> Yes, that works.
> 
> Now I just need to remove the last character if it is a forward slash.
> How can I do that?
> 
> Thanks,
> Pablo Zurita.
> 
> Sent from my iPhone
> 
> On Mar 2, 2011, at 1:47 AM, Yuri Timenkov <yuri at timenkov.ru
> <mailto:yuri at timenkov.ru>> wrote:
> 
>> Does get_filename_component help?
>>
>> On Wed, Mar 2, 2011 at 6:17 AM, Pablo Zurita
>> <<mailto:pzurita at gmail.com>pzurita at gmail.com
>> <mailto:pzurita at gmail.com>> wrote:
>>
>>     Hello everybody,
>>
>>     I'm just getting started and I need some help dealing with strings in
>>     CMake. Basically what I have a bunch of strings such as the ones
>>     below:
>>
>>     "Main.cpp"
>>     "Window/Example/Example.cpp"
>>     "Window/Window.cpp"
>>
>>     What I need to do is create two strings for each, one is going to be
>>     the directory, so the output in order for the list above is:
>>
>>     ""
>>     "Window/Example"
>>     "Window"
>>
>>     And the other string I need is the file itself. So the output for
>>     that would be
>>
>>     "Main.cpp"
>>     "Example.cpp"
>>     "Window.cpp"
>>
>>     Since I'm processing each one by one it doesn't matter if there
>>     are collisions.
>>
>>     As you can see all I need to is find the first forward slash on the
>>     string reading from right to left, and then put what's on the left of
>>     that string on one variable, and what is to the right in another.
>>
>>     Does anybody know how I can do that?
>>
>>     Thanks,
>>     Pablo Zurita.




More information about the CMake mailing list