# pybind11 extension module. Only configured when SCAVENGER_BUILD_PYTHON_BINDINGS
# is ON (see root CMakeLists.txt) - i.e. when building via `pip install`, not a
# plain C++-only `cmake --build`.

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)

# Named with a leading underscore: this is the compiled implementation detail
# behind the public `siliconscavenger` Python package (src/siliconscavenger),
# not something users are meant to `import` directly.
pybind11_add_module(_scavenger_core MODULE pybind_module.cpp)
target_link_libraries(_scavenger_core PRIVATE scavenger_core)

# docs/FUTURE_DIRECTION.md Phase O0: when ON (see root CMakeLists.txt for
# the SCAVENGER_BUILD_BACKENDS + SCAVENGER_BUILD_PYTHON_BINDINGS
# precondition it enforces), pybind_module.cpp's `#ifdef
# SCAVENGER_BUILD_PYTHON_REAL` branch compiles in, giving PyScheduler a
# real-backend construction path alongside its default MockBackend one.
# scavenger_core itself already contains OpenVinoBackend/LlamaVulkanBackend
# whenever SCAVENGER_BUILD_BACKENDS is ON (see
# core/src/backends/CMakeLists.txt) - this define only controls whether
# *this* translation unit actually uses them.
if(SCAVENGER_BUILD_PYTHON_REAL)
    target_compile_definitions(_scavenger_core PRIVATE SCAVENGER_BUILD_PYTHON_REAL)
endif()

# ${SKBUILD_PROJECT_NAME} is set by scikit-build-core to the [project.name] in
# pyproject.toml ("siliconscavenger"); falls back to a literal for a plain
# `cmake --build` done outside of a pip install.
if(DEFINED SKBUILD_PROJECT_NAME)
    install(TARGETS _scavenger_core DESTINATION ${SKBUILD_PROJECT_NAME})
else()
    install(TARGETS _scavenger_core DESTINATION siliconscavenger)
endif()
