1
1
2
2
from distutils import sysconfig
3
- from distutils . core import setup
3
+ from setuptools import setup
4
4
from distutils .util import convert_path
5
5
from distutils .command .build import build as DistutilsBuild
6
- from distutils .cmd import Command
6
+ from setuptools .command .install import install as SetuptoolsInstall
7
+ from setuptools import Distribution , Command
7
8
from subprocess import check_call , check_output
8
9
from glob import glob
9
10
import platform
13
14
14
15
###############################################################################
15
16
16
- class VMDBuild ( DistutilsBuild ):
17
- user_options = [
17
+ class VMDDistribution ( Distribution ):
18
+ custom_options = [
18
19
("debug" , None , "Build with debug symbols" ),
19
20
("egl" , None , "Build with support for rendering to an offscreen "
20
21
"EGL buffer. Requires EGL and libOpenGL" ),
21
22
]
23
+ global_options = Distribution .global_options + custom_options
22
24
23
- def initialize_options (self ):
24
- self .debug = False
25
+ def __init__ (self , * args , ** kwargs ):
25
26
self .egl = False
27
+ self .debug = False
28
+ Distribution .__init__ (self , * args , ** kwargs )
29
+
30
+ ###############################################################################
31
+
32
+ class VMDBuild (DistutilsBuild ):
33
+ """ Build VMD library """
34
+
35
+ description = "Build vmd shared library"
36
+ user_options = []
37
+
38
+ def initialize_options (self ):
26
39
DistutilsBuild .initialize_options (self )
27
40
28
41
#==========================================================================
29
42
30
43
def finalize_options (self ):
31
- if self .debug :
32
- print ("Building with debug symbols" )
33
- self .debug = True
34
- if self .egl :
35
- print ("Building with EGL support" )
36
- self .egl = True
37
44
38
45
# If compilers aren't set already, default to GCC
39
46
if not os .environ .get ("CC" ):
@@ -54,16 +61,17 @@ def finalize_options(self):
54
61
os .environ ["LDFLAGS" ] = ""
55
62
56
63
self .libdirs = self ._get_libdirs ()
64
+ self .incdirs = self ._get_incdirs ()
57
65
58
66
DistutilsBuild .finalize_options (self )
59
67
60
68
#==========================================================================
61
69
62
70
def run (self ):
71
+ self .compile_vmd ()
72
+
63
73
# Run original build code
64
74
DistutilsBuild .run (self )
65
- # Setup and run compilation script
66
- self .execute (self .compile_vmd , [], msg = "Compiling VMD" )
67
75
68
76
#==========================================================================
69
77
@@ -120,17 +128,10 @@ def _get_libdirs(pydir=sysconfig.EXEC_PREFIX):
120
128
#==========================================================================
121
129
122
130
@staticmethod
123
- def _find_include_dir (incfile , pydir = sysconfig .EXEC_PREFIX ):
124
- """
125
- Finds the path containing an include file. Starts by searching
126
- $INCLUDE, then whatever system include paths $CC looks in.
127
- If it can't find the file, defaults to "$pydir/include"
128
- """
131
+ def _get_incdirs (pydir = sysconfig .EXEC_PREFIX ):
129
132
130
- # Look in directories specified by $INCLUDE
131
- searchdirs = [d for d in os .environ .get ("INCLUDE" , "" ).split (":" )
132
- if os .path .isdir (d )]
133
133
# Also look in the directories $CC does
134
+ searchdirs = []
134
135
try :
135
136
out = check_output (r"echo | %s -E -Wp,-v - 2>&1 | grep '^\s.*'"
136
137
% os .environ ["CC" ],
@@ -140,11 +141,26 @@ def _find_include_dir(incfile, pydir=sysconfig.EXEC_PREFIX):
140
141
except : pass
141
142
searchdirs .insert (0 , os .path .join (pydir , "include" ))
142
143
144
+ # Also look in directories specified by $INCLUDE
145
+ searchdirs += [d for d in os .environ .get ("INCLUDE" , "" ).split (":" )
146
+ if os .path .isdir (d )]
147
+
148
+ return searchdirs
149
+
150
+ #==========================================================================
151
+
152
+ def _find_include_dir (self , incfile ):
153
+ """
154
+ Finds the path containing an include file. Starts by searching
155
+ $INCLUDE, then whatever system include paths $CC looks in.
156
+ If it can't find the file, defaults to "$pydir/include"
157
+ """
158
+
143
159
# Find the actual file
144
160
incdir = ""
145
161
try :
146
162
out = check_output (["find" , "-H" ]
147
- + searchdirs
163
+ + self . incdirs
148
164
+ ["-maxdepth" , "2" ,
149
165
"-path" , r"*/%s" % incfile ],
150
166
close_fds = True ,
@@ -154,7 +170,6 @@ def _find_include_dir(incfile, pydir=sysconfig.EXEC_PREFIX):
154
170
except : pass
155
171
156
172
if not glob (os .path .join (incdir , incfile )): # Glob allows wildcards
157
- incdir = os .path .join (pydir , "include" , incfile )
158
173
raise RuntimeError ("Could not find include file '%s' in standard "
159
174
"include directories. Update $INCLUDE to include the "
160
175
"directory containing this file, or make sure it is present "
@@ -262,11 +277,6 @@ def set_environment_variables(self, pydir):
262
277
os .environ ["LDFLAGS" ] += " -headerpad_max_install_names"
263
278
os .environ ["LDFLAGS" ] += " -Wl,-rpath,%s" % addir
264
279
265
- addir = sysconfig .get_config_var ("INCLUDEDIR" )
266
- if addir is None : addir = os .path .join (pydir , "include" )
267
- os .environ ["CFLAGS" ] += " -I%s" % addir
268
- os .environ ["CXXFLAGS" ] += " -I%s" % addir
269
-
270
280
# No reliable way to ask for actual available library, so try 8.5 first
271
281
tcllibdir = self ._find_library_dir ("libtcl8.5" , mandatory = False )
272
282
os .environ ["TCLLDFLAGS" ] = "-ltcl8.5"
@@ -315,29 +325,46 @@ def set_environment_variables(self, pydir):
315
325
316
326
# Set extra config variables if requested
317
327
os .environ ["VMDEXTRAFLAGS" ] = ""
318
- if self .debug :
328
+ if self .distribution .debug :
329
+ print ("Building with debug symbols" )
319
330
os .environ ["VMDEXTRAFLAGS" ] += " DEBUG"
320
- if self .egl :
321
- # Find OpenGL headers
322
- oglheaders = set ([" -I%s" % self ._find_include_dir ("GL/gl.h" ),
323
- " -I%s" % self ._find_include_dir ("EGL/egl.h" ),
324
- " -I%s" % self ._find_include_dir ("EGL/eglext.h" )])
325
- os .environ ["CFLAGS" ] += "" .join (oglheaders )
326
- os .environ ["CXXFLAGS" ] += "" .join (oglheaders )
327
331
328
- ogllib = self ._find_library_dir ("libOpenGL" )
329
- os .environ ["LDFLAGS" ] += " -L%s" % ogllib
332
+ #asandir = self._find_library_dir("libasan")
333
+ #os.environ["LDFLAGS"] += " -L%s" % asandir
334
+
335
+ if self .distribution .egl :
336
+ print ("Building with EGL support" )
337
+
338
+ # Find OpenGL headers
339
+ # The -idirafter option means search this include directory
340
+ # after all specified by -I, then all system defaults. This
341
+ # prevents us from pulling in system standard libraries when
342
+ # building for conda
343
+ oglheaders = set ([" -idirafter%s" % self ._find_include_dir ("GL/gl.h" ),
344
+ " -idirafter%s" % self ._find_include_dir ("EGL/egl.h" ),
345
+ " -idirafter%s" % self ._find_include_dir ("EGL/eglext.h" )])
346
+ os .environ ["OGLINC" ] = "" .join (oglheaders )
347
+
348
+ ogllibs = set ([" -L%s" % self ._find_library_dir ("libOpenGL" ),
349
+ " -L%s" % self ._find_library_dir ("libEGL" )])
350
+ os .environ ["OGLLIB" ] = "" .join (ogllibs )
330
351
331
352
os .environ ["VMDEXTRAFLAGS" ] += " EGLPBUFFER"
332
353
354
+ # Add Python include directories
355
+ addir = sysconfig .get_config_var ("INCLUDEDIR" )
356
+ if addir is None : addir = os .path .join (pydir , "include" )
357
+ os .environ ["CFLAGS" ] += " -I%s" % addir
358
+ os .environ ["CXXFLAGS" ] += " -I%s" % addir
359
+
333
360
# Print a summary
334
361
print ("Building with:" )
335
- print (" CC: %s" % os .environ ["CC" ])
336
- print (" CXX: %s" % os .environ ["CXX" ])
337
- print (" LD: %s" % os .environ ["LD" ])
338
- print (" CFLAGS: %s" % os .environ ["CFLAGS" ])
339
- print (" CXXFLAGS: %s" % os .environ ["CXXFLAGS" ])
340
- print (" LDFLAGS: %s" % os .environ ["LDFLAGS" ])
362
+ print (" CC: %s" % os .environ ["CC" ])
363
+ print (" CXX: %s" % os .environ ["CXX" ])
364
+ print (" LD: %s" % os .environ ["LD" ])
365
+ print (" CFLAGS: %s" % os .environ ["CFLAGS" ])
366
+ print (" CXXFLAGS: %s" % os .environ ["CXXFLAGS" ])
367
+ print (" LDFLAGS: %s" % os .environ ["LDFLAGS" ])
341
368
342
369
#==========================================================================
343
370
@@ -377,6 +404,21 @@ def get_vmd_build_target():
377
404
378
405
###############################################################################
379
406
407
+ class VMDInstall (SetuptoolsInstall ):
408
+ """ Installs vmd """
409
+
410
+ def initialize_options (self ):
411
+ SetuptoolsInstall .initialize_options (self )
412
+
413
+ def finalize_options (self ):
414
+ SetuptoolsInstall .finalize_options (self )
415
+
416
+ def run (self ):
417
+ self .run_command ("build" )
418
+ SetuptoolsInstall .run (self )
419
+
420
+ ###############################################################################
421
+
380
422
class VMDTest (Command ):
381
423
user_options = [("pytest-args=" , "a" , "Arguments to pass to pytest" )]
382
424
@@ -401,9 +443,11 @@ def run(self):
401
443
url = 'http://github.com/Eigenstate/vmd-python' ,
402
444
license = 'VMD License' ,
403
445
packages = ['vmd' ],
404
- package_data = {'vmd' : ['vmd.so' ]},
446
+ package_data = {'vmd' : ['libvmd.so' ]},
447
+ distclass = VMDDistribution ,
405
448
cmdclass = {
406
449
'build' : VMDBuild ,
450
+ 'install' : VMDInstall ,
407
451
'test' : VMDTest ,
408
452
},
409
453
)
0 commit comments