CMakeUserUseFlex: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Add explicit preformat markup)
(Remove leading space rectangles from preformatted blocks)
Line 2: Line 2:


<pre>
<pre>
# - Look for GNU flex, the lexer generator.
# - Look for GNU flex, the lexer generator.
# Defines the following:
# Defines the following:
#  FLEX_EXECUTABLE - path to the flex executable
#  FLEX_EXECUTABLE - path to the flex executable
#  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.  
 
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)
  MESSAGE(STATUS "Looking for flex")
  MESSAGE(STATUS "Looking for flex")
  FIND_PROGRAM(FLEX_EXECUTABLE flex)
  FIND_PROGRAM(FLEX_EXECUTABLE flex)
  IF(FLEX_EXECUTABLE)
  IF(FLEX_EXECUTABLE)
    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("${PATH}" STREQUAL "")
    IF("${PATH}" STREQUAL "")
      SET(PATH_OPT "")
      SET(PATH_OPT "")
    ELSE("${PATH}" STREQUAL "")
    ELSE("${PATH}" STREQUAL "")
      SET(PATH_OPT "/${PATH}")
      SET(PATH_OPT "/${PATH}")
    ENDIF("${PATH}" STREQUAL "")
    ENDIF("${PATH}" STREQUAL "")
    IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
    IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
      FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
      FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
    ENDIF(NOT EXISTS "${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)
    ELSE(FLEX_PREFIX_OUTPUTS)
    ELSE(FLEX_PREFIX_OUTPUTS)
      SET(PREFIX "yy")
      SET(PREFIX "yy")
    ENDIF(FLEX_PREFIX_OUTPUTS)
    ENDIF(FLEX_PREFIX_OUTPUTS)
    SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
    SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
    ADD_CUSTOM_COMMAND(
    ADD_CUSTOM_COMMAND(
      OUTPUT "${OUTFILE}"
      OUTPUT "${OUTFILE}"
      COMMAND "${FLEX_EXECUTABLE}"
      COMMAND "${FLEX_EXECUTABLE}"
      ARGS "--prefix=${PREFIX}"
      ARGS "--prefix=${PREFIX}"
      "--outfile=${OUTFILE}"
      "--outfile=${OUTFILE}"
      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
      "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
      DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
    SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
  ENDMACRO(FLEX_FILE)
  ENDMACRO(FLEX_FILE)
ENDIF(FLEX_EXECUTABLE)
ENDIF(FLEX_EXECUTABLE)
</pre>
</pre>


{{CMake/Template/Footer}}
{{CMake/Template/Footer}}
[[Category:CMakeMacro]]
[[Category:CMakeMacro]]

Revision as of 21:04, 20 April 2018

You are now on the CMake wiki.
Many pages are now DEPRECATED and sometimes even considered bad practice. Those are only kept as reference for previous CMake versions.
The documentations for the latest versions are available here : CMake Documentation.


# - 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. 

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]