Brandon J. Van Every wrote:
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.

Lacking arguments, I also had to pass variables via a file and then INCLUDE it. My final solution uses 3 files: CMakeLists.txt, scm_vars.cmake.in, and scm_regex.cmake.


CMakeLists.txt:
---------------

MACRO(GEN_CSC_SCM)
CONFIGURE_FILE(${Chicken_SOURCE_DIR}/csc_vars.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/csc_vars.cmake)
  ADD_CUSTOM_COMMAND(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/csc.scm
    MAIN_DEPENDENCY ${Chicken_SOURCE_DIR}/csc.scm.in
    DEPENDS
      ${CMAKE_CURRENT_BINARY_DIR}/csc_vars.cmake
      ${Chicken_SOURCE_DIR}/csc_regex.cmake
    COMMAND ${CMAKE_COMMAND} -P ${Chicken_SOURCE_DIR}/csc_regex.cmake
  )
ENDMACRO(GEN_CSC_SCM)


csc_vars.cmake.in:
------------------

SET(Chicken_SOURCE_DIR ${Chicken_SOURCE_DIR})
SET(CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# SET whatever specific vars are needed


csc_regex.cmake:
----------------

INCLUDE(${CMAKE_SOURCE_DIR}/csc_vars.cmake)

# Now we have some of the usual variables we're expecting to have.

MESSAGE(STATUS "Regexing ${Chicken_SOURCE_DIR}/csc.scm.in to ${CMAKE_CURRENT_BINARY_DIR}/csc.scm")
FILE(READ ${Chicken_SOURCE_DIR}/csc.scm.in input)
# Do the regex here
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/csc.scm "${input}")



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





_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to