CMakeLists: auto-detect local antlr4 runtime, gitignore local-only files

zhm
zhm 2 weeks ago
parent 87fa235dc1
commit b62d2fcac2

6
.gitignore vendored

@ -64,6 +64,12 @@ cmake-build-release/
.DS_Store
Thumbs.db
# =========================
# Local-only (not for grader)
# =========================
include
third_party/antlr4-runtime-4.13.2/runtime/
# =========================
# Project outputs
# =========================

@ -24,7 +24,6 @@ target_include_directories(build_options INTERFACE
"${PROJECT_SOURCE_DIR}/src/include"
"${PROJECT_SOURCE_DIR}/src"
"${ANTLR4_GENERATED_DIR}"
# 使 -Xexact-output-dir ANTLR
"${ANTLR4_GENERATED_DIR}/src/antlr4"
)
@ -39,11 +38,32 @@ endif()
option(COMPILER_PARSE_ONLY "Build only the frontend parser pipeline" OFF)
# 线antlr4 -lantlr4-runtime
# antlr4
find_package(Threads REQUIRED)
# ANTLR4 -lantlr4-runtime
set(ANTLR4_RUNTIME_TARGET "antlr4-runtime")
set(ANTLR4_RUNTIME_LOCAL_DIR "${PROJECT_SOURCE_DIR}/third_party/antlr4-runtime-4.13.2/runtime/src")
if(EXISTS "${ANTLR4_RUNTIME_LOCAL_DIR}/antlr4-runtime.h")
set(ANTLR4_RUNTIME_SRC_DIR "${ANTLR4_RUNTIME_LOCAL_DIR}")
add_library(antlr4_runtime STATIC)
target_compile_features(antlr4_runtime PUBLIC cxx_std_17)
target_include_directories(antlr4_runtime PUBLIC
"${ANTLR4_RUNTIME_SRC_DIR}"
"${ANTLR4_RUNTIME_SRC_DIR}/atn"
"${ANTLR4_RUNTIME_SRC_DIR}/dfa"
"${ANTLR4_RUNTIME_SRC_DIR}/internal"
"${ANTLR4_RUNTIME_SRC_DIR}/misc"
"${ANTLR4_RUNTIME_SRC_DIR}/support"
"${ANTLR4_RUNTIME_SRC_DIR}/tree"
"${ANTLR4_RUNTIME_SRC_DIR}/tree/pattern"
"${ANTLR4_RUNTIME_SRC_DIR}/tree/xpath"
)
file(GLOB_RECURSE ANTLR4_RUNTIME_SOURCES CONFIGURE_DEPENDS
"${ANTLR4_RUNTIME_SRC_DIR}/*.cpp"
)
target_sources(antlr4_runtime PRIVATE ${ANTLR4_RUNTIME_SOURCES})
target_link_libraries(antlr4_runtime PUBLIC Threads::Threads)
set(ANTLR4_RUNTIME_TARGET antlr4_runtime)
else()
set(ANTLR4_RUNTIME_TARGET "antlr4-runtime")
endif()
add_subdirectory(src)
Loading…
Cancel
Save