build(antlr): 引入第三方 ANTLR4 runtime/tool 并接入构建
This commit is contained in:
@@ -24,6 +24,8 @@ target_include_directories(build_options INTERFACE
|
||||
"${PROJECT_SOURCE_DIR}/include"
|
||||
"${PROJECT_SOURCE_DIR}/src"
|
||||
"${ANTLR4_GENERATED_DIR}"
|
||||
# 兼容未使用 -Xexact-output-dir 时 ANTLR 可能生成到的子目录结构
|
||||
"${ANTLR4_GENERATED_DIR}/src/antlr4"
|
||||
)
|
||||
|
||||
option(COMPILER_ENABLE_WARNINGS "Enable common compiler warnings" ON)
|
||||
@@ -35,22 +37,41 @@ if(COMPILER_ENABLE_WARNINGS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# 尝试查找系统 ANTLR4 runtime;找不到则提供占位 target,便于先配置工程
|
||||
find_package(antlr4-runtime CONFIG QUIET)
|
||||
# 使用仓库内 third_party 提供的 ANTLR4 C++ runtime(较新版本)
|
||||
# third_party 目录结构以仓库为准:runtime 源码位于 third_party/antlr4-runtime-4.13.2/runtime/src
|
||||
set(ANTLR4_RUNTIME_SRC_DIR "${PROJECT_SOURCE_DIR}/third_party/antlr4-runtime-4.13.2/runtime/src")
|
||||
|
||||
set(ANTLR4_RUNTIME_TARGET "")
|
||||
if(TARGET antlr4_shared)
|
||||
set(ANTLR4_RUNTIME_TARGET antlr4_shared)
|
||||
elseif(TARGET antlr4_static)
|
||||
set(ANTLR4_RUNTIME_TARGET antlr4_static)
|
||||
elseif(TARGET antlr4-runtime)
|
||||
set(ANTLR4_RUNTIME_TARGET antlr4-runtime)
|
||||
endif()
|
||||
add_library(antlr4_runtime STATIC)
|
||||
target_compile_features(antlr4_runtime PUBLIC cxx_std_17)
|
||||
|
||||
if(ANTLR4_RUNTIME_TARGET STREQUAL "")
|
||||
add_library(antlr4_runtime_fallback INTERFACE)
|
||||
set(ANTLR4_RUNTIME_TARGET antlr4_runtime_fallback)
|
||||
message(STATUS "antlr4-runtime 未找到:将以占位 target 配置工程;需要 ANTLR 功能时请安装/引入 antlr4-runtime。")
|
||||
endif()
|
||||
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"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/atn/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/dfa/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/internal/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/misc/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/support/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/tree/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/tree/pattern/*.cpp"
|
||||
"${ANTLR4_RUNTIME_SRC_DIR}/tree/xpath/*.cpp"
|
||||
)
|
||||
target_sources(antlr4_runtime PRIVATE ${ANTLR4_RUNTIME_SOURCES})
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(antlr4_runtime PUBLIC Threads::Threads)
|
||||
|
||||
set(ANTLR4_RUNTIME_TARGET antlr4_runtime)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
Reference in New Issue
Block a user