1#from distutils.core import setup, Extension
2from setuptools import setup, Extension,find_packages
3import io
4import glob
5import numpy
6import sys
7import os
8import os.path
9import re
10import pathlib
11
12
13here = pathlib.Path(__file__).parent.resolve()
14ROOT = here
15ROOT=""
16
17PYTHON_MOD = os.path.join(ROOT,"cmsisdsp")
18version_path = os.path.join(PYTHON_MOD,"version.py")
19
20__version__ = re.search(
21    r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]',  # It excludes inline comment too
22    io.open(version_path, encoding='utf_8_sig').read()
23    ).group(1)
24
25
26includes = [os.path.join(ROOT,"Include"),os.path.join(ROOT,"PrivateInclude"),os.path.join("PythonWrapper","cmsisdsp_pkg","src")]
27
28if sys.platform == 'win32':
29  cflags = ["-DWIN","-DCMSISDSP","-DUNALIGNED_SUPPORT_DISABLE"]
30else:
31  cflags = ["-Wno-attributes","-Wno-unused-function","-Wno-unused-variable","-Wno-implicit-function-declaration","-DCMSISDSP","-D__GNUC_PYTHON__"]
32
33# Add dependencies
34transformMod = [] # transform + common + basic + complexf + fastmath + matrix + statistics
35statisticsMod = [] # statistics + common + fastmath + basic
36interpolationMod = [] # interpolation + common
37filteringMod = [] # filtering + common + support + fastmath + basic
38controllerMod = [] # controller + common
39
40matrixMod = [] # matrix + basic
41supportMod = [] # support
42complexfMod = [] # complexf + fastmath + common + basic
43basicMod = [] # basic
44quaternionMod = [] # quaternion
45fastmathMod = [] # basic + fastmath + common
46distanceMod = [] # distance + common + basic + statistics + fastmath
47bayesMod = [] # bayes + fastmath + common + statistics + basic
48svmMod = [] # svm + fastmath + common + basic
49
50windowMod = [] # window
51
52filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c"))
53matrixMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_matrix.c"))
54supportMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_support.c"))
55statisticsMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_statistics.c"))
56complexfMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_complexf.c"))
57basicMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_basic.c"))
58controllerMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_controller.c"))
59transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_transform.c"))
60interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c"))
61quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c"))
62fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c"))
63distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c"))
64bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c"))
65svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c"))
66windowMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_window.c"))
67
68
69
70
71missing=set([
72  ])
73
74def notf16(number):
75  if re.search(r'f16',number):
76     return(False)
77  if re.search(r'F16',number):
78     return(False)
79  return(True)
80
81def isnotmissing(src):
82  name=os.path.splitext(os.path.basename(src))[0]
83  return(not (name in missing))
84
85# If there are too many files, the linker command is failing on Windows.
86# So f16 functions are removed since they are not currently available in the wrapper.
87# A next version will have to structure this wrapper more cleanly so that the
88# build can work even with more functions
89
90filtering = list(filter(isnotmissing,list(filter(notf16, filteringMod))))
91matrix = list(filter(isnotmissing,list(filter(notf16, matrixMod))))
92support = list(filter(isnotmissing,list(filter(notf16, supportMod))))
93statistics = list(filter(isnotmissing,list(filter(notf16, statisticsMod))))
94complexf = list(filter(isnotmissing,list(filter(notf16, complexfMod))))
95basic = list(filter(isnotmissing,list(filter(notf16, basicMod))))
96controller = list(filter(isnotmissing,list(filter(notf16, controllerMod))))
97transform = list(filter(isnotmissing,list(filter(notf16, transformMod))))
98interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod))))
99quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod))))
100fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod))))
101distance = list(filter(isnotmissing,list(filter(notf16, distanceMod))))
102bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod))))
103svm = list(filter(isnotmissing,list(filter(notf16, svmMod))))
104window = list(filter(isnotmissing,list(filter(notf16, windowMod))))
105
106#for l in filtering:
107#  print(os.path.basename(l))
108#quit()
109
110def mkModule(name,srcs,funcDir):
111  localinc = os.path.join(ROOT,"Source",funcDir)
112  libdir = [os.path.join(ROOT,"PythonWrapper","build","bin_dsp")]
113  lib = ["CMSISDSP"]
114  extraobjs=[]
115
116  if sys.platform.startswith('linux'):
117    lib = []
118    extraobjs = [os.path.join(ROOT,"PythonWrapper","build_linux","bin_dsp","libCMSISDSP.a")]
119    libdir = []
120
121  if sys.platform.startswith('darwin'):
122    lib = []
123    extraobjs = [os.path.join(ROOT,"PythonWrapper","build_darwin","bin_dsp","libCMSISDSP.a")]
124    libdir = []
125
126  return(Extension(name,
127                    sources = (srcs
128                              )
129                              ,
130                    include_dirs =  [localinc] + includes + [numpy.get_include()],
131                    extra_compile_args = cflags,
132                    library_dirs = libdir,
133                    libraries=lib,
134                    extra_objects=extraobjs
135                              ))
136
137flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES",
138    "-DARM_FAST_ALLOW_TABLES",
139    "-DARM_ALL_FAST_TABLES"]
140
141moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions")
142moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions")
143moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions")
144moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions")
145moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions")
146moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions")
147moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions")
148moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions")
149moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions")
150moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions")
151moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions")
152moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions")
153moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions")
154moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions")
155moduleWindow = mkModule('cmsisdsp_window',window,"WindowFunctions")
156
157
158
159
160def build():
161  if sys.version_info.major < 3:
162      print('setup.py: Error: This package only supports Python 3.', file=sys.stderr)
163      sys.exit(1)
164
165  setup (name = 'cmsisdsp',
166         version = __version__,
167         packages=["cmsisdsp"],
168         description = 'CMSIS-DSP Python API',
169         long_description=open("PythonWrapper_README.md").read(),
170         long_description_content_type='text/markdown',
171         ext_modules = [moduleFiltering ,
172                        moduleMatrix,
173                        moduleSupport,
174                        moduleStatistics,
175                        moduleComplexf,
176                        moduleBasic,
177                        moduleController,
178                        moduleTransform,
179                        moduleInterpolation,
180                        moduleQuaternion,
181                        moduleFastmath,
182                        moduleDistance,
183                        moduleBayes,
184                        moduleSVM,
185                        moduleWindow
186                        ],
187         include_package_data=True,
188         author = 'Copyright (C) 2010-2024 ARM Limited or its affiliates. All rights reserved.',
189         author_email = 'christophe.favergeon@arm.com',
190         url="https://github.com/ARM-software/CMSIS-DSP",
191         python_requires='>=3.9',
192         license="License :: OSI Approved :: Apache Software License",
193         platforms=['any'],
194         classifiers=[
195                "Programming Language :: Python :: 3",
196                "Programming Language :: Python :: Implementation :: CPython",
197                "Programming Language :: C",
198                "License :: OSI Approved :: Apache Software License",
199                "Operating System :: OS Independent",
200                "Development Status :: 4 - Beta",
201                "Topic :: Software Development :: Embedded Systems",
202                "Topic :: Scientific/Engineering :: Mathematics",
203                "Environment :: Console",
204                "Intended Audience :: Developers",
205          ],
206          keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths','ml','cortex-m','cortex-a'],
207          install_requires=[
208          'numpy>=1.23.5',
209          ],
210          project_urls={  # Optional
211             'Bug Reports': 'https://github.com/ARM-software/CMSIS-DSP/issues',
212             'Source': 'https://github.com/ARM-software/CMSIS-DSP',
213            }
214          )
215
216
217build()
218