from setuptools import find_packages, setup
from setuptools.dist import Distribution
from setuptools import Extension
import platform
import os
import numpy as np

class BinaryDistribution(Distribution):
  def is_pure(self):
    return False
  def has_ext_modules(self):
    return True

from setuptools.command.install import install
class InstallPlatlib(install):
    def finalize_options(self):
        install.finalize_options(self)
        self.install_lib=self.install_platlib

# project prefix
prefix = "aruco"

# add README to long description
with open(os.path.join(prefix, "README.md"), "r", encoding="utf-8") as fh:
    long_description = fh.read()

# compiling
sourcefiles = ['arucoPYTHON_wrap.cxx']
extra_cpp_args = ["-std=c++11", "-Wall", "-O3", "-g0", "-DNDEBUG"]

for i in range(len(sourcefiles)):
    sourcefiles[i] = os.path.join(prefix, sourcefiles[i])

# Compiling on OSX does not work with openmp switch
if platform.system().lower() not in ("darwin", "osx"):
    extra_cpp_args.append("-fopenmp")

aruco_module = Extension('_pyaruco',
                         sources=sourcefiles,
                         language="c++",
                         extra_compile_args=extra_cpp_args,
                         include_dirs=[np.get_include(),
                                       "/usr/local/include/",
                                       "/usr/local/include/opencv4/",
                                       "/usr/include/eigen3/",
                                       "aruco/include"],
                         libraries=["aruco", "opencv_core", "opencv_imgproc", "opencv_calib3d", "opencv_highgui", "opencv_ml"],
                         library_dirs=["/usr/local/lib"])

setup(
  name='aruco',
  version='3.1.12.0',
  author="""ArUco: Rafael Muñoz Salinas, Python wrappers: Marcus Degenkolbe""",
  author_email='marcus@degenkolbe.eu',
  description="""ArUco Python wrappers""",
  license="Copyright 2017 Rafael Muñoz Salinas. All rights reserved.",
  url='https://github.com/fehlfarbe/python-aruco',
  long_description=long_description,
  long_description_content_type='text/markdown',
  keywords='aruco wrapper',
  # distclass=BinaryDistribution,
  cmdclass={'install': InstallPlatlib},
  install_requires=['numpy'],
  ext_modules=[aruco_module],
  packages=find_packages(),
  package_data={
  'aruco':['*'],
  'aruco.aruco':['_pyaruco.so'],
  },
  include_package_data=True,
  options={"build_ext": {"inplace": True}}
)
