Bump version
[pycuda.git] / setup.py
1 #!/usr/bin/env python
2 # -*- coding: latin-1 -*-
3 from os.path import dirname, join, normpath
4
5
6 def search_on_path(filenames):
7     """Find file on system path."""
8     # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52224
9
10     from os.path import exists, abspath
11     from os import pathsep, environ
12
13     search_path = environ["PATH"]
14
15     paths = search_path.split(pathsep)
16     for path in paths:
17         for filename in filenames:
18             if exists(join(path, filename)):
19                 return abspath(join(path, filename))
20
21
22 def get_config_schema():
23     from aksetup_helper import ConfigSchema, Option, \
24             IncludeDir, LibraryDir, Libraries, BoostLibraries, \
25             Switch, StringListOption, make_boost_base_options
26
27     nvcc_path = search_on_path(["nvcc", "nvcc.exe"])
28     if nvcc_path is None:
29         print("*** WARNING: nvcc not in path.")
30         cuda_root_default = None
31     else:
32         cuda_root_default = normpath(join(dirname(nvcc_path), ".."))
33
34     return ConfigSchema(make_boost_base_options() + [
35         Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
36
37         BoostLibraries("python"),
38         BoostLibraries("thread"),
39
40         Switch("CUDA_TRACE", False, "Enable CUDA API tracing"),
41         Option("CUDA_ROOT", default=cuda_root_default,
42             help="Path to the CUDA toolkit"),
43         Option("CUDA_PRETEND_VERSION",
44             help="Assumed CUDA version, in the form 3010 for 3.1."),
45         IncludeDir("CUDA", None),
46
47         Switch("CUDA_ENABLE_GL", False, "Enable CUDA GL interoperability"),
48         Switch("CUDA_ENABLE_CURAND", True, "Enable CURAND library"),
49
50         LibraryDir("CUDADRV", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
51         Libraries("CUDADRV", ["cuda"]),
52
53         LibraryDir("CUDART", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
54         Libraries("CUDART", ["cudart"]),
55
56         LibraryDir("CURAND", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
57         Libraries("CURAND", ["curand"]),
58
59         StringListOption("CXXFLAGS", [],
60             help="Any extra C++ compiler options to include"),
61         StringListOption("LDFLAGS", [],
62             help="Any extra linker options to include"),
63         ])
64
65
66 def main():
67     import sys
68
69     from aksetup_helper import (hack_distutils, get_config, setup,
70             NumpyExtension, set_up_shipped_boost_if_requested,
71             check_git_submodules)
72
73     check_git_submodules()
74
75     hack_distutils()
76     conf = get_config(get_config_schema())
77
78     EXTRA_SOURCES, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pycuda", conf)
79
80     EXTRA_DEFINES["PYGPU_PACKAGE"] = "pycuda"
81     EXTRA_DEFINES["PYGPU_PYCUDA"] = "1"
82
83     LIBRARY_DIRS = conf["BOOST_LIB_DIR"] + conf["CUDADRV_LIB_DIR"]
84     LIBRARIES = (conf["BOOST_PYTHON_LIBNAME"] + conf["BOOST_THREAD_LIBNAME"]
85             + conf["CUDADRV_LIBNAME"])
86
87     if not conf["CUDA_INC_DIR"]:
88         conf["CUDA_INC_DIR"] = [join(conf["CUDA_ROOT"], "include")]
89
90     if conf["CUDA_TRACE"]:
91         EXTRA_DEFINES["CUDAPP_TRACE_CUDA"] = 1
92
93     if conf["CUDA_PRETEND_VERSION"]:
94         EXTRA_DEFINES["CUDAPP_PRETEND_CUDA_VERSION"] = conf["CUDA_PRETEND_VERSION"]
95
96     INCLUDE_DIRS = ['src/cpp'] + conf["BOOST_INC_DIR"] + conf["CUDA_INC_DIR"]
97     conf["USE_CUDA"] = True
98
99     if 'darwin' in sys.platform and sys.maxsize == 2147483647:
100         # The Python interpreter is running in 32 bit mode on OS X
101         if "-arch" not in conf["CXXFLAGS"]:
102             conf["CXXFLAGS"].extend(['-arch', 'i386', '-m32'])
103         if "-arch" not in conf["LDFLAGS"]:
104             conf["LDFLAGS"].extend(['-arch', 'i386', '-m32'])
105
106     if 'darwin' in sys.platform:
107         # set path to Cuda dynamic libraries,
108         # as a safe substitute for DYLD_LIBRARY_PATH
109         for lib_dir in conf["CUDADRV_LIB_DIR"]:
110             conf["LDFLAGS"].extend(["-Xlinker", "-rpath", "-Xlinker", lib_dir])
111
112     if conf["CUDA_ENABLE_GL"]:
113         EXTRA_SOURCES.append("src/wrapper/wrap_cudagl.cpp")
114         EXTRA_DEFINES["HAVE_GL"] = 1
115
116     if conf["CUDA_ENABLE_CURAND"]:
117         EXTRA_DEFINES["HAVE_CURAND"] = 1
118         EXTRA_SOURCES.extend([
119             "src/wrapper/wrap_curand.cpp"
120             ])
121         LIBRARIES.extend(conf["CURAND_LIBNAME"])
122         LIBRARY_DIRS.extend(conf["CURAND_LIB_DIR"])
123
124     ver_dic = {}
125     exec(compile(open("pycuda/__init__.py").read(), "pycuda/__init__.py", 'exec'),
126             ver_dic)
127
128     try:
129         from distutils.command.build_py import build_py_2to3 as build_py
130     except ImportError:
131         # 2.x
132         from distutils.command.build_py import build_py
133
134     import sys
135     if sys.version_info >= (3,):
136         pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
137     else:
138         pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
139
140     setup(name="pycuda",
141             # metadata
142             version=ver_dic["VERSION_TEXT"],
143             description="Python wrapper for Nvidia CUDA",
144             long_description=open("README.rst", "rt").read(),
145             author="Andreas Kloeckner",
146             author_email="inform@tiker.net",
147             license="MIT",
148             url="http://mathema.tician.de/software/pycuda",
149             classifiers=[
150                 'Environment :: Console',
151                 'Development Status :: 5 - Production/Stable',
152                 'Intended Audience :: Developers',
153                 'Intended Audience :: Other Audience',
154                 'Intended Audience :: Science/Research',
155                 'License :: OSI Approved :: MIT License',
156                 'Natural Language :: English',
157                 'Programming Language :: C++',
158                 'Programming Language :: Python',
159                 'Programming Language :: Python :: 3',
160                 'Programming Language :: Python :: 2.6',
161                 'Programming Language :: Python :: 2.7',
162                 'Programming Language :: Python :: 3.3',
163                 'Programming Language :: Python :: 3.4',
164                 'Topic :: Scientific/Engineering',
165                 'Topic :: Scientific/Engineering :: Mathematics',
166                 'Topic :: Scientific/Engineering :: Physics',
167                 'Topic :: Scientific/Engineering :: Visualization',
168                 ],
169
170             # build info
171             packages=["pycuda", "pycuda.gl", "pycuda.sparse", "pycuda.compyte"],
172
173             install_requires=[
174                 "pytools>=2011.2",
175                 "pytest>=2",
176                 "decorator>=3.2.0"
177                 ],
178
179             ext_package="pycuda",
180             ext_modules=[
181                 NumpyExtension("_driver",
182                     [
183                         "src/cpp/cuda.cpp",
184                         "src/cpp/bitlog.cpp",
185                         "src/wrapper/wrap_cudadrv.cpp",
186                         "src/wrapper/mempool.cpp",
187                         ]+EXTRA_SOURCES,
188                     include_dirs=INCLUDE_DIRS,
189                     library_dirs=LIBRARY_DIRS,
190                     libraries=LIBRARIES,
191                     define_macros=list(EXTRA_DEFINES.items()),
192                     extra_compile_args=conf["CXXFLAGS"],
193                     extra_link_args=conf["LDFLAGS"],
194                     ),
195                 NumpyExtension("_pvt_struct",
196                     [pvt_struct_source],
197                     extra_compile_args=conf["CXXFLAGS"],
198                     extra_link_args=conf["LDFLAGS"],
199                     ),
200                 ],
201
202             include_package_data=True,
203             package_data={
204                     "pycuda": [
205                         "cuda/*.hpp",
206                         ]
207                     },
208
209             zip_safe=False,
210
211             # 2to3 invocation
212             cmdclass={'build_py': build_py})
213
214
215 if __name__ == '__main__':
216     main()