cmake_minimum_required(VERSION 3.20)
project(Continuum VERSION 1.1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    add_compile_options(-O3 -march=native -mavx2 -mfma -ffast-math -Wall -Wextra -pthread)
endif()

include_directories(include)

# 1. Core Engine Library (Includes Safetensors Loader and OpenCL Dynamic Bridge)
add_library(continuum_core STATIC
    src/memory.cpp
    src/orchestrator.cpp
    src/self_healing.cpp
    src/polyhedral.cpp
    src/dataloader.cpp
    src/gpu_bridge.cpp
    src/safetensors.cpp
)
target_link_libraries(continuum_core PUBLIC pthread ${CMAKE_DL_LIBS})

# 2. C++ Verification Harness
add_executable(continuum_test tests/test_continuum.cpp)
target_link_libraries(continuum_test PRIVATE continuum_core)

# 3. Python AI Layer Bindings
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

# Dynamically extract the exact PyBind11 include path directly from Python
execute_process(
    COMMAND ${Python3_EXECUTABLE} -c "import pybind11; print(pybind11.get_include())"
    OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

add_library(continuum_py MODULE src/python_bindings.cpp)

# Link the Python module directly to the Continuum Core Engine
target_link_libraries(continuum_py PRIVATE continuum_core)

# Explicitly inject the raw header paths
target_include_directories(continuum_py PRIVATE 
    ${Python3_INCLUDE_DIRS} 
    ${PYBIND11_INCLUDE_DIR} 
    include
)

# Strip the "lib" prefix to create a native Python module
set_target_properties(continuum_py PROPERTIES PREFIX "" SUFFIX ".so")