[CMake] string replacement without external commands help (ex.
sed)
Dizzy
dizzy at roedu.net
Tue Aug 21 11:30:56 EDT 2007
On Tuesday 21 August 2007 18:22:25 Alexander Neundorf wrote:
> On Tuesday 21 August 2007 11:10, Dizzy wrote:
> > Hello
> >
> > Short version:
> > Is there some built-in support in cmake for string replacement in files
> > (ie to generate a file from another by replacing a given string with
> > another, similar to configure_file() but more general) and could this
> > string replacement operation be used as a "command" for
> > add_custom_command() ?
>
> You can read a file using FILE (READ) and then replace stuff using
> STRING(REPLACE) and STRING(REGEX REPLACE) and write it using FILE(WRITE).
> If you really need to do this from a custom command you have to put these
> commands in an extra cmake script and call this one using ${CMAKE_COMMAND}
> -P <your cmake script>, probably you need to add something like
> -DFILENAME=<your file name> before the -P to set some variables which will
> be needed in the script.
Oh...
> Why do you need this from add_custom_command() ?
So that I have the config file generation like a normal "build" target that
depends on it's input file (ie project.conf is generated from project.conf.in
and is only updated if there is no project.conf or project.conf.in has been
updated in the meantime, just as any other target building dependency). Can I
do it some other way?
> I would suggest using plain configure_file().
I was hoping to have missed something from cmake docs and not require
something complex as FILE read/write and so on. In that case indeeed I would
probably look into using configure_file(), can I use configure_file() from
add_custom_command? (if I need add_custom_command...)
> > Long version:
> > I have recently started to test a cmake based build system for one of my
> > projects. I am interested in cmake mostly because currently we have to
> > deal with autotools for Unices (which even works for exotic ones such as
> > BeOS)
>
> CMake should also work on BeOS (not sure how many active cmake users there
> are).
Yes, I looked portability info up before doing this because one of the
requirements is to not be less portable than it was (well at least on the
platforms we do support and BeOS is one of them). I will be able to get some
feedback on my project building with cmake on BeOS I hope soon and if there
are problems I will report. I also made some cmake modules myself, I will
open a thread separately for those after I finnish getting the project up and
running well with cmake.
Thanks for your help.
--
Mihai RUSU Email: dizzy at roedu.net
"Linux is obsolete" -- AST
More information about the CMake
mailing list