#!/usr/bin/python

# ----------------- BEGIN LICENSE BLOCK ---------------------------------
#
# Copyright (c) 2020-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
# ----------------- END LICENSE BLOCK -----------------------------------

"""
This module uses pygccxml and py++ to generate
Python interfaces for all classes and datatypes
of the ad_physics library.

The resulting library is called libad_physics_python
"""

from python_wrapper_helper import generate_python_wrapper, post_process_python_wrapper


def main():
    """
    Main function to generate Python-C++ binding code
    """
    header_dirs = {
        "@CMAKE_CURRENT_LIST_DIR@/../generated/include/",
        "@CMAKE_CURRENT_LIST_DIR@/../include/"
    }
    include_dirs = {
        "@GENPY_INCLUDE_DIRS@"
    }

    generate_python_wrapper(library_name="physics",
                            cpp_filename="Ad-physics-PythonWrapper.cpp.in",
                            header_directories=header_dirs,
                            include_paths=include_dirs,
                            main_namespace="ad::physics",
                            declarations={
                                "ad::physics", "toString", "fromString", "std::to_string", "std::sqrt", "std::fabs", "std::numeric_limits"}
    )

    additional_replacements = {("BOOST_PYTHON_MODULE(physics){",
                                "BOOST_PYTHON_MODULE(ad_physics_@PYTHON_BINDING_NAME@){\n" +
         "  bp::object ad_physics_module(bp::handle<>(bp::borrowed(PyImport_AddModule(\"physics\"))));\n" +
         "  bp::scope().attr(\"physics\") = ad_physics_module;\n" +
         "  bp::scope submodule_scope = ad_physics_module;\n\n" +
         "  bp::scope().attr(\"__doc__\") = \"Python binding of ad_physics ad::physics namespace C++ code for @binding_string@\";\n" +
         "  bp::scope().attr(\"__copyright__\") = \"Copyright (C) 2020-2021 Intel Corporation\";\n" +
         "  bp::scope().attr(\"__license__\") = \"MIT\";\n"
         )
        }
    post_process_python_wrapper(header_directories=header_dirs,
                                cpp_filename_in="Ad-physics-PythonWrapper.cpp.in",
                                cpp_filename_out="Ad-physics-PythonWrapper.cpp",
                                additional_replacements=additional_replacements)

if __name__ == '__main__':
    main()
