-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup_cpp_ext.py
43 lines (38 loc) · 1.15 KB
/
setup_cpp_ext.py
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
#
# Author: David Futschik
# Provided as part of the Chunkmogrify project, 2021.
#
import platform
import setuptools
import numpy as np
from setuptools import sandbox
platform_specific_flags = []
if platform.system() == "Windows":
platform_specific_flags += ["/permissive-", "/Ox", "/std:c++11"]
else:
platform_specific_flags += ["-O3", "--std=c++11"]
ext_modules = [
setuptools.Extension('_C_canvas',
sources=['extensions/canvas_to_masks.cpp'],
include_dirs=[np.get_include()],
extra_compile_args=platform_specific_flags,
language='c++'),
setuptools.Extension('_C_heatmap',
sources=['extensions/heatmap.cpp'],
include_dirs=[np.get_include()],
extra_compile_args=platform_specific_flags,
language='c++')
]
def checked_build(force=False):
def do_build():
sandbox.run_setup('setup_cpp_ext.py', ['build_ext', '--inplace'])
try:
import _C_canvas
import _C_heatmap
if force: do_build()
except ImportError:
do_build()
if __name__ == "__main__":
setuptools.setup(
ext_modules=ext_modules
)