Skip to content

Commit

Permalink
Fixes when building from source
Browse files Browse the repository at this point in the history
  • Loading branch information
gvinciguerra committed Jul 10, 2020
1 parent a77e891 commit 7caece2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include PGM-Index/include/piecewise_linear_model.hpp
include PGM-Index/include/pgm_index.hpp
include PGM-index/include/piecewise_linear_model.hpp
include PGM-index/include/pgm_index.hpp
69 changes: 45 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import glob
import os
import subprocess
import sys
import tempfile

import setuptools
from setuptools.command.build_ext import build_ext


__version__ = '0.1'
__version__ = '0.1.dev3'


class get_pybind_include(object):
Expand Down Expand Up @@ -41,13 +42,6 @@ def has_flag(compiler, flag):
]


def box_msg(msg):
"""Create an ASCII box around a string."""
row = len(msg)
h = ''.join(['+'] + ['-' * row] + ['+'])
return h + '\n'"|" + msg + "|"'\n' + h


def is_clang(bin):
"""Check whether the compiler is clang."""
output = subprocess.check_output([bin, '-v'], stderr=subprocess.STDOUT)
Expand All @@ -61,37 +55,51 @@ def build_extensions(self):
comp_args = ['-std=c++17', '-O3', '-fvisibility=hidden']
link_args = []

print('is_clang', is_clang(self.compiler.compiler[0]))
if sys.platform == 'darwin' and is_clang(self.compiler.compiler[0]):
omp = '/usr/local/opt/libomp'
if self.compiler.find_library_file([omp + '/lib'], 'omp') is None:
sys.exit(box_msg('OpenMP is needed. Run brew install libomp'))
comp_args += ['-Xpreprocessor',
'-fopenmp',
'-mmacosx-version-min=10.9',
'-I%s/include/' % omp]
link_args += ['-L%s/lib' % omp,
'-lomp',
'-mmacosx-version-min=10.9']
else:
omp_lib = self.compiler.find_library_file([omp + '/lib'], 'omp')
if omp_lib is not None:
print('libomp found on macOS')
comp_args += ['-Xpreprocessor',
'-fopenmp',
'-I%s/include/' % omp]
link_args += ['-L%s/lib' % omp,
'-lomp']
comp_args += ['-mmacosx-version-min=10.9']
link_args += ['-mmacosx-version-min=10.9']
elif has_flag(self.compiler, '-fopenmp'):
comp_args += ['-fopenmp']
link_args += ['-fopenmp']

for ext in self.extensions:
ext.extra_compile_args = comp_args
ext.extra_link_args = link_args

build_ext.build_extensions(self)


if sys.version_info[:2] < (3, 3):
raise RuntimeError("Python version >= 3.3 required.")

if 'CXX' not in os.environ:
path = os.getenv('PATH').split(os.path.pathsep)
globs = [os.path.join(p, 'g++*') for p in path]
gccs = [g for p in globs for g in glob.glob(p)]
gccs = sorted(gccs, key=lambda p: os.path.basename(p))
if len(gccs) > 0:
os.environ["CC"] = gccs[-1]
os.environ["CXX"] = gccs[-1]
print('Found GCC in ', gccs[-1])

setuptools.setup(
name='pypgm',
version=__version__,
author='Giorgio Vinciguerra',
author_email='i@gvdev.com',
url='https://github.com/gvinciguerra/PyPGM',
license='GPL-3.0',
description=('Sorted containers with efficient query performance'
'and memory usage'),
description=('Sorted containers with state-of-the-art query performance '
'and compressed memory usage'),
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
ext_modules=ext_modules,
Expand All @@ -100,17 +108,30 @@ def build_extensions(self):
cmdclass={'build_ext': BuildExt},
zip_safe=False,
classifiers=[
'License :: OSI Approved :: GPL-3.0 License',
'Development Status :: 2 - Pre-Alpha',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Programming Language :: C++',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Database',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Software Development',
'Topic :: System',
'Topic :: System :: Archiving :: Compression',
'Topic :: Utilities',
],
keywords=('tree list array btree b+tree vector skiplist container '
'sortedlist sorted set query index data structure'),
Expand Down

0 comments on commit 7caece2

Please sign in to comment.