[CMake] STRING(CONFIGURE ...) problem with too-early variable substitution

Brad King brad.king at kitware.com
Sat Jan 14 10:10:05 EST 2006


Zachary Pincus wrote:
> Hi again folks,
> 
> I'm trying to use the CMake STRING(CONFIGURE ...) command.
> For reference, this should 'configure' a string the way that  
> CONFIGURE_FILE does to a file.
> 
> The general gist of what I want to do is something like
> 
> SET(to_configure "/path/to/@directory@")
> 
> and then in a macro:
> SET(directory "frob")
> STRING(CONFIGURE to_configure configured @ONLY)
> 
> to get the result that ${configured} contains "/path/to/frob".
> 
> Of course, this doesn't work, because CMake tries to substitute the  
> variable @directory@ right when to_configure is set!
> 
> Is there any good way to get the literal '@...@' or '$ {...}' (excluding 
> the quotes) into a CMake variable? If not, what use  is STRING(CONFIGURE 
> ...)?
> 
> I tried using SET(to_configure '@...@') which is the shell-style way  of 
> preventing variable substitution, but that didn't work at all. Not  
> using quotes at all is a problem in cases when there need to be  spaces 
> in the string, and I'm not sure it would work in any case.
> 
> Right now, I work around this issue by using STRING(REPLACE ...)  
> instead, but I do wonder what the right way to use STRING (CONFIGURE 
> ...) is?

You have to escape the @ symbols with a backslash:

   SET(to_configure "/path/to/\@directory\@")

-Brad


More information about the CMake mailing list