aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/antlr.cmake
blob: d203fd9c88587a79b28904bb03a802e0a7e0b64f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function(ensure_antlr)
    if(NOT ANTLR3_EXECUTABLE)
        find_program(ANTLR3_EXECUTABLE
                     NAMES antlr3)
        if (NOT ANTLR3_EXECUTABLE)
            message(FATAL_ERROR "Unable to find antlr3 program. Please install antlr3 and make sure executable file present in the $PATH env.")
        endif()
    endif()
endfunction()

function(run_antlr)
    ensure_antlr()
    set(options "")
    set(oneValueArgs WORKING_DIRECTORY)
    set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
    cmake_parse_arguments(
        RUN_ANTLR
         "${options}"
         "${oneValueArgs}"
         "${multiValueArgs}"
         ${ARGN}
    )

    add_custom_command(
        OUTPUT ${RUN_ANTLR_OUTPUT}
        COMMAND ${ANTLR3_EXECUTABLE} ${RUN_ANTLR_ANTLER_ARGS}
        WORKING_DIRECTORY ${RUN_ANTLR_WORKING_DIRECTORY}
        DEPENDS ${RUN_ANTLR_DEPENDS}
    )

endfunction()