Refactor CMakeLists.txt

This allows ANTLR to be compiled locally instead of globally. This
prevents bugs when emscripten is/isn't used.
This commit is contained in:
ArthurSonzogni
2020-12-20 23:12:31 +01:00
parent ffbf4a7093
commit aff3e0864d
8 changed files with 185 additions and 197 deletions
+63
View File
@@ -0,0 +1,63 @@
set(DIAGON_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "")
# ┌─────────────────────────────────────────────────┐
# │ ANTLR │
# └─────────────────────────────────────────────────┘
execute_process(
COMMAND bash download_and_patch.sh
WORKING_DIRECTORY ${DIAGON_TOOLS_DIR}
)
FetchContent_Declare(antlr
GIT_REPOSITORY https://github.com/antlr/antlr4
GIT_TAG 4.8)
FetchContent_GetProperties(antlr)
if(NOT json_POPULATED)
FetchContent_Populate(antlr)
SET(WITH_LIBCXX OFF CACHE BOOL "")
add_subdirectory(
${antlr_SOURCE_DIR}/runtime/Cpp
${antlr_BINARY_DIR}
EXCLUDE_FROM_ALL)
target_include_directories(antlr4_static
PUBLIC ${antlr_SOURCE_DIR}/runtime/Cpp/runtime/src
)
endif()
# Function
# ANTLR(<file.g4>)
#
# Description:
# Take an ANTLR file and produce a CMake rule to generate the corresponding
# C++ files.
#
# Notes:
# The ANTLR file path must be relative to ${CMAKE_CURRENT_SOURCE_DIR}
#
# Example:
# ANTLR(Grammar.g4)
function(ANTLR source)
get_filename_component(source_filename ${CMAKE_CURRENT_SOURCE_DIR}/${source} NAME_WE)
get_filename_component(source_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/${source} DIRECTORY)
get_filename_component(source_gen_dir ${CMAKE_CURRENT_BINARY_DIR}/${source} DIRECTORY)
add_custom_command(
OUTPUT
${source_gen_dir}/${source_filename}Lexer.cpp
${source_gen_dir}/${source_filename}Parser.cpp
${source_gen_dir}/${source_filename}Lexer.h
${source_gen_dir}/${source_filename}Parser.h
COMMAND
java
ARGS
-jar ${DIAGON_TOOLS_DIR}/antlr.jar
-Dlanguage=Cpp
-no-listener
-no-visitor
-o ${source_gen_dir}
${source_src_dir}/${source_filename}.g4
MAIN_DEPENDENCY
${source_src_dir}/${source_filename}.g4
)
endfunction()
-15
View File
@@ -1,15 +0,0 @@
cd "$(dirname "$0")"
top=$(pwd)
if [ -d cpp_runtime ]
then
exit
fi
mkdir -p cpp_runtime
## Download the ANTLR executable.
curl http://www.antlr.org/download/antlr-4.8-complete.jar -L -o antlr.jar
## Download the C++ runtime.
git clone --depth 1 https://github.com/antlr/antlr4 -b 4.8
+9
View File
@@ -0,0 +1,9 @@
cd "$(dirname "$0")"
top=$(pwd)
if [[ -f "antlr.jar" ]]
then
exit
else
curl http://www.antlr.org/download/antlr-4.8-complete.jar -L -o antlr.jar
fi