-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
167 lines (143 loc) · 6.16 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
Install script for riegl_canopy
"""
import os
import sys
import numpy
import ctypes
import pylidar_tls_canopy
from setuptools import Extension,setup
NUMPY_MACROS = ('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')
def getExtraCXXFlags():
"""
Looks at the $PYLIDAR_CXX_FLAGS environment variable.
If it exists, this function returns a list of flags
to be passed as the extra_compile_args argument to
the Extension constructor.
Otherwise None.
"""
if 'PYLIDAR_CXX_FLAGS' in os.environ:
return os.environ['PYLIDAR_CXX_FLAGS'].split()
else:
return None
def addRieglRXPDriver(extModules, cxxFlags):
"""
RIEGL RXP driver
"""
if 'RIVLIB_ROOT' in os.environ:
print('Building RIEGL RXP Extension...')
rivlibRoot = os.environ['RIVLIB_ROOT']
rivlibs = ['scanlib-mt', 'riboost_chrono-mt',
'riboost_date_time-mt', 'riboost_filesystem-mt',
'riboost_regex-mt', 'riboost_system-mt',
'riboost_thread-mt']
# on Windows the libs do not follow the normal naming convention
# and start with 'lib'. On Linux the compiler prepends this automatically
# but on Windows we need to do it manually
if sys.platform == 'win32':
rivlibs = ['lib' + name for name in rivlibs]
elif sys.platform == 'darwin':
print('RiVlib library is not available for MacOS')
rieglModule = Extension(name='riegl_rxp',
define_macros=[NUMPY_MACROS],
sources=['src/riegl_rxp.cpp', 'src/pylidar.c'],
include_dirs=[os.path.join(rivlibRoot, 'include'), numpy.get_include()],
extra_compile_args=cxxFlags,
libraries=rivlibs,
library_dirs=[os.path.join(rivlibRoot, 'lib')],
runtime_library_dirs=[os.path.join(rivlibRoot, 'lib')])
extModules.append(rieglModule)
else:
print('RIEGL RXP libraries not found.')
print('If installed set $RIVLIB_ROOT to the install location of RiVLib')
def addRieglRDBDriver(extModules, cxxFlags):
"""
Decides if the Riegl RDB driver is to be built. If so
adds the Extension class to extModules.
"""
if 'RDBLIB_ROOT' in os.environ:
print('Building RIEGL RDB Extension...')
rdblibRoot = os.environ['RDBLIB_ROOT']
if sys.platform == 'win32':
rdbLibName = 'rdblib'
else:
rdbLibName = 'rdb'
defines = getRieglRDBLibVersion(rdblibRoot, rdbLibName)
defines.extend([NUMPY_MACROS])
rieglRDBModule = Extension(name='riegl_rdb',
define_macros=defines,
sources=['src/riegl_rdb.cpp', 'src/pylidar.c'],
include_dirs=[os.path.join(rdblibRoot, 'interface', 'c'), numpy.get_include()],
extra_compile_args=cxxFlags,
libraries=[rdbLibName],
library_dirs=[os.path.join(rdblibRoot, 'library')],
runtime_library_dirs=[os.path.join(rdblibRoot, 'library')])
extModules.append(rieglRDBModule)
else:
print('RIEGL RDB libraries not found.')
print('If installed set $RDBLIB_ROOT to the install location of RDBLib')
def getRieglRDBLibVersion(rdbRoot, libname):
"""
Because we cannot distribute the rdblib library, we need
to check that the major version at compile time matches the
version the user has at runtime. We do this by getting the
version now and setting it as a #define. The library can then
use the #define to check at runtime.
Unfortunately the headers don't give us this information.
"""
if sys.platform == 'win32':
libname = os.path.join(rdbRoot, 'library', libname + '.dll')
elif sys.platform == 'darwin':
libname = os.path.join(rdbRoot, 'library', 'lib' + libname + '.dylib')
else:
libname = os.path.join(rdbRoot, 'library', 'lib' + libname + '.so')
rdb = ctypes.cdll.LoadLibrary(libname)
context = ctypes.c_void_p()
logLevel = ctypes.c_char_p(b"NONE")
logPath = ctypes.c_char_p(b"")
rdb.rdb_context_new(ctypes.byref(context), logLevel, logPath)
version = ctypes.c_char_p()
rdb.rdb_library_version(context, ctypes.byref(version))
versionString = version.value
if sys.version_info[0] >= 3:
versionString = versionString.decode()
rdb.rdb_context_delete(ctypes.byref(context))
# versionString is quite specific -something like:
# 2.2.1-2094 (x86_64-linux, Jul 11 2019, 13:10:32)
# we probably don't have to have the exact same string
# so just extract major and minor version numbers
arr = versionString.split('.')
major = arr[0]
minor = arr[1]
return [("RIEGL_RDB_MAJOR", major),
("RIEGL_RDB_MINOR", minor)]
# get any C++ flags
cxxFlags = getExtraCXXFlags()
# External modules
externalModules = []
addRieglRXPDriver(externalModules, cxxFlags)
addRieglRDBDriver(externalModules, cxxFlags)
if len(externalModules) == 0:
print('RiVLib and/or RDBLib not found. Only the LEAF and RDBX (if installed) drivers will be available.')
setup(name='pylidar-tls-canopy',
version=pylidar_tls_canopy.__version__,
author='John Armston',
author_email='[email protected]',
packages=['pylidar_tls_canopy','pylidar_tls_canopy.cmd'],
entry_points={
'console_scripts': [
'pylidar_cartesiangrid = pylidar_tls_canopy.cmd.cartesiangrid:run',
'pylidar_scangrid = pylidar_tls_canopy.cmd.scangrid:run',
'pylidar_sphericalgrid = pylidar_tls_canopy.cmd.sphericalgrid:run',
'pylidar_plantprofile = pylidar_tls_canopy.cmd.plantprofile:run',
'pylidar_voxelization = pylidar_tls_canopy.cmd.voxelization:run',
],
},
ext_modules=externalModules,
description='Tools for canopy gap probability modeling using RIEGL VZ and LEAF TLS measurements',
classifiers=['Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10'
])