forked from idealo/imagededup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
50 lines (40 loc) · 1.26 KB
/
setup.py
File metadata and controls
50 lines (40 loc) · 1.26 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import os
try:
from Cython.Build import cythonize
use_cython = True
except ImportError:
use_cython = False
on_mac = sys.platform.startswith('darwin')
on_windows = sys.platform.startswith('win')
MOD_NAME = 'brute_force_cython_ext'
MOD_PATH = 'imagededup/handlers/search/brute_force_cython_ext'
COMPILE_ARGS_BASE = ['-O3']
COMPILE_ARGS_OSX = ['-stdlib=libc++']
LINK_ARGS_OSX = ['-lc++', '-nodefaultlibs']
COMPILE_ARGS_NATIVE = ['-march=native', '-mtune=native']
# Start with base args
compile_args = COMPILE_ARGS_BASE.copy()
link_args = COMPILE_ARGS_BASE.copy()
# Only use -march=native if not doing macOS universal builds
if not on_mac and not on_windows:
compile_args += COMPILE_ARGS_NATIVE
link_args += COMPILE_ARGS_NATIVE
# macOS-specific adjustments
if on_mac:
compile_args += COMPILE_ARGS_OSX
link_args += LINK_ARGS_OSX
ext_modules = []
source_ext = '.pyx' if use_cython else '.cpp'
source_file = MOD_PATH + source_ext
ext = Extension(
MOD_NAME,
[source_file],
language='c++',
extra_compile_args=compile_args,
extra_link_args=link_args
)
ext_modules = cythonize([ext]) if use_cython else [ext]
setup(ext_modules=ext_modules)