CMakeUserUseFlex: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Created)
 
(Allow .l file to be in top directory.)
Line 4: Line 4:
  #  FLEX_FILE - parse a file with flex
  #  FLEX_FILE - parse a file with flex
  #  FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
  #  FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
  #                        lex.${filename}.c, not lex.yy.c . Passes -P to flex.
  #                        lex.${filename}.c, not lex.yy.c . Passes -P to flex.  
MESSAGE(STATUS "In flex")
   
   
  IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
  IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
   SET(FLEX_PREFIX_OUTPUTS FALSE)
   SET(FLEX_PREFIX_OUTPUTS FALSE)
  ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
  ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS)  
   
   
  IF(NOT FLEX_EXECUTABLE)
  IF(NOT FLEX_EXECUTABLE)
Line 16: Line 18:
     MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
     MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
   ENDIF(FLEX_EXECUTABLE)
   ENDIF(FLEX_EXECUTABLE)
  ENDIF(NOT FLEX_EXECUTABLE)
  ENDIF(NOT FLEX_EXECUTABLE)  
   
   
  IF(FLEX_EXECUTABLE)
  IF(FLEX_EXECUTABLE)
   MACRO(FLEX_FILE FILENAME)
   MACRO(FLEX_FILE FILENAME)
     GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
     GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
     IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PATH}")
    IF("${PATH}" STREQUAL "")
       FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PATH}")
      SET(PATH_OPT "")
     ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${PATH}")
    ELSE("${PATH}" STREQUAL "")
      SET(PATH_OPT "/${PATH}")
    ENDIF("${PATH}" STREQUAL "")
     IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
       FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
     ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
     IF(FLEX_PREFIX_OUTPUTS)
     IF(FLEX_PREFIX_OUTPUTS)
       GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
       GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
Line 29: Line 36:
       SET(PREFIX "yy")
       SET(PREFIX "yy")
     ENDIF(FLEX_PREFIX_OUTPUTS)
     ENDIF(FLEX_PREFIX_OUTPUTS)
     SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}/${PATH}/lex.${PREFIX}.c")
     SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
     ADD_CUSTOM_COMMAND(
     ADD_CUSTOM_COMMAND(
       OUTPUT "${OUTFILE}"
       OUTPUT "${OUTFILE}"

Revision as of 04:16, 19 February 2009

# - Look for GNU flex, the lexer generator.
# Defines the following:
#  FLEX_EXECUTABLE - path to the flex executable
#  FLEX_FILE - parse a file with flex
#  FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
#                        lex.${filename}.c, not lex.yy.c . Passes -P to flex. 

MESSAGE(STATUS "In flex")

IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
  SET(FLEX_PREFIX_OUTPUTS FALSE)
ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS) 

IF(NOT FLEX_EXECUTABLE)
  MESSAGE(STATUS "Looking for flex")
  FIND_PROGRAM(FLEX_EXECUTABLE flex)
  IF(FLEX_EXECUTABLE)
    MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
  ENDIF(FLEX_EXECUTABLE)
ENDIF(NOT FLEX_EXECUTABLE) 

IF(FLEX_EXECUTABLE)
  MACRO(FLEX_FILE FILENAME)
    GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
    IF("${PATH}" STREQUAL "")
      SET(PATH_OPT "")
    ELSE("${PATH}" STREQUAL "")
      SET(PATH_OPT "/${PATH}")
    ENDIF("${PATH}" STREQUAL "")
    IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
      FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
    ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
    IF(FLEX_PREFIX_OUTPUTS)
      GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
    ELSE(FLEX_PREFIX_OUTPUTS)
      SET(PREFIX "yy")
    ENDIF(FLEX_PREFIX_OUTPUTS)
    SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
    ADD_CUSTOM_COMMAND(
      OUTPUT "${OUTFILE}"
      COMMAND "${FLEX_EXECUTABLE}"
      ARGS "--prefix=${PREFIX}"
      "--outfile=${OUTFILE}"
      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
  ENDMACRO(FLEX_FILE)
ENDIF(FLEX_EXECUTABLE)



CMake: [Welcome | Site Map]