[CMake] FIND sub-command to the STRING command

Tim Hütz tim at huetz.biz
Fri Feb 4 05:00:54 EST 2011


Hey,

mhh, yeah, thats a good idea. Ok, I'll use this for doing a "STRING( FIND ...)" :) It was just an idea to share this patch with you, but you're right. Its easier doing this with regular expressions.

Regards,
Tim

Am 04.02.2011 um 10:56 schrieb Michael Wild:

> On 02/04/2011 10:40 AM, Tim Hütz wrote:
>> Hello,
>> 
>> recently I was searching for a CMake option to get the position of a single character (first appearance) out of a string. As I found nothing which could provide me an easy solution, I pulled the latest development version and added a FIND sub-command to the STRING command. I don't know if this could be helpful for anymore else, hence I attached a patch with this extension to CMake. I'm happy for any comments.
>> 
>> Best regards,
>> Tim
> 
> I normally do it like this:
> 
> set(str "Hello Tim")
> set(pos -1)
> if(str MATCHES "^([^T]*)T")
>  string(LENGTH "${CMAKE_MATCH_1}" pos)
> endif()
> message(STATUS "Position of first T is ${pos}")
> 
> If CMake also supported non-greedy regexes one could also find substrings.
> 
> 
> Michael
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 833 bytes
Desc: Signierter Teil der Nachricht
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110204/7088a9aa/attachment.pgp>


More information about the CMake mailing list