cmake_minimum_required(VERSION 3.24)
project(bazi_calendar LANGUAGES CXX)
# Plugin-owned calendar library: vtour loads it through vtour.native from
# bazi-research/calendar.lua. It links the pinned bazi-core snapshot and has
# no vtour, Lua or ImGui dependency. Inside the vtour build the bazi-core and
# nlohmann_json targets already exist; standalone builds point BAZI_CORE_DIR
# at vendor/bazi-core and provide nlohmann_json through find_package.
if(NOT TARGET vtour_bazi_core)
  set(BAZI_CORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/bazi-core" CACHE PATH "bazi-core snapshot")
  file(GLOB_RECURSE _bazi_sources CONFIGURE_DEPENDS "${BAZI_CORE_DIR}/src/*.cpp")
  add_library(vtour_bazi_core STATIC ${_bazi_sources})
  target_compile_features(vtour_bazi_core PUBLIC cxx_std_17)
  target_include_directories(vtour_bazi_core PUBLIC "${BAZI_CORE_DIR}/include" PRIVATE "${BAZI_CORE_DIR}/src")
  set_target_properties(vtour_bazi_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
  if(MSVC)
    target_compile_options(vtour_bazi_core PUBLIC /EHsc PRIVATE /utf-8)
  endif()
endif()
if(NOT TARGET nlohmann_json::nlohmann_json)
  find_package(nlohmann_json 3 REQUIRED)
endif()
add_library(vtour_bazi_calendar SHARED calendar.cpp)
target_compile_features(vtour_bazi_calendar PRIVATE cxx_std_17)
target_link_libraries(vtour_bazi_calendar PRIVATE vtour_bazi_core nlohmann_json::nlohmann_json)
set_target_properties(vtour_bazi_calendar PROPERTIES PREFIX "" OUTPUT_NAME "bazi_calendar"
  CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN YES)
# Tests call the same adapter directly, without the C ABI.
add_library(vtour_bazi_calendar_adapter STATIC calendar.cpp)
target_compile_features(vtour_bazi_calendar_adapter PUBLIC cxx_std_17)
target_compile_definitions(vtour_bazi_calendar_adapter PUBLIC BAZI_CALENDAR_STATIC)
target_include_directories(vtour_bazi_calendar_adapter PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(vtour_bazi_calendar_adapter PUBLIC vtour_bazi_core nlohmann_json::nlohmann_json)
