Home | History | Annotate | Download | only in modules
      1 # - Try to find Bison
      2 # Once done this will define
      3 #
      4 #  BISON_FOUND - system has Bison
      5 #  BISON_EXECUTABLE - path of the bison executable
      6 #  BISON_VERSION - the version string, like "2.5.31"
      7 #
      8 
      9 MACRO(FIND_BISON)
     10 	FIND_PROGRAM(BISON_EXECUTABLE NAMES bison)
     11 
     12 	IF(BISON_EXECUTABLE)
     13 		SET(BISON_FOUND TRUE)
     14 
     15 		EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version
     16 			OUTPUT_VARIABLE _BISON_VERSION
     17 		)
     18 		string (REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" BISON_VERSION "${_bison_VERSION}")
     19 	ENDIF(BISON_EXECUTABLE)
     20 
     21 	IF(BISON_FOUND)
     22 	  IF(NOT Bison_FIND_QUIETLY)
     23 		MESSAGE(STATUS "Found Bison: ${BISON_EXECUTABLE}")
     24 	  ENDIF(NOT Bison_FIND_QUIETLY)
     25 	ELSE(BISON_FOUND)
     26 	  IF(Bison_FIND_REQUIRED)
     27 		MESSAGE(FATAL_ERROR "Could not find Bison")
     28 	  ENDIF(Bison_FIND_REQUIRED)
     29 	ENDIF(BISON_FOUND)
     30 ENDMACRO(FIND_BISON)
     31 
     32 MACRO(BISON_GENERATOR _PREFIX _Y_INPUT _H_OUTPUT _CPP_OUTPUT)
     33 	IF(BISON_EXECUTABLE)
     34 		GET_FILENAME_COMPONENT(_Y_DIR ${_Y_INPUT} PATH)
     35 		ADD_CUSTOM_COMMAND(
     36 			OUTPUT  ${_CPP_OUTPUT}
     37 			OUTPUT  ${_H_OUTPUT}
     38 			DEPENDS ${_Y_INPUT}
     39 			COMMAND ${BISON_EXECUTABLE}
     40 			ARGS
     41 				-p ${_PREFIX} -o"${_CPP_OUTPUT}"
     42 				--defines="${_H_OUTPUT}" ${_Y_INPUT}
     43 			WORKING_DIRECTORY ${_Y_DIR}
     44 		)
     45 		SET_SOURCE_FILES_PROPERTIES(
     46 			${_CPP_OUTPUT} ${_H_OUTPUT}
     47 			GENERATED
     48 		)
     49 	ELSE(BISON_EXECUTABLE)
     50 		MESSAGE(SEND_ERROR "Can't find bison program, and it's required")
     51 	ENDIF(BISON_EXECUTABLE)
     52 ENDMACRO(BISON_GENERATOR)
     53