cmake_minimum_required(VERSION 3.11.0)

include(FetchContent)

if(NOT PYTHON_EXECUTABLE AND PYBIND11_PYTHON_VERSION)
    # venv version is prioritized (instead of PYBIND11_PYTHON_VERSION) if PYTHON_EXECUTABLE is not set.
    # See https://pybind11.readthedocs.io/en/stable/changelog.html#v2-6-0-oct-21-2020
    if((${CMAKE_VERSION} VERSION_LESS "3.22.0") AND (NOT WIN32))
        find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED)
        set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
    else()
        find_package(Python3 ${PYBIND11_PYTHON_VERSION} REQUIRED EXACT COMPONENTS Interpreter Development)
        set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
    endif()
endif()

FetchContent_Declare(
    pybind11
    GIT_REPOSITORY https://github.com/pybind/pybind11.git
    GIT_TAG 80dc998efced8ceb2be59756668a7e90e8bef917 # Version 2.10.1
    #GIT_SHALLOW TRUE
    SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/pybind11"
    BINARY_DIR "${CMAKE_CURRENT_LIST_DIR}/pybind11"
)

if(NOT HAILO_OFFLINE_COMPILATION)
    # https://stackoverflow.com/questions/65527126/disable-install-for-fetchcontent
    FetchContent_GetProperties(pybind11)
    if(NOT pybind11_POPULATED)
        FetchContent_Populate(pybind11)
        add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR} EXCLUDE_FROM_ALL)
    endif()
else()
    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/pybind11 EXCLUDE_FROM_ALL)
endif()