Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix pkg-config handling to make cross-compiling work #4430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def make_extension(name, files, *args, **kwargs):
"""
Make a new extension. Automatically sets include_dirs and
library_dirs to the base directories appropriate for this
platform.
platform when pkg-config is not available.

`name` is the name of the extension.

Expand All @@ -228,14 +228,15 @@ def make_extension(name, files, *args, **kwargs):
`distutils.core.Extension` constructor.
"""
ext = DelayedExtension(name, files, *args, **kwargs)
for dir in get_base_dirs():
include_dir = os.path.join(dir, 'include')
if os.path.exists(include_dir):
ext.include_dirs.append(include_dir)
for lib in ('lib', 'lib64'):
lib_dir = os.path.join(dir, lib)
if os.path.exists(lib_dir):
ext.library_dirs.append(lib_dir)
if not self.has_pkgconfig:
for dir in get_base_dirs():
include_dir = os.path.join(dir, 'include')
if os.path.exists(include_dir):
ext.include_dirs.append(include_dir)
for lib in ('lib', 'lib64'):
lib_dir = os.path.join(dir, lib)
if os.path.exists(lib_dir):
ext.library_dirs.append(lib_dir)
ext.include_dirs.append('.')

return ext
Expand All @@ -252,29 +253,15 @@ def __init__(self):
if sys.platform == 'win32':
self.has_pkgconfig = False
else:
self.set_pkgconfig_path()
status, output = getstatusoutput("pkg-config --help")
self.pkgconfig = os.environ.get('PKG_CONFIG', 'pkg-config')
status, output = getstatusoutput("%s --help" % self.pkgconfig)
self.has_pkgconfig = (status == 0)
if not self.has_pkgconfig:
print("IMPORTANT WARNING:")
print(
" pkg-config is not installed.\n"
" matplotlib may not be able to find some of its dependencies")

def set_pkgconfig_path(self):
pkgconfig_path = sysconfig.get_config_var('LIBDIR')
if pkgconfig_path is None:
return

pkgconfig_path = os.path.join(pkgconfig_path, 'pkgconfig')
if not os.path.isdir(pkgconfig_path):
return

try:
os.environ['PKG_CONFIG_PATH'] += ':' + pkgconfig_path
except KeyError:
os.environ['PKG_CONFIG_PATH'] = pkgconfig_path

def setup_extension(self, ext, package, default_include_dirs=[],
default_library_dirs=[], default_libraries=[],
alt_exec=None):
Expand All @@ -286,7 +273,7 @@ def setup_extension(self, ext, package, default_include_dirs=[],

executable = alt_exec
if self.has_pkgconfig:
executable = 'pkg-config {0}'.format(package)
executable = '%s %s' % (self.pkgconfig, package)

use_defaults = True

Expand Down Expand Up @@ -330,7 +317,7 @@ def get_version(self, package):
return None

status, output = getstatusoutput(
"pkg-config %s --modversion" % (package))
'%s %s --modversion' % (self.pkgconfig, package))
if status == 0:
return output
return None
Expand Down