[CMake] STRING(REPLACE <match_expression> bugged?

Brandon J. Van Every bvanevery at gmail.com
Sun Jun 11 22:48:33 EDT 2006


The CMake 2.4.2 docs specify:

STRING(REPLACE <match_expression>
<replace_expression> <output variable>
<input> [<input>...])

<match_expression> is not defined elsewhere in the document.  I presume 
it is somehow different than a <regular_expression>.  It appears that a 
<match_expression> of "@VARIABLE_NAME@" will not match anything in a 
file.  Is this expected behavior or a bug?  If it's expected behavior, 
it should be documented.


Cheers,
Brandon Van Every


My replacement script:

FILE(READ ${Chicken_SOURCE_DIR}/chicken-defaults.h.in input)
MESSAGE("${input}")
STRING(REPLACE "@INSTALL_HOME@" "${INSTALL_HOME}" input "${input}")
STRING(REPLACE "@INSTALL_LIB_HOME@" "${INSTALL_LIB_HOME}" input "${input}")
STRING(REPLACE "@DEFAULT_TARGET_STACK_SIZE@" 
"${DEFAULT_TARGET_STACK_SIZE}" input "${input}")
STRING(REPLACE "@CMAKE_C_COMPILER@" "${CMAKE_C_COMPILER}" input "${input}")
STRING(REPLACE "@STACK_GROWS_DOWNWARD@" "${STACK_GROWS_DOWNWARD}" input 
"${input}")
STRING(REPLACE "@INSTALL_BIN_HOME@" "${INSTALL_BIN_HOME}" input "${input}")
STRING(REPLACE "INSTALL_BIN_HOME" "PROOF_OF_BOGOSITY" input "${input}")
MESSAGE("${input}")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/chicken-defaults.h "${input}")


The contents of chicken-defaults.h after processing:

/*** Program generated file: any edits may be lost ***/
#ifndef C_INSTALL_HOME
# define C_INSTALL_HOME @INSTALL_HOME@
#endif
#ifndef C_PROOF_OF_BOGOSITY
#define C_PROOF_OF_BOGOSITY @PROOF_OF_BOGOSITY@
#endif
#ifndef C_INSTALL_LIB_HOME
# define C_INSTALL_LIB_HOME @INSTALL_LIB_HOME@
#endif
#ifndef C_DEFAULT_TARGET_STACK_SIZE
# define C_DEFAULT_TARGET_STACK_SIZE @DEFAULT_TARGET_STACK_SIZE@
#endif
#ifndef C_CC
#define C_CC @CMAKE_C_COMPILER@
#endif
#ifndef C_STACK_GROWS_DOWNWARD
# define C_STACK_GROWS_DOWNWARD @STACK_GROWS_DOWNWARD@
#endif


More information about the CMake mailing list