Skip to content

Commit

Permalink
Updates to fix Cpp build.
Browse files Browse the repository at this point in the history
* Move code to init npm environment after cd'ing to build.
* Remove code to get version. It doesn't work because Antlr-ng and Antlr4 tools are very different in version strings.
* Remove "-no-listener" because it's useless, but also crashes Antlr-ng.
  • Loading branch information
kaby76 committed Jan 17, 2025
1 parent 004024a commit 724a7a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
24 changes: 1 addition & 23 deletions _scripts/templates/Cpp/cmake/st.FindANTLR.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
find_package(Java QUIET COMPONENTS Runtime)

execute_process(
<if(antlrng_tool)>
COMMAND node node_modules/antlr-ng/dist/cli/runner.js --version
<else>
COMMAND antlr4<if(os_win)>.exe<else><endif> -v ${ANTLR4_TAG}
<endif>
OUTPUT_VARIABLE ANTLR_COMMAND_OUTPUT
ERROR_VARIABLE ANTLR_COMMAND_ERROR
RESULT_VARIABLE ANTLR_COMMAND_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(ANTLR_COMMAND_RESULT EQUAL 0)
string(REGEX MATCH "Version [0-9]+(\\\\.[0-9]+)*" ANTLR_VERSION ${ANTLR_COMMAND_OUTPUT})
string(REPLACE "Version " "" ANTLR_VERSION ${ANTLR_VERSION})
else()
message(
SEND_ERROR
"Command antlr4<if(os_win)>.exe<else><endif> "
"failed with the output '${ANTLR_COMMAND_ERROR}'")
endif()

macro(ANTLR_TARGET Name InputFile)
set(ANTLR_OPTIONS LEXER PARSER LISTENER VISITOR)
set(ANTLR_ONE_VALUE_ARGS PACKAGE OUTPUT_DIRECTORY DEPENDS_ANTLR)
Expand Down Expand Up @@ -108,12 +87,11 @@ find_package(Java QUIET COMPONENTS Runtime)
<endif>
${InputFile}
-o ${ANTLR_${Name}_OUTPUT_DIR}
-no-listener
-Dlanguage=Cpp
${ANTLR_TARGET_COMPILE_FLAGS}
DEPENDS ${InputFile}
${ANTLR_TARGET_DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building ${Name} with ANTLR ${ANTLR_VERSION}")
COMMENT "Building ${Name} with ANTLR")
endmacro(ANTLR_TARGET)

6 changes: 3 additions & 3 deletions _scripts/templates/Cpp/st.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
set -e
if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi
rm -rf node_modules
rm -rf build
mkdir build
cd build
<if(antlrng_tool)>
npm init -y
npm i antlr-ng
<endif>
rm -rf build
mkdir build
cd build
<if(test.IsWindows)>cmake .. -G "Visual Studio 17 2022" -A x64
<else>cmake ..
<endif>
Expand Down

0 comments on commit 724a7a6

Please sign in to comment.