Added --use-rpath option to setup.py

This commit is contained in:
Federico Di Gregorio 2015-12-04 11:21:55 +01:00
parent 452fd56e04
commit 1dffca2929

View File

@ -236,10 +236,12 @@ class psycopg_build_ext(build_ext):
"Compile with OpenSSL built PostgreSQL libraries (Windows only)."), "Compile with OpenSSL built PostgreSQL libraries (Windows only)."),
('static-libpq', None, ('static-libpq', None,
"Statically link the PostgreSQL client library"), "Statically link the PostgreSQL client library"),
('use-rpath', None,
"Set -rpath to the runtime location of libpq as given by pg_config")
]) ])
boolean_options = build_ext.boolean_options[:] boolean_options = build_ext.boolean_options[:]
boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq')) boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq', 'use-rpath'))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
build_ext.__init__(self, *args, **kwargs) build_ext.__init__(self, *args, **kwargs)
@ -253,6 +255,7 @@ class psycopg_build_ext(build_ext):
self.have_ssl = have_ssl self.have_ssl = have_ssl
self.static_libpq = static_libpq self.static_libpq = static_libpq
self.pg_config = None self.pg_config = None
self.use_rpath = 0
def compiler_is_msvc(self): def compiler_is_msvc(self):
return self.get_compiler_name().lower().startswith('msvc') return self.get_compiler_name().lower().startswith('msvc')
@ -387,6 +390,8 @@ class psycopg_build_ext(build_ext):
os.path.join(pg_config_helper.query("libdir"), "libpq.a")) os.path.join(pg_config_helper.query("libdir"), "libpq.a"))
else: else:
self.libraries.append("pq") self.libraries.append("pq")
if self.use_rpath:
self.rpath = [pg_config_helper.query("libdir")]
try: try:
self.library_dirs.append(pg_config_helper.query("libdir")) self.library_dirs.append(pg_config_helper.query("libdir"))
@ -441,6 +446,13 @@ class psycopg_build_ext(build_ext):
if hasattr(self, "finalize_" + sys.platform): if hasattr(self, "finalize_" + sys.platform):
getattr(self, "finalize_" + sys.platform)() getattr(self, "finalize_" + sys.platform)()
def build_extension(self, ext):
# HACK: runtime library dirs are correctly fixed by ccompiler only
# if ext.runtime_library_dirs is None, but the build_ext sets it
# to null.
ext.runtime_library_dirs = None
build_ext.build_extension(self, ext)
def is_py_64(): def is_py_64():
# sys.maxint not available since Py 3.1; # sys.maxint not available since Py 3.1;
# sys.maxsize not available before Py 2.6; # sys.maxsize not available before Py 2.6;