You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FindRagel.cmake 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # - Find Ragel executable and provides macros to generate custom build rules
  2. # The module defines the following variables:
  3. #
  4. # RAGEL_EXECUTABLE - path to the ragel program
  5. # RAGEL_VERSION - version of ragel
  6. # RAGEL_FOUND - true if the program was found
  7. #
  8. # If ragel is found, the module defines the macros:
  9. #
  10. # RAGEL_TARGET(<Name> INPUTS <inputs> OUTPUT <output>
  11. # [COMPILE_FLAGS <string>] [DEPENDS <depends>])
  12. #
  13. # which will create a custom rule to generate a state machine. <RagelInp> is
  14. # the path to a Ragel file. <CodeOutput> is the name of the source file
  15. # generated by ragel. If COMPILE_FLAGS option is specified, the next
  16. # parameter is added in the ragel command line.
  17. #
  18. # The macro defines a set of variables:
  19. # RAGEL_${Name}_DEFINED - true is the macro ran successfully
  20. # RAGEL_${Name}_INPUT - The input source file, an alias for <RagelInp>
  21. # RAGEL_${Name}_OUTPUT_SOURCE - The source file generated by ragel
  22. # RAGEL_${Name}_OUTPUT_HEADER - The header file generated by ragel
  23. # RAGEL_${Name}_OUTPUTS - The sources files generated by ragel
  24. # RAGEL_${Name}_COMPILE_FLAGS - Options used in the ragel command line
  25. #
  26. # ====================================================================
  27. # Example:
  28. #
  29. # find_package(RAGEL) # or e.g.: find_package(RAGEL 6.6 REQUIRED)
  30. # RAGEL_TARGET(MyMachine machine.rl ${CMAKE_CURRENT_BINARY_DIR}/machine.cc)
  31. # add_executable(Foo main.cc ${RAGEL_MyMachine_OUTPUTS})
  32. # ====================================================================
  33. # 2014-02-09, Georg Sauthoff <mail@georg.so>
  34. #
  35. # I don't think that these few lines are even copyrightable material,
  36. # but I am fine with using the BSD/MIT/GPL license on it ...
  37. #
  38. # I've used following references:
  39. # http://www.cmake.org/cmake/help/v2.8.12/cmake.html
  40. # /usr/share/cmake/Modules/FindFLEX.cmake
  41. # /usr/share/cmake/Modules/FindBISON.cmake
  42. # uses some features which are not available in 2.6
  43. cmake_minimum_required(VERSION 2.8)
  44. find_program(RAGEL_EXECUTABLE NAMES ragel DOC "path to the ragel executable")
  45. mark_as_advanced(RAGEL_EXECUTABLE)
  46. if(RAGEL_EXECUTABLE)
  47. execute_process(COMMAND ${RAGEL_EXECUTABLE} --version
  48. OUTPUT_VARIABLE RAGEL_version_output
  49. ERROR_VARIABLE RAGEL_version_error
  50. RESULT_VARIABLE RAGEL_version_result
  51. OUTPUT_STRIP_TRAILING_WHITESPACE)
  52. if(${RAGEL_version_result} EQUAL 0)
  53. string(REGEX REPLACE "^Ragel State Machine Compiler version ([^ ]+) .*$"
  54. "\\1"
  55. RAGEL_VERSION "${RAGEL_version_output}")
  56. else()
  57. message(SEND_ERROR
  58. "Command \"${RAGEL_EXECUTABLE} --version\" failed with output:
  59. ${RAGEL_version_error}")
  60. endif()
  61. #============================================================
  62. # RAGEL_TARGET (public macro)
  63. #============================================================
  64. #
  65. macro(RAGEL_TARGET Name)
  66. CMAKE_PARSE_ARGUMENTS(RAGEL "" "OUTPUT"
  67. "INPUTS;DEPENDS;COMPILE_FLAGS" ${ARGN})
  68. add_custom_command(OUTPUT ${RAGEL_OUTPUT}
  69. COMMAND ${RAGEL_EXECUTABLE}
  70. ARGS ${RAGEL_COMPILE_FLAGS} -o${RAGEL_OUTPUT} ${RAGEL_INPUTS}
  71. DEPENDS ${RAGEL_INPUTS} ${RAGEL_DEPENDS}
  72. COMMENT
  73. "[RAGEL][${Name}] Compiling state machine with Ragel ${RAGEL_VERSION}"
  74. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  75. set(RAGEL_${Name}_DEFINED TRUE)
  76. set(RAGEL_${Name}_OUTPUTS ${RAGEL_OUTPUT})
  77. set(RAGEL_${Name}_INPUT ${RAGEL_INPUTS})
  78. set(RAGEL_${Name}_COMPILE_FLAGS ${RAGEL_COMPILE_FLAGS})
  79. endmacro()
  80. endif()
  81. # use this include when module file is located under /usr/share/cmake/Modules
  82. #include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  83. # use this include when module file is located in build tree
  84. include(FindPackageHandleStandardArgs)
  85. FIND_PACKAGE_HANDLE_STANDARD_ARGS(RAGEL REQUIRED_VARS RAGEL_EXECUTABLE
  86. VERSION_VAR RAGEL_VERSION)