blob: 8d7cca8432b21d366a27ca28a7e5ba231fbf51c8 [file] [log] [blame]
Christophe Favergeonc8a9c182022-02-25 09:48:43 +01001#from distutils.core import setup, Extension
2from setuptools import setup, Extension,find_packages
3from distutils.util import convert_path
4import glob
5import numpy
6import sys
7import os
8import os.path
9import re
10import pathlib
11
12here = pathlib.Path(__file__).parent.resolve()
13ROOT = here
14ROOT=""
15
16includes = [os.path.join(ROOT,"Include"),os.path.join(ROOT,"PrivateInclude"),os.path.join("PythonWrapper","cmsisdsp_pkg","src")]
17
18if sys.platform == 'win32':
19 cflags = ["-DWIN","-DCMSISDSP","-DUNALIGNED_SUPPORT_DISABLE"]
20else:
21 cflags = ["-Wno-attributes","-Wno-unused-function","-Wno-unused-variable","-Wno-implicit-function-declaration","-DCMSISDSP","-D__GNUC_PYTHON__"]
22
23transform = glob.glob(os.path.join(ROOT,"Source","TransformFunctions","*.c"))
24
25# Files are present when creating the source distribution
26# but they are not copied to the source distribution
27# When doing pip install those files are not prevent
28# and it should not fail
29try:
30 transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctions.c"))
31 transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctionsF16.c"))
32except:
33 pass
34
35support = glob.glob(os.path.join(ROOT,"Source","SupportFunctions","*.c"))
36
37try:
38 support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctions.c"))
39 support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctionsF16.c"))
40except:
41 pass
42
43fastmath = glob.glob(os.path.join(ROOT,"Source","FastMathFunctions","*.c"))
44try:
45 fastmath.remove(os.path.join(ROOT,"Source","FastMathFunctions","FastMathFunctions.c"))
46except:
47 pass
48
49filtering = glob.glob(os.path.join(ROOT,"Source","FilteringFunctions","*.c"))
50try:
51 filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctions.c"))
52 filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctionsF16.c"))
53except:
54 pass
55
56matrix = glob.glob(os.path.join(ROOT,"Source","MatrixFunctions","*.c"))
57try:
58 matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctions.c"))
59 matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctionsF16.c"))
60except:
61 pass
62
63statistics = glob.glob(os.path.join(ROOT,"Source","StatisticsFunctions","*.c"))
64try:
65 statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctions.c"))
66 statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctionsF16.c"))
67except:
68 pass
69
70complexf = glob.glob(os.path.join(ROOT,"Source","ComplexMathFunctions","*.c"))
71try:
72 complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctions.c"))
73 complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctionsF16.c"))
74except:
75 pass
76
77basic = glob.glob(os.path.join(ROOT,"Source","BasicMathFunctions","*.c"))
78try:
79 basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctions.c"))
80 basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctionsF16.c"))
81except:
82 pass
83
84controller = glob.glob(os.path.join(ROOT,"Source","ControllerFunctions","*.c"))
85try:
86 controller.remove(os.path.join(ROOT,"Source","ControllerFunctions","ControllerFunctions.c"))
87except:
88 pass
89
90common = glob.glob(os.path.join(ROOT,"Source","CommonTables","*.c"))
91try:
92 common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTables.c"))
93 common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTablesF16.c"))
94except:
95 pass
96
97interpolation = glob.glob(os.path.join(ROOT,"Source","InterpolationFunctions","*.c"))
98try:
99 interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctions.c"))
100 interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctionsF16.c"))
101except:
102 pass
103
104quaternion = glob.glob(os.path.join(ROOT,"Source","QuaternionMathFunctions","*.c"))
105try:
106 quaternion.remove(os.path.join(ROOT,"Source","QuaternionMathFunctions","QuaternionMathFunctions.c"))
107except:
108 pass
109
Christophe Favergeon71060102022-03-07 11:05:01 +0100110distance = glob.glob(os.path.join(ROOT,"Source","DistanceFunctions","*.c"))
111try:
112 distance.remove(os.path.join(ROOT,"Source","DistanceFunctions","DistanceFunctions.c"))
113except:
114 pass
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100115
Christophe Favergeon71060102022-03-07 11:05:01 +0100116bayes = glob.glob(os.path.join(ROOT,"Source","BayesFunctions","*.c"))
117try:
118 bayes.remove(os.path.join(ROOT,"Source","BayesFunctions","BayesFunctions.c"))
119except:
120 pass
121
122svm = glob.glob(os.path.join(ROOT,"Source","SVMFunctions","*.c"))
123try:
124 svm.remove(os.path.join(ROOT,"Source","SVMFunctions","SVMFunctions.c"))
125except:
126 pass
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100127
128# Add dependencies
129transformMod = transform + common + basic + complexf + fastmath + matrix + statistics
Christophe Favergeon71060102022-03-07 11:05:01 +0100130statisticsMod = statistics + common + fastmath + basic
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100131interpolationMod = interpolation + common
132filteringMod = filtering + common + support + fastmath
133controllerMod = controller + common
134
135matrixMod = matrix
136supportMod = support
137complexfMod = complexf + fastmath + common
138basicMod = basic
139quaternionMod = quaternion
140fastmathMod = fastmath + common
Christophe Favergeon71060102022-03-07 11:05:01 +0100141distanceMod = distance + common + basic + statistics + fastmath
142bayesMod = bayes + fastmath + common + statistics + basic
143svmMod = svm + fastmath + common
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100144
145
146filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c"))
147matrixMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_matrix.c"))
148supportMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_support.c"))
149statisticsMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_statistics.c"))
150complexfMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_complexf.c"))
151basicMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_basic.c"))
152controllerMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_controller.c"))
153transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_transform.c"))
154interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c"))
155quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c"))
156fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c"))
Christophe Favergeon71060102022-03-07 11:05:01 +0100157distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c"))
158bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c"))
159svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c"))
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100160
161
162
163
Christophe Favergeon71060102022-03-07 11:05:01 +0100164missing=set([
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100165 ])
166
167def notf16(number):
168 if re.search(r'f16',number):
169 return(False)
170 if re.search(r'F16',number):
171 return(False)
172 return(True)
173
174def isnotmissing(src):
175 name=os.path.splitext(os.path.basename(src))[0]
176 return(not (name in missing))
177
178# If there are too many files, the linker command is failing on Windows.
179# So f16 functions are removed since they are not currently available in the wrapper.
180# A next version will have to structure this wrapper more cleanly so that the
181# build can work even with more functions
182
183filtering = list(filter(isnotmissing,list(filter(notf16, filteringMod))))
184matrix = list(filter(isnotmissing,list(filter(notf16, matrixMod))))
185support = list(filter(isnotmissing,list(filter(notf16, supportMod))))
186statistics = list(filter(isnotmissing,list(filter(notf16, statisticsMod))))
187complexf = list(filter(isnotmissing,list(filter(notf16, complexfMod))))
188basic = list(filter(isnotmissing,list(filter(notf16, basicMod))))
189controller = list(filter(isnotmissing,list(filter(notf16, controllerMod))))
190transform = list(filter(isnotmissing,list(filter(notf16, transformMod))))
191interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod))))
192quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod))))
193fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod))))
Christophe Favergeon71060102022-03-07 11:05:01 +0100194distance = list(filter(isnotmissing,list(filter(notf16, distanceMod))))
195bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod))))
196svm = list(filter(isnotmissing,list(filter(notf16, svmMod))))
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100197
198#for l in filtering:
199# print(os.path.basename(l))
200#quit()
201
Christophe Favergeon71060102022-03-07 11:05:01 +0100202def mkModule(name,srcs,funcDir,newCflags=[]):
203 localinc = os.path.join(ROOT,"Source",funcDir)
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100204 return(Extension(name,
205 sources = (srcs
206 )
207 ,
Christophe Favergeon71060102022-03-07 11:05:01 +0100208 include_dirs = [localinc] + includes + [numpy.get_include()],
209 extra_compile_args = cflags + newCflags
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100210 ))
211
Christophe Favergeon71060102022-03-07 11:05:01 +0100212flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES",
213 "-DARM_FAST_ALLOW_TABLES",
214 "-DARM_ALL_FAST_TABLES"]
215
216moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions",flagsForCommonWithoutFFT)
217moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions")
218moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions")
219moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions",flagsForCommonWithoutFFT)
220moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions")
221moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions")
222moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions",flagsForCommonWithoutFFT)
223moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions")
224moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions",flagsForCommonWithoutFFT)
225moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions")
226moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions",flagsForCommonWithoutFFT)
227moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions",flagsForCommonWithoutFFT)
228moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions",flagsForCommonWithoutFFT)
229moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions",flagsForCommonWithoutFFT)
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100230
231
232
233
234def build():
235 if sys.version_info.major < 3:
236 print('setup.py: Error: This package only supports Python 3.', file=sys.stderr)
237 sys.exit(1)
238
239 main_ns = {}
240 ver_path = convert_path(os.path.join("cmsisdsp","version.py"))
241 with open(ver_path) as ver_file:
242 exec(ver_file.read(), main_ns)
243
244 setup (name = 'cmsisdsp',
245 version = main_ns['__version__'],
246 packages=["cmsisdsp","cmsisdsp.sdf","cmsisdsp.sdf.nodes","cmsisdsp.sdf.nodes.host","cmsisdsp.sdf.scheduler"],
247 description = 'CMSIS-DSP Python API',
248 long_description=open("PythonWrapper_README.md").read(),
249 long_description_content_type='text/markdown',
250 ext_modules = [moduleFiltering ,
251 moduleMatrix,
252 moduleSupport,
253 moduleStatistics,
254 moduleComplexf,
255 moduleBasic,
256 moduleController,
257 moduleTransform,
258 moduleInterpolation,
259 moduleQuaternion,
Christophe Favergeon71060102022-03-07 11:05:01 +0100260 moduleFastmath,
261 moduleDistance,
262 moduleBayes,
263 moduleSVM
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100264 ],
265 include_package_data=True,
266 author = 'Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.',
267 author_email = 'christophe.favergeon@arm.com',
268 url="https://arm-software.github.io/CMSIS_5/DSP/html/index.html",
269 python_requires='>=3.6',
270 license="License :: OSI Approved :: Apache Software License",
271 platforms=['any'],
272 classifiers=[
273 "Programming Language :: Python :: 3",
274 "Programming Language :: Python :: Implementation :: CPython",
275 "Programming Language :: C",
276 "License :: OSI Approved :: Apache Software License",
277 "Operating System :: OS Independent",
278 "Development Status :: 4 - Beta",
279 "Topic :: Software Development :: Embedded Systems",
280 "Topic :: Scientific/Engineering :: Mathematics",
281 "Environment :: Console",
282 "Intended Audience :: Developers",
283 ],
284 keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths'],
285 install_requires=['numpy>=1.19',
286 'networkx>=2.5',
Christophe Favergeon71060102022-03-07 11:05:01 +0100287 'jinja2>= 2.0, <3.0',
288 'sympy>=1.6',
289 'markupsafe<2.1'
290 ],
Christophe Favergeonc8a9c182022-02-25 09:48:43 +0100291 project_urls={ # Optional
292 'Bug Reports': 'https://github.com/ARM-software/CMSIS_5/issues',
293 'Source': 'https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP',
294 }
295 )
296
297
298build()