cmake_minimum_required(VERSION 3.15)

project(antlr4_runtime_vendor LANGUAGES CXX)

# 仅构建静态库运行时；生成器（antlr jar）不在 CMake 内集成（按仓库约定不提供脚本）。
add_library(antlr4_runtime STATIC)

target_compile_features(antlr4_runtime PUBLIC cxx_std_17)

target_include_directories(antlr4_runtime PUBLIC
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/atn"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/dfa"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/internal"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/misc"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/support"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree/pattern"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree/xpath"
)

file(GLOB_RECURSE ANTLR4_RUNTIME_SOURCES CONFIGURE_DEPENDS
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/atn/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/dfa/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/internal/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/misc/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/support/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree/pattern/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/runtime/src/tree/xpath/*.cpp"
)
target_sources(antlr4_runtime PRIVATE ${ANTLR4_RUNTIME_SOURCES})

# Linux/Unix 下需要 pthread 以保证 std::call_once 等线程相关行为正确
find_package(Threads REQUIRED)
target_link_libraries(antlr4_runtime PUBLIC Threads::Threads)

