Skip to content

Commit

Permalink
Build support for openmp/gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Nov 16, 2014
1 parent 1d8eb6a commit 5f1455f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ install:
python setup.py install
python selftest.py --installed

install-openmp:
python setup.py build_ext --enable-openmp install
python selftest.py --installed

test:
python test-installed.py

Expand Down
28 changes: 21 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class pil_build_ext(build_ext):

class feature:
zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = webpmux = None
jpeg2000 = None
jpeg2000 = openmp = None
required = []

def require(self, feat):
Expand Down Expand Up @@ -136,6 +136,7 @@ def initialize_options(self):

def finalize_options(self):
build_ext.finalize_options(self)
self.feature.openmp = False
for x in self.feature:
if getattr(self, 'disable_%s' % x):
setattr(self.feature, x, False)
Expand All @@ -152,7 +153,8 @@ def build_extensions(self):

library_dirs = []
include_dirs = []

extra_compile_args = []

_add_directory(include_dirs, "libImaging")

#
Expand Down Expand Up @@ -500,8 +502,14 @@ def build_extensions(self):
_find_library_file(self, "libwebpdemux")):
feature.webpmux = "libwebpmux"

if feature.require('openmp'):
extra_compile_args.append('-fopenmp')
feature.openmp = 'gomp'

for f in feature:
if not getattr(feature, f) and feature.require(f):
print (feature, f, getattr(feature,f))
print (feature.require(f))
raise ValueError(
'--enable-%s requested but %s not found, aborting.'
% (f, f))
Expand Down Expand Up @@ -535,9 +543,11 @@ def build_extensions(self):
libs.extend(["kernel32", "user32", "gdi32"])
if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
defs.append(("WORDS_BIGENDIAN", None))
if feature.openmp:
libs.append(feature.openmp)

exts = [(Extension(
"PIL._imaging", files, libraries=libs, define_macros=defs))]
exts = [(Extension("PIL._imaging", files, libraries=libs,
define_macros=defs, extra_compile_args=extra_compile_args))]

#
# additional libraries
Expand Down Expand Up @@ -603,10 +613,12 @@ def build_extensions(self):
libraries=[feature.tcl, feature.tk]))

if os.path.isfile("_imagingmath.c"):
exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))
exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"],
extra_compile_args=extra_compile_args))

if os.path.isfile("_imagingmorph.c"):
exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"]))
exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"],
extra_compile_args=extra_compile_args))

self.extensions[:] = exts

Expand Down Expand Up @@ -644,7 +656,9 @@ def summary_report(self, feature, unsafe_zlib):
(feature.freetype, "FREETYPE2"),
(feature.lcms, "LITTLECMS2"),
(feature.webp, "WEBP"),
(feature.webpmux, "WEBPMUX"), ]
(feature.webpmux, "WEBPMUX"),
(feature.openmp, "OpenMP"),
]

all = 1
for option in options:
Expand Down

0 comments on commit 5f1455f

Please sign in to comment.