# The extension module posco._native (nanobind). Built by scikit-build-core from pyproject.toml;
# docs/development/building.md. The Python package itself is python/posco.
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module)
execute_process(
  COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
  OUTPUT_STRIP_TRAILING_WHITESPACE
  OUTPUT_VARIABLE nanobind_ROOT
  COMMAND_ERROR_IS_FATAL ANY)
find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(_native NB_STATIC src/module.cpp)
# nanobind and the Python headers are third-party: no first-party warnings for them.
set_target_properties(nanobind-static PROPERTIES SYSTEM ON)
get_target_property(_posco_nb_includes nanobind-static INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(_native SYSTEM PRIVATE ${_posco_nb_includes} ${Python_INCLUDE_DIRS})
target_link_libraries(_native PRIVATE posco::core)
posco_target_warnings(_native)
install(TARGETS _native LIBRARY DESTINATION posco COMPONENT python)

# Type stub of the extension, generated from the built module.
nanobind_add_stub(_native_stub
  MODULE _native
  OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_native.pyi"
  PYTHON_PATH "$<TARGET_FILE_DIR:_native>"
  DEPENDS _native)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_native.pyi" DESTINATION posco COMPONENT python)
