[CMake] REGEX for CONFIGURE_FILE

Brandon J. Van Every bvanevery at gmail.com
Thu Jun 8 03:38:34 EDT 2006


I have a file csc.scm.in that I cannot change because 2 other build 
systems depend on it.  It has variables of the form %BLAH_BLAH% that 
need to be substituted.  I can't change them to @BLAH_BLAH@ or 
${BLAH_BLAH}.  I'm not sure if there's a Scheme preprocessor facility I 
could use to get around this; I definitely can't use the usual C 
preprocessor #ifdef tricks as it's all Scheme code.  I don't know that 
polluting the code would go over well anyways.

1 build system simply copies the file from csc.scm.in to csc.scm 
unchanged.  This is the extremely dumb vcbuild.bat system, which is 
meant to run in a tools-poor Windows enviornment.  It's brain dead but 
it works.

The 2nd build system is a ./configure Makefile.am getup.  It performs 
sed substitutions on csc.scm.in to generate csc.scm.  Since it has full 
regex capabilities it doesn't care that the substitution convention is 
%BLAH_BLAH%.  It also worries about escaping quotes in various places.

So now with CMake my options with CONFIGURE_FILE are exceedingly 
limited.  Really I can't do it that way.

I've learned about ${CMAKE_COMMAND} -P scripting.  There are no input 
parameters and no internal variables are retained from the calling 
CMake.  All it "knows" is the directory in which it was called, as 
either ${CMAKE_SOURCE_DIR} or ${CMAKE_BINARY_DIR}.  They're both the 
same thing.  Apparently the CVS version has a -D option that works in 
conjunction with -P, but I need this to work with straight 2.4.2.  I 
tried various permutations of -P -DMYVAR:STRING=myfilename.scm and it 
doesn't work.  So I suppose I'll be copying to some local files and 
using -E copy_if_different as a final step.

It would be a lot cleaner if CONFIGURE_FILE was capable of more 
intelligence.  Doing regex replacements is an exceedingly common 
operation when porting from a ./configure script.  I think potential 
converts will be a lot happier if they can keep their sed equivalents 
inside CMakeLists.txt.


Cheers,
Brandon Van Every



More information about the CMake mailing list