find_package(
  Python
  3.10
  REQUIRED
  COMPONENTS
    Interpreter
    Development.Module
    ${SKBUILD_SABI_COMPONENT}
)

find_package(nanobind CONFIG REQUIRED)
message(STATUS "Using nanobind: ${nanobind_DIR} (version ${nanobind_VERSION})")

nanobind_add_module(_core
  STABLE_ABI  # Perform a stable ABI build
  NB_STATIC  # Compile the core nanobind library as a static library
  LTO  # Perform link time optimization
  NOMINSIZE  # Don’t perform optimizations to minimize binary size
  bindings.cpp
)

target_include_directories(
  _core
  PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(_core PRIVATE pauliengine-objs)

install(TARGETS _core LIBRARY DESTINATION ${PROJECT_NAME})

# generation of Python typing stubs
# NOTE must come after installing the _core target
nanobind_add_stub(_core
  INSTALL_TIME  # Stub generation postponed to the installation phase.
  MODULE pauliengine  # Specifies the name of the module that should be imported.
  OUTPUT "${PROJECT_NAME}/_core.pyi"  # Specifies the name of the stub file that should be written.
  PYTHON_PATH "${PROJECT_NAME}"  # List of search paths - relative to CMAKE_INSTALL_PREFIX - that should be considered when importing the module.
  VERBOSE  # Show status messages generated by stubgen.
  MARKER_FILE "${PROJECT_NAME}/py.typed"  # Automatically generate an empty marker file.~
)