Skip to content

Commit 77b6011

Browse files
committed
Merge branch 'egl'
2 parents fbe8e98 + 9e56d6c commit 77b6011

File tree

4 files changed

+142
-54
lines changed

4 files changed

+142
-54
lines changed

setup.py

Lines changed: 91 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
from distutils import sysconfig
3-
from distutils.core import setup
3+
from setuptools import setup
44
from distutils.util import convert_path
55
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
78
from subprocess import check_call, check_output
89
from glob import glob
910
import platform
@@ -13,27 +14,33 @@
1314

1415
###############################################################################
1516

16-
class VMDBuild(DistutilsBuild):
17-
user_options = [
17+
class VMDDistribution(Distribution):
18+
custom_options = [
1819
("debug", None, "Build with debug symbols"),
1920
("egl", None, "Build with support for rendering to an offscreen "
2021
"EGL buffer. Requires EGL and libOpenGL"),
2122
]
23+
global_options = Distribution.global_options + custom_options
2224

23-
def initialize_options(self):
24-
self.debug = False
25+
def __init__(self, *args, **kwargs):
2526
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):
2639
DistutilsBuild.initialize_options(self)
2740

2841
#==========================================================================
2942

3043
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
3744

3845
# If compilers aren't set already, default to GCC
3946
if not os.environ.get("CC"):
@@ -54,16 +61,17 @@ def finalize_options(self):
5461
os.environ["LDFLAGS"] = ""
5562

5663
self.libdirs = self._get_libdirs()
64+
self.incdirs = self._get_incdirs()
5765

5866
DistutilsBuild.finalize_options(self)
5967

6068
#==========================================================================
6169

6270
def run(self):
71+
self.compile_vmd()
72+
6373
# Run original build code
6474
DistutilsBuild.run(self)
65-
# Setup and run compilation script
66-
self.execute(self.compile_vmd, [], msg="Compiling VMD")
6775

6876
#==========================================================================
6977

@@ -120,17 +128,10 @@ def _get_libdirs(pydir=sysconfig.EXEC_PREFIX):
120128
#==========================================================================
121129

122130
@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):
129132

130-
# Look in directories specified by $INCLUDE
131-
searchdirs = [d for d in os.environ.get("INCLUDE", "").split(":")
132-
if os.path.isdir(d)]
133133
# Also look in the directories $CC does
134+
searchdirs = []
134135
try:
135136
out = check_output(r"echo | %s -E -Wp,-v - 2>&1 | grep '^\s.*'"
136137
% os.environ["CC"],
@@ -140,11 +141,26 @@ def _find_include_dir(incfile, pydir=sysconfig.EXEC_PREFIX):
140141
except: pass
141142
searchdirs.insert(0, os.path.join(pydir, "include"))
142143

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+
143159
# Find the actual file
144160
incdir = ""
145161
try:
146162
out = check_output(["find", "-H"]
147-
+ searchdirs
163+
+ self.incdirs
148164
+ ["-maxdepth", "2",
149165
"-path", r"*/%s" % incfile],
150166
close_fds=True,
@@ -154,7 +170,6 @@ def _find_include_dir(incfile, pydir=sysconfig.EXEC_PREFIX):
154170
except: pass
155171

156172
if not glob(os.path.join(incdir, incfile)): # Glob allows wildcards
157-
incdir = os.path.join(pydir, "include", incfile)
158173
raise RuntimeError("Could not find include file '%s' in standard "
159174
"include directories. Update $INCLUDE to include the "
160175
"directory containing this file, or make sure it is present "
@@ -262,11 +277,6 @@ def set_environment_variables(self, pydir):
262277
os.environ["LDFLAGS"] += " -headerpad_max_install_names"
263278
os.environ["LDFLAGS"] += " -Wl,-rpath,%s" % addir
264279

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-
270280
# No reliable way to ask for actual available library, so try 8.5 first
271281
tcllibdir = self._find_library_dir("libtcl8.5", mandatory=False)
272282
os.environ["TCLLDFLAGS"] = "-ltcl8.5"
@@ -315,29 +325,46 @@ def set_environment_variables(self, pydir):
315325

316326
# Set extra config variables if requested
317327
os.environ["VMDEXTRAFLAGS"] = ""
318-
if self.debug:
328+
if self.distribution.debug:
329+
print("Building with debug symbols")
319330
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)
327331

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)
330351

331352
os.environ["VMDEXTRAFLAGS"] += " EGLPBUFFER"
332353

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+
333360
# Print a summary
334361
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"])
341368

342369
#==========================================================================
343370

@@ -377,6 +404,21 @@ def get_vmd_build_target():
377404

378405
###############################################################################
379406

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+
380422
class VMDTest(Command):
381423
user_options = [("pytest-args=", "a", "Arguments to pass to pytest")]
382424

@@ -401,9 +443,11 @@ def run(self):
401443
url='http://github.com/Eigenstate/vmd-python',
402444
license='VMD License',
403445
packages=['vmd'],
404-
package_data={'vmd' : ['vmd.so']},
446+
package_data={'vmd' : ['libvmd.so']},
447+
distclass=VMDDistribution,
405448
cmdclass={
406449
'build': VMDBuild,
450+
'install': VMDInstall,
407451
'test': VMDTest,
408452
},
409453
)

vmd/install.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ rm $vmd_src/vmd_src/plugins
6262
# Copy init.py file into build directory
6363
cp "$vmd_src/vmd_src/__init__.py" "$VMDDIR"
6464

65+
# Add additional info to __init__.py if necessary
66+
if [[ $VMDEXTRAFLAGS == *"DEBUG"* ]]; then
67+
echo "vmd._debug = True" >> "$VMDDIR/__init__.py"
68+
else
69+
echo "vmd._debug = False" >> "$VMDDIR/__init__.py"
70+
fi
71+
72+
if [[ $VMDEXTRAFLAGS == *"EGLPBUFFER"* ]]; then
73+
echo "vmd._egl = True" >> "$VMDDIR/__init__.py"
74+
else
75+
echo "vmd._egl = False" >> "$VMDDIR/__init__.py"
76+
fi
77+
6578
# Copy tests into build directory so they're accessible
6679
cp -r "$vmd_src/../test" "$VMDDIR"
6780

vmd/plugins/Make-arch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ LINUXAMD64:
4242
"RANLIB = touch" \
4343
"SHLD = $(CC) -shared"
4444

45+
LINUXPPC64:
46+
$(MAKE) dynlibs staticlibs bins \
47+
"ARCH = LINUXPPC64" \
48+
"CC = $(CC)" \
49+
"CXX = $(CXX)" \
50+
"COPTO = -fPIC -m64 -o " \
51+
"LOPTO = -fPIC -m64 $(LDFLAGS) -o " \
52+
"DEF = -D" \
53+
"CCFLAGS = $(CFLAGS) -m64 -O2 -fPIC -Wall" \
54+
"CXXFLAGS = $(CXXFLAGS) -m64 -O2 -fPIC -Wall" \
55+
"TCLLDFLAGS = $(TCLLDFLAGS)" \
56+
"NETCDFLDFLAGS = $(NETCDFLDFLAGS)" \
57+
"AR = $(AR)" \
58+
"NM = $(NM) -p" \
59+
"RANLIB = touch" \
60+
"SHLD = $(CC) -shared"
61+
4562
MACOSX:
4663
$(MAKE) dynlibs staticlibs bins \
4764
"ARCH = MACOSX" \

vmd/vmd_src/configure

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,13 @@ $vulkan_defines = "-DVMDOPENGL";
562562
# OpenGL libraries. Note that these options require -I and -L in front of
563563
# the include and library directory names
564564
$opengl_dep_dir = "";
565-
$opengl_dep_include = "";
565+
$opengl_dep_include = $ENV{"OGLINC"};
566566
$opengl_dep_library = "";
567567
if ($config_opengl_dispatch) {
568568
# version of OpenGL libs that can do dispatch, allowing use of
569569
# EGL for window management, but full GL or GLES etc for drawing
570570
# as appropriate
571-
$opengl_dep_libs = "-lOpenGL";
571+
$opengl_dep_libs = $ENV{"OGLLIB"} . " -lOpenGL";
572572
} else {
573573
#$opengl_dep_libs = "-lGL -lGLU";
574574
$opengl_dep_libs = "-lGL";
@@ -636,7 +636,7 @@ $opengl_pbuffer_defines = "-DVMDOPENGLPBUFFER -DVMDGLXPBUFFER";
636636
# EGL OpenGL Pbuffer off-screen graphics rendering context
637637
#
638638
$egl_pbuffer_dir = "";
639-
$egl_pbuffer_include = "";
639+
$egl_pbuffer_include = $ENV{"OGLINC"};
640640
$egl_pbuffer_library = "";
641641
$egl_pbuffer_libs = "-lEGL";
642642
$egl_pbuffer_defines = "-DVMDOPENGLPBUFFER -DVMDEGLPBUFFER";
@@ -1074,6 +1074,19 @@ if ($config_opengl) {
10741074
$liboptix_defines = "-DVMDLIBOPTIX ";
10751075
}
10761076

1077+
################ DEBUG
1078+
# OPTIONAL COMPONENT: Debug output
1079+
#$debug_libs = "-lasan";
1080+
$debug_libs = "";
1081+
$debug_defines = "-DPYDEBUG";
1082+
$debug_dir = "";
1083+
$debug_include = "";
1084+
$debug_library = "";
1085+
@debug_cc = ();
1086+
@debug_cu = ();
1087+
@debug_ccpp = ();
1088+
@debug_h = ();
1089+
10771090
# Standard builds
10781091
# $liboptix_dir = "/usr/local/encap/NVIDIA-OptiX-SDK-3.6.3-linux64";
10791092
# $liboptix_dir = "/usr/local/encap/NVIDIA-OptiX-SDK-3.8.0-linux64";
@@ -1906,7 +1919,7 @@ if ($config_arch eq "LINUX") {
19061919
$arch_shlibname = "so";
19071920
$arch_shcppopts = "-fPIC";
19081921
$arch_shldopts = "";
1909-
$arch_opt_flag .= "-m32 -fno-for-scope -Wno-deprecated -Wall -Wno-unknown-pragmas -O3";
1922+
$arch_opt_flag .= "-m32 -Wno-deprecated -Wall -Wno-unknown-pragmas -O3";
19101923
$arch_copts .= "-m32 -Wall -Wno-unknown-pragmas -O3";
19111924

19121925
if ($config_static) {
@@ -1963,14 +1976,14 @@ if ($config_arch eq "LINUXAMD64") {
19631976
print "LP64 ABI is already the default on this platform.\n";
19641977
}
19651978

1966-
$arch_opt_flag .= " -m64 -fno-for-scope -Wno-deprecated -Wall -Wno-unknown-pragmas -ffast-math";
1979+
$arch_opt_flag .= " -m64 -Wno-deprecated -Wall -Wno-unknown-pragmas -ffast-math";
19671980
$arch_depend_flag .= " -MM";
19681981
$arch_copts .= " -m64 -Wall -Wno-unknown-pragmas -ffast-math";
19691982

19701983
if ($config_debug) {
19711984
$arch_opt_flag .= " -g -Og";
1972-
$arch_copts .= " -fsanitize=address -g -Og -DPYDEBUG";
1973-
$arch_lopts .= " -lasan";
1985+
$arch_copts .= " -g -Og";
1986+
$arch_cppopts .= " -g -Og";
19741987
} else {
19751988
$arch_opt_flag .= " -O3";
19761989
$arch_copts .= " -O3";
@@ -2416,6 +2429,7 @@ END_OF_IF
24162429

24172430
$if_statements = '';
24182431

2432+
$if_statements .= &create_config_option('debug');
24192433
$if_statements .= &create_config_option('vulkan');
24202434
$if_statements .= &create_config_option('opengl');
24212435
$if_statements .= &create_config_option('opengl_pbuffer');

0 commit comments

Comments
 (0)