summaryrefslogtreecommitdiff
blob: de52bc063a24fe0a9b3acd359e88f19dc189e1da (plain)
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
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
diff --git a/setup.py b/setup.py
index f1de675..4c23028 100644
--- a/setup.py
+++ b/setup.py
@@ -27,53 +27,59 @@ if system == 'Darwin':
     os.environ.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.14')
     extra_compile_args.append('-std=c++11')
 
-if os.getenv('BUILD_WITH_CYTHON') and not CYTHON_AVAILABLE:
+build_with_cython = os.getenv('BUILD_WITH_CYTHON')
+if build_with_cython and not CYTHON_AVAILABLE:
     print(
         'BUILD_WITH_CYTHON environment variable is set, but cython'
         ' is not available. Falling back to pre-cythonized version if'
         ' available.'
     )
+    build_with_cython = False
 
-if os.getenv('BUILD_WITH_CYTHON') and CYTHON_AVAILABLE:
-    macros = []
-    compiler_directives = {
-        'embedsignature': True
-    }
+build_with_system_lib = os.getenv('BUILD_WITH_SYSTEM_LIB')
+
+macros = []
+compiler_directives = {}
+libraries = []
+sources = [
+    'simdjson/errors.cpp',
+]
+
+if build_with_system_lib:
+    libraries.append('simdjson')
+else:
+    sources.append('simdjson/simdjson.cpp')
+
+if build_with_cython:
+    compiler_directives['embedsignature'] = True
 
     if os.getenv('BUILD_FOR_DEBUG'):
         # Enable line tracing, which also enables support for coverage
         # reporting.
-        macros = [
+        macros += [
             ('CYTHON_TRACE', 1),
             ('CYTHON_TRACE_NOGIL', 1)
         ]
         compiler_directives['linetrace'] = True
 
-    extensions = cythonize([
-        Extension(
-            'csimdjson',
-            [
-                'simdjson/simdjson.cpp',
-                'simdjson/errors.cpp',
-                'simdjson/csimdjson.pyx'
-            ],
-            define_macros=macros,
-            extra_compile_args=extra_compile_args
-        )
-    ], compiler_directives=compiler_directives)
+    sources.append('simdjson/csimdjson.pyx')
 else:
-    extensions = [
-        Extension(
-            'csimdjson',
-            [
-                'simdjson/simdjson.cpp',
-                'simdjson/errors.cpp',
-                'simdjson/csimdjson.cpp'
-            ],
-            extra_compile_args=extra_compile_args,
-            language='c++'
-        )
-    ]
+    sources.append('simdjson/csimdjson.cpp')
+
+
+extensions = [
+    Extension(
+        'csimdjson',
+        sources,
+        define_macros=macros,
+        extra_compile_args=extra_compile_args,
+        libraries=libraries,
+        language='c++',
+    )
+]
+
+if build_with_cython:
+    extensions = cythonize(extensions, compiler_directives=compiler_directives)
 
 setup(
     name='pysimdjson',