Skip to content

Commit

Permalink
Fix libtgvoip headers search
Browse files Browse the repository at this point in the history
  • Loading branch information
bakatrouble committed Mar 29, 2019
1 parent ab3845e commit bcd2e67
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,12 @@
import re
import sys
import platform
import subprocess

import setuptools
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext


def check_libraries():
args = 'gcc -ltgvoip'.split()
out = subprocess.run(args, stderr=subprocess.PIPE).stderr.decode()
match = re.findall(r'cannot find -l(\w+)', out)
if match:
raise RuntimeError(
'libtgvoip was not found.\nFor guide on compiling it please refer to '
'https://pytgvoip.readthedocs.io/en/latest/guides/libtgvoip.html'
)


class get_pybind_include(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
Expand All @@ -55,17 +43,47 @@ def __str__(self):
return pybind11.get_include(self.user)


def find_libtgvoip_headers():
search = [
'/Library/Frameworks/include/tgvoip',
'/usr/local/include/tgvoip',
'/usr/include/tgvoip',
'/sw/include/tgvoip',
'/opt/local/include/tgvoip',
'/opt/csw/include/tgvoip',
'/opt/include/tgvoip',
os.environ.get('TGVOIP_INCLUDE_ROOT', ''),
]
for path in search:
if os.path.exists(path) and os.path.exists(os.path.join(path, 'VoIPController.h')):
return path
raise RuntimeError('libtgvoip headers are not found\nRefer to '
'https://pytgvoip.readthedocs.io/en/latest/guides/libtgvoip.html '
'for guide on building libtgvoip')


ext_modules = [
Extension(
'_tgvoip',
[
'src/_tgvoip.cpp',
'src/_tgvoip_module.cpp',
'src/_tgvoip.cpp',
],
libraries=['tgvoip'],
library_dirs=[
os.environ.get('TGVOIP_LIBRARY_ROOT', ''),
],
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
get_pybind_include(user=True)
get_pybind_include(user=True),
find_libtgvoip_headers(),
],
define_macros=[
('TGVOIP_USE_CALLBACK_AUDIO_IO', '1'),
('WEBRTC_APM_DEBUG_DUMP', '0'),
('WEBRTC_NS_FLOAT', '1'),
('TGVOIP_USE_DESKTOP_DSP', '1'),
],
language='c++'
),
Expand Down Expand Up @@ -111,7 +129,6 @@ def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.c_opts.get(ct, [])
if ct == 'unix':
check_libraries()
opts.append('-DVERSION_INFO="{}"'.format(get_version()))
opts.append(cpp_flag(self.compiler))
if has_flag(self.compiler, '-fvisibility=hidden'):
Expand Down

0 comments on commit bcd2e67

Please sign in to comment.