-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
105 lines (78 loc) · 3.29 KB
/
setup.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
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
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
#
"""Setup script for compiling the Cython example.
Usage:
python -m setup build_ext --inplace
"""
from __future__ import absolute_import
#########################################################
# Config
#########################################################
# choose build type here
#
build_type="optimized"
#build_type="debug"
#########################################################
# Init
#########################################################
# check for Python 2.7 or later
# http://stackoverflow.com/questions/19534896/enforcing-python-version-in-setup-py
import sys
if sys.version_info < (2,7):
sys.exit('Sorry, Python < 2.7 is not supported')
import os
from setuptools import setup
from setuptools.extension import Extension
try:
from Cython.Build import cythonize
except ImportError:
sys.exit("Cython not found. Cython is needed to build the extension modules for pydgq.")
#########################################################
# Definitions
#########################################################
extra_compile_args_math_optimized = ['-fopenmp', '-march=native', '-O2', '-msse', '-msse2', '-mfma', '-mfpmath=sse']
extra_compile_args_math_debug = ['-fopenmp', '-march=native', '-O0', '-g']
extra_compile_args_nonmath_optimized = ['-O2']
extra_compile_args_nonmath_debug = ['-O0', '-g']
extra_link_args_optimized = ['-fopenmp']
extra_link_args_debug = ['-fopenmp']
if build_type == 'optimized':
my_extra_compile_args_math = extra_compile_args_math_optimized
my_extra_compile_args_nonmath = extra_compile_args_nonmath_optimized
my_extra_link_args = extra_link_args_optimized
debug = False
print "build configuration selected: optimized"
else: # build_type == 'debug':
my_extra_compile_args_math = extra_compile_args_math_debug
my_extra_compile_args_nonmath = extra_compile_args_nonmath_debug
my_extra_link_args = extra_link_args_debug
debug = True
print "build configuration selected: debug"
#########################################################
# Helpers
#########################################################
my_include_dirs = ["."] # IMPORTANT, see https://github.com/cython/cython/wiki/PackageHierarchy
def ext(extName):
extPath = extName.replace(".", os.path.sep)+".pyx"
return Extension( extName,
[extPath],
extra_compile_args=my_extra_compile_args_nonmath
)
def ext_math(extName):
extPath = extName.replace(".", os.path.sep)+".pyx"
return Extension( extName,
[extPath],
extra_compile_args=my_extra_compile_args_math,
extra_link_args=my_extra_link_args,
libraries=["m"] # "m" links libm, the math library on unix-likes; see http://docs.cython.org/src/tutorial/external.html
)
#########################################################
# Modules
#########################################################
ext_module_ckernel = ext_math( "cython_kernel" )
#########################################################
setup(
ext_modules = cythonize( [ ext_module_ckernel ],
include_path = my_include_dirs,
gdb_debug = debug )
)