# Copyright 2025 Digitalwerk GmbH.
#
#     This Source Code Form is subject to the terms of the Mozilla
#     Public License, v. 2.0. If a copy of the MPL was not distributed
#     with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# If it is not possible or desirable to put the notice in a particular file, then
# You may include the notice in a location (such as a LICENSE file in a
# relevant directory) where a recipient would be likely to look for such a notice.
#
# You may add additional accurate notices of copyright ownership.

function(install_module NAME)
    if (WIN32)
        set(original_pythonpath ";$ENV{PYTHONPATH}")
    else ()
        set(original_pythonpath ":$ENV{PYTHONPATH}")
    endif ()
    add_custom_command(TARGET "_${NAME}" POST_BUILD COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$<TARGET_FILE_DIR:_${NAME}>${original_pythonpath}" pybind11-stubgen -o "${CMAKE_CURRENT_BINARY_DIR}" ${ARGN} "_${NAME}"
            COMMENT "Generating doc stubs for ${NAME}")
    install(TARGETS "_${NAME}" DESTINATION ${NAME} COMPONENT "${NAME}_python")
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_${NAME}.pyi" DESTINATION ${NAME} COMPONENT "${NAME}_python")
    install(FILES py.typed __init__.py "${CMAKE_CURRENT_BINARY_DIR}/version.py" DESTINATION ${NAME} COMPONENT "${NAME}_python")

    if (MSVC)
        install(FILES "$<TARGET_PDB_FILE:_${NAME}>" DESTINATION ${NAME}
                CONFIGURATIONS "Debug" "RelWithDebInfo"
                COMPONENT adtf_python
        )
    endif ()
endfunction()

string(MAKE_C_IDENTIFIER "v${BUILD_VERSION}" MODULE_RELEASE_ABI_VERSION)

add_subdirectory(decoder)
add_subdirectory(adtf)
add_subdirectory(adtf_file)
add_subdirectory(adtf_file_python_processor)