antlr4.cmake 869 B

123456789101112131415161718192021222324252627282930
  1. function(ensure_antlr4)
  2. if(NOT ANTLR4_EXECUTABLE)
  3. find_program(ANTLR4_EXECUTABLE NAMES antlr4)
  4. if (NOT ANTLR4_EXECUTABLE)
  5. message(FATAL_ERROR "Unable to find antlr4 program. Please install antlr4 and make sure executable file present in the $PATH env.")
  6. endif()
  7. endif()
  8. endfunction()
  9. function(run_antlr4)
  10. ensure_antlr4()
  11. set(options "")
  12. set(oneValueArgs WORKING_DIRECTORY)
  13. set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
  14. cmake_parse_arguments(
  15. RUN_ANTLR4
  16. "${options}"
  17. "${oneValueArgs}"
  18. "${multiValueArgs}"
  19. ${ARGN}
  20. )
  21. add_custom_command(
  22. OUTPUT ${RUN_ANTLR4_OUTPUT}
  23. COMMAND ${ANTLR4_EXECUTABLE} ${RUN_ANTLR4_ANTLER_ARGS}
  24. WORKING_DIRECTORY ${RUN_ANTLR4_WORKING_DIRECTORY}
  25. DEPENDS ${RUN_ANTLR4_DEPENDS}
  26. )
  27. endfunction()