Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from HQSquantumsimulations/develop
Browse files Browse the repository at this point in the history
Fixing build on macos
  • Loading branch information
nfwvogt authored Aug 20, 2020
2 parents 77e5aa4 + a3843d7 commit 3b8ad04
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 402 deletions.
6 changes: 5 additions & 1 deletion build_quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
import ctypes
from cffi import FFI
import os
import platform

def build_quest_so():
lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pyquest_cffi/questlib/')
quest_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "QuEST/QuEST")
questlib = os.path.join(lib_path, "libQuEST.so")
if platform.system() == 'Darwin':
questlib = os.path.join(lib_path, "libQuEST.dylib")
else:
questlib = os.path.join(lib_path, "libQuEST.so")
include = [os.path.join(quest_path, "include")]

_questlib = ctypes.CDLL(questlib)
Expand Down
24 changes: 22 additions & 2 deletions pyquest_cffi/questlib/build_quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import ctypes
from cffi import FFI
import os
import platform
import subprocess


def build_quest_so() -> None:
Expand All @@ -26,7 +28,11 @@ def build_quest_so() -> None:
"""
lib_path = os.path.dirname(os.path.realpath(__file__))
quest_path = os.path.join(lib_path, "../../QuEST/QuEST")
questlib = os.path.join(lib_path, "libQuEST.so")

if platform.system() == 'Darwin':
questlib = os.path.join(lib_path, "libQuEST.dylib")
else:
questlib = os.path.join(lib_path, "libQuEST.so")
include = [os.path.join(quest_path, "include")]

_questlib = ctypes.CDLL(questlib)
Expand Down Expand Up @@ -86,7 +92,21 @@ def build_quest_so() -> None:
extra_link_args=['-Wl,-rpath,$ORIGIN'],
# extra_link_args=['-Wl,-rpath={}'.format(lib_path)],
)
ffibuilder.compile(verbose=True)
# For working import also under macos target must produce .so library
ffibuilder.compile(target = '_quest.so', verbose=True)

#Setting relative paths in libraries
if platform.system() == 'Darwin':
librun = subprocess.run(['otool', '-L', os.path.join(lib_path, '_quest.so')],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
libraries_text = librun.stdout.split('\n')
for line in libraries_text:
if 'libQuEST.dylib' in line:
pathname = line.strip().split('/libQuEST.dylib')[0]
break
subprocess.run(['install_name_tool', '-change',
os.path.join(pathname, 'libQuEST.dylib'), '@loader_path/libQuEST.dylib',
os.path.join(lib_path, '_quest.so')], check=True)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 3b8ad04

Please sign in to comment.