diff --git a/.gitignore b/.gitignore index 0f95955b..6f874262 100644 --- a/.gitignore +++ b/.gitignore @@ -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 # ========================= diff --git a/CMakeLists.txt b/CMakeLists.txt index df0a85fc..13c90ff3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file