set(PYBIND11_FINDPYTHON ON)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 REQUIRED)

pybind11_add_module(_nabla_core bindings.cpp)

target_link_libraries(_nabla_core PRIVATE nabla_core)

# Static-link the C++ runtime so the .pyd is self-contained (MinGW)
if(MINGW)
    target_link_options(_nabla_core PRIVATE -static-libgcc -static-libstdc++)
endif()

target_include_directories(_nabla_core PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)

# Place the built module into python/nabla_quant/ so it's importable (local dev)
set_target_properties(_nabla_core PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/python/nabla_quant"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/python/nabla_quant"
)

# MSVC: also handle per-config output dirs (Debug/Release)
foreach(config IN ITEMS DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
    string(TOUPPER ${config} config_upper)
    set_target_properties(_nabla_core PROPERTIES
        LIBRARY_OUTPUT_DIRECTORY_${config_upper} "${CMAKE_SOURCE_DIR}/python/nabla_quant"
        RUNTIME_OUTPUT_DIRECTORY_${config_upper} "${CMAKE_SOURCE_DIR}/python/nabla_quant"
    )
endforeach()

# Install rule for scikit-build-core: puts the compiled extension into the wheel
install(TARGETS _nabla_core DESTINATION nabla_quant)

