[CMake] get_file_name_component - how to return true extension
Brian Davis
bitminer at gmail.com
Wed Nov 25 17:28:39 EST 2009
Yes so I did find the string regexp functions and the following seems to be
working for me.
For example (in case anyone else sees this thread and finds it helpful)
SET( FILE_NAME openssl-0.9.8a.tar.gz )
STRING( REGEX REPLACE "[.]gz" "" FILE_NAME_NO_EXT ${FILE_NAME} )
STRING( REGEX REPLACE "[.]tar" "" FILE_NAME_NO_EXT ${FILE_NAME_NO_EXT} )
MESSAGE( STATUS "File name only is ${FILE_NAME_NO_EXT}" )
Displays the following in the CMake GUI output window
File name only is openssl-0.9.8a
STRING( REGEX REPLACE ".*([.]tar).*" "\\1" TAR_EXT ${FILE_NAME} )
STRING( REGEX REPLACE ".*([.]gz).*" "\\1" GZ_EXT ${FILE_NAME} )
MESSAGE( STATUS "File extension is ${TAR_EXT}" )
MESSAGE( STATUS "File extension is ${GZ_EXT}" )
Outputs:
File extension is .tar
File extension is .gz
So TAR_EXT and GZ_EXT can be tested for and zxvf or xvf can then be used
appropriately amd TAR_OPTS set accordingly.
Thanks,
Brian
On Wed, Nov 25, 2009 at 3:24 PM, Eric Noulard <eric.noulard at gmail.com>wrote:
> 2009/11/25 Brian Davis <bitminer at gmail.com>:
> >
> > for a given file of the form:
> >
> > openssl-0.9.8a.tar.gz
> >
> > I call as an example:
> >
> > get_filename_component( TAR_EXT openssl-0.9.8a.tar.gz EXT )
> >
> > and I get for TAR_EXT
> >
> > .9.1.tar.gz
>
> you should be getting: ".9.8a.tar.gz"
> but I think it's a copy/paste typo
>
> > Which is not quite what I was expecting.
> > I was expecting .gz and with successive calls I would get .tar
> >
> > Is there a mechanism in CMake for getting the trailing extension?
>
> With get_filename_component I don't think so
> but may be you can use some string(xxxx) calls.
> example attached.
>
> --
> Erk
> Membre de l'April - « promouvoir et défendre le logiciel libre » -
> http://www.april.org
>
--
Brian J. Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091125/6d0b9892/attachment.htm>
More information about the CMake
mailing list