Blame view

src/wrapper_flipro/setup.py 5.41 KB
9b90cb8a   Alain Klotz   compatibility set...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3

from setuptools import Extension, setup
import shutil
import glob
import os
import stat
import numpy

print("="*40 + "\nSetup of the module wrapper_flipro\n" + "="*40)

# ====================================
# === Distribution identification ===
# ====================================
import platform
psystem = platform.system()
if psystem == "Windows":
    distribution = platform.win32_ver()
    distro_name = psystem
    distro_version = distribution[0]
elif psystem == "Darwin":
    distribution = platform.mac_ver()
    distro_name = psystem
    distro_version = distribution[0]
elif psystem == "Linux":
    release = platform.release
    if "microsoft" in release:
        # release = '5.10.16.3-microsoft-standard-WSL2'
        distro_name = release.split("-")[3]
        distro_version = release.split("-")[0]
300eeb29   Alain Klotz   bugfix in setup
31
    else:
9b90cb8a   Alain Klotz   compatibility set...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
        distribution = platform.freedesktop_os_release()
        distro_name = distribution['NAME']
        distro_version = distribution['VERSION_ID']
print(f"\n{distro_name=}")
print(f"\n{distro_version=}")

# ====================================
# === Path and general description ===
# ====================================
from pathlib import Path
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text(encoding="utf-8")
path_external = os.path.join("audela","src","external","flipro")
    
# ===========================================
# === Directory of the manufacturer files ===
# ===========================================
if distro_name == "Windows":
    path_manufacturer = "libflipro-Version-1.12.59-Windows"
elif distro_name == "Ubuntu" or distro_name == "Fedora":
    path_manufacturer = "libflipro-Version-2.0.5-"
    
# =====================================================
# === Copy manufacturer resources (libraires, etc.) ===
# =====================================================
# --- List the resource files
srcs = []
if distro_name == "Windows":
    library_dirs = [os.path.join(path_external, path_manufacturer, "x64")]
    for library_dir in library_dirs:
        srcs.extend( glob.glob(os.path.join(library_dir, "*.dll")) )
elif distro_name == "Ubuntu" or distro_name == "Fedora":
    library_dirs = [os.path.join(path_external, path_manufacturer + distro_name)]
    for library_dir in library_dirs:
        srcs.extend( glob.glob(os.path.join(library_dir, "*.so*")) )
else:
    raise("No compilation found for your distribution")
# --- Copy the resource files into the current working directory
if len(srcs) > 0:
    print("\ncopy resource files:")
for src in srcs:
    dest = os.path.join(this_directory, os.path.basename(src))
    print(f" {src=} -> {dest=}")
    shutil.copyfile(src, dest)
    if psystem != "Windows":
        # --- Modify attributes
        os.chmod(dest, stat.S_IRWXU  | stat.S_IRWXG | stat.S_IRWXO)

# =============================================
# === Include files and compilation options ===
# =============================================
# --- Specific platform includes
extra_compile_args = []
extra_link_args = []
if distro_name == "Windows":
    include_dirs=[os.path.join(path_external, path_manufacturer)]
    extra_compile_args.append("/D")
    extra_compile_args.append('"_CRT_SECURE_NO_WARNINGS"')
    extra_compile_args.append("/W3")
elif distro_name == "Ubuntu" or distro_name == "Fedora":
    include_dirs=[os.path.join(path_external, path_manufacturer + distro_name)]
    #extra_compile_args.append("-Wwrite-strings")    
    #extra_compile_args.append("-lstdc++")   
    #extra_link_args.append("-lm")
    extra_link_args.append("-lusb-1.0") 
    #extra_link_args.append("-lstdc++")    
# --- Any platform includes
include_dirs.append(numpy.get_include()) # numpy
include_dirs.append(os.path.join("audela",      "src","include")) # sysexp.h
include_dirs.append(os.path.join("audela_notcl","src","include")) # tcl.h libcam/licam.h libcam/libstruc.h
include_dirs.append(os.path.join("audela",      "src","libcam","libfingerlakespro","src")) # camera.h

# =================
# === Libraries ===
# =================
libraries = ["libflipro"]

# ===============
# === Sources ===
# ===============
# --- Define the common source files to compile
sources = []
sources.append("audela/src/libcam/util.cpp")
# --- Define the specific source files to compile
sources.append("wrapper_flipro.cpp")
sources.append("audela/src/libcam/libfingerlakespro/src/camera.cpp")
    
# =============
# === Setup ===
# =============
print(f"\n{include_dirs=}")
print(f"\n{extra_compile_args=}")
print(f"\n{extra_link_args=}")
print(f"\n{library_dirs=}")
print(f"\n{libraries=}")
print(f"\n{sources=}")
setup(

    description = "A Python wrapper of a device flipro",
    long_description = long_description,
    long_description_content_type = "text/markdown",
    version = "0.9",
    author = "Alain Klotz",
    author_email = "aklotz@irap.omp.eu",
    license = "MIT",
    
    ext_modules = [
        Extension(
            name = "wrapper_flipro",  # as it would be imported. It includes packages/namespaces separated by `.`
            include_dirs = include_dirs,
            extra_compile_args = extra_compile_args,
            extra_link_args = extra_link_args,
            library_dirs = library_dirs,
            libraries = libraries,
            sources = sources, # all sources are compiled into a single binary file
        ),
    ]
)