[CMake] Re: macro within a custom command

Brandon J. Van Every bvanevery at gmail.com
Fri May 19 08:00:07 EDT 2006


Brandon J. Van Every wrote:
>
> If there's no way to perform a simple text substitution on a custom 
> build rule's COMMAND line, then that's really really irritating.

I still would like a text substitution macro, but I did find a 
semi-elegant way around being stuck with DEPENDS in ADD_CUSTOM_COMMAND.

# A MACRO cannot be used within the COMMAND line of ADD_CUSTOM_COMMAND!
# This makes it really irritating to do variable substitutions and
# implement abstract rules.  We're also stuck with using DEPENDS to
# specify our dependencies, there's no other way. 
# In CMake 2.4.2, ADD_FILE_DEPENDENCIES will *not* work in
# conjunction with ADD_CUSTOM_COMMAND.  It is meant to be
# used for .o file dependencies on .c files, not for
# source-file-to-source-file dependencies.  We hack around this
# by creating a variable out of a file's name, shoving the
# desired dependencies into this variable, and shoving that into
# DEPENDS.  Sorta like OO, heh, neato!

# Specify DEPLIST(root dep1 dep2 dep3 etc) before calling any of:
#   SIMPLE_SCM_TO_C
#   LIBRARY_SCM_TO_C
#   UNSAFE_LIBRARY_SCM_TO_C
#
# After 'root', list the rootnames of any number of dependencies.
# ${Chicken_BINARY_DIR}/root.c is assumed
# $(Chicken_SOURCE_DIR)/deproots.scm is assumed for all dependencies.
# If these conditions aren't true, you'll need to write out
# a custom rule the long way.

MACRO(DEPLIST root)
  # Put only variable args in deps.
  SET(deproots ${ARGV})
  LIST(REMOVE_ITEM deproots 0)
  ADD_SUFFIX(deproots .scm)
  SET(${root}_deplist ${deproots})
ENDMACRO(DEPLIST)

MACRO(SIMPLE_SCM_TO_C root)
  ADD_CUSTOM_COMMAND(
    OUTPUT ${Chicken_BINARY_DIR}/${root}.c
    MAIN_DEPENDENCY ${root}.scm
    DEPENDS ${${root}_deplist}
    COMMAND ${VALID_CHICKEN} ${Chicken_SOURCE_DIR}/${root}.scm 
-output-file ${Chicken_BINARY_DIR}/${root}.c ${CHICKEN_FLAGS}
  )
ENDMACRO(SIMPLE_SCM_TO_C)


Typical usage:

DEPLIST(chicken build chicken-ffi-macros chicken-more-macros tweaks)
SIMPLE_SCM_TO_C(chicken)


Cheers,
Brandon Van Every





More information about the CMake mailing list