# Python bindings for cuframes — pybind11 module.
#
# Buildup: используется как subdirectory из root CMakeLists.txt при
# BUILD_PYTHON_BINDINGS=ON, либо standalone через scikit-build-core
# (см. pyproject.toml).
#
# Output: единый shared module `_native.so` который импортируется из
# Python package `cuframes` (cuframes/__init__.py re-export'ит публичный API).

include(FetchContent)

# pybind11 — header-only + helper functions. FetchContent чтобы не требовать
# system install; pinned tag для воспроизводимых билдов.
FetchContent_Declare(
    pybind11
    GIT_REPOSITORY https://github.com/pybind/pybind11.git
    GIT_TAG v2.13.6
    GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(pybind11)

pybind11_add_module(_native MODULE
    src/_native.cpp
)

target_include_directories(_native PRIVATE
    ${PROJECT_SOURCE_DIR}/include
)

target_link_libraries(_native PRIVATE
    cuframes  # imported target из libcuframes/CMakeLists.txt
)

# Версия модуля соответствует libcuframes (см. cuframes.h)
target_compile_definitions(_native PRIVATE
    CUFRAMES_PY_BINDING_VERSION="${PROJECT_VERSION}"
)

set_target_properties(_native PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
    CXX_VISIBILITY_PRESET hidden
    INTERPROCEDURAL_OPTIMIZATION TRUE
)

# При scikit-build-core билде модуль попадает в wheel рядом с Python-исходниками
# пакета. При standalone CMake — устанавливается в site-packages по умолчанию.
if(SKBUILD)
    install(TARGETS _native DESTINATION cuframes)
else()
    install(TARGETS _native LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/cuframes)
endif()
