|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +####################################################### |
| 19 | +# Enhanced version of find ANTLR. |
| 20 | +# |
| 21 | +# Usage: |
| 22 | +# find_antlr(${USE_ANTLR}) |
| 23 | +# |
| 24 | +# - When USE_ANTLR=ON, use auto search by first trying to find antlr4 program, |
| 25 | +# then trying to find antlr-*-complete.jar |
| 26 | +# - When USE_ANTLR=/path/to/antlr-*-complete.jar, use provided jar |
| 27 | +# |
| 28 | +# Provide variables: |
| 29 | +# - ANTLR4 |
| 30 | +# |
| 31 | +macro(find_antlr use_antlr) |
| 32 | + set(JAVA_HOME $ENV{JAVA_HOME}) |
| 33 | + if (NOT DEFINED JAVA_HOME) |
| 34 | + # Hack to get system to search for Java itself. |
| 35 | + message(STATUS "JAVA_HOME is not defined. Set it to ensure proper use") |
| 36 | + set(JAVA_HOME "/usr") |
| 37 | + endif() |
| 38 | + if(MSVC) |
| 39 | + set(JAVA_PROGRAM ${JAVA_HOME}/java.exe) |
| 40 | + else() |
| 41 | + set(JAVA_PROGRAM ${JAVA_HOME}/bin/java) |
| 42 | + endif() |
| 43 | + message(STATUS "Using Java at " ${JAVA_PROGRAM}) |
| 44 | + |
| 45 | + if (${use_antlr} STREQUAL "ON") |
| 46 | + find_program(ANTLR4 antlr4) |
| 47 | + if (NOT ANTLR4) |
| 48 | + file(GLOB_RECURSE ANTLR4JAR |
| 49 | + /usr/local/lib/antlr-*-complete.jar |
| 50 | + /usr/local/Cellar/*antlr-*-complete.jar) |
| 51 | + |
| 52 | + # Get the first element of the list of antlr jars. |
| 53 | + # Sort and reverse the list so the item selected is the highest |
| 54 | + # version in lib or else in Cellar if no lib installation exists. |
| 55 | + list(SORT ANTLR4JAR) |
| 56 | + list(REVERSE ANTLR4JAR) |
| 57 | + list(GET ANTLR4JAR 0 ANTLR4JAR) |
| 58 | + |
| 59 | + set(ANTLR4 ${JAVA_PROGRAM} -jar ${ANTLR4JAR}) |
| 60 | + endif() |
| 61 | + elseif(NOT ${use_antlr} STREQUAL "OFF") |
| 62 | + set(ANTLR4 ${JAVA_PROGRAM} -jar ${use_antlr}) |
| 63 | + endif() |
| 64 | + message(STATUS "ANTLR4="${ANTLR4}) |
| 65 | +endmacro(find_antlr) |
0 commit comments