Commit 8b525ba8 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

working on pip install (#23)



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 1260ca26
......@@ -175,6 +175,7 @@ ExternalProject_Add(xacc-python
-DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include #${XACC_INCLUDE_DIR}
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR}
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DFROM_SETUP_PY=${FROM_SETUP_PY}
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
......@@ -196,9 +197,4 @@ INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/eigen" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/rapidjson" DESTINATION include )
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/pybind11" DESTINATION include )
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/bin/" DESTINATION bin PATTERN "bin/*" PERMISSIONS OWNER_EXECUTE)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/include/" DESTINATION include)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/lib/" DESTINATION lib)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/cppus_install/usr/local/share/" DESTINATION share)
#install( DIRECTORY "${CMAKE_BINARY_DIR}/stage/${CMAKE_INSTALL_PREFIX}" DESTINATION .)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/plugins/xacc-install-plugins.py" DESTINATION bin)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/framework/xacc-framework" DESTINATION bin)
......@@ -37,14 +37,10 @@ include_directories(${XACC_ROOT}/tpls/spdlog)
include_directories(${PYTHON_INCLUDE_DIR})
link_directories(${XACC_LIBRARY_DIR})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -O2 -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv")
add_subdirectory(pybind11)
if(APPLE)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)
pybind11_add_module(pyxacc xacc-py.cpp)
add_library(pyxacc SHARED xacc-py.cpp)
SET_TARGET_PROPERTIES(pyxacc PROPERTIES PREFIX "")
set(CppUsLib CppMicroServicesd)
link_directories(${CPPUS_LIBRARY_DIR})
link_directories(${Boost_LIBRARY_DIR})
......@@ -52,7 +48,12 @@ find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(pyxacc ${PYTHON_LIBRARY} xacc xacc-quantum-gate xacc-quantum-aqc ${CppUsLib} ${Boost_LIBRARIES} cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(pyxacc PRIVATE xacc xacc-quantum-gate xacc-quantum-aqc ${CppUsLib} ${Boost_LIBRARIES} cpprest ${OPENSSL_LIBRARIES})
if (FROM_SETUP_PY)
install(TARGETS pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX})
else()
install(TARGETS pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python)
endif()
endif()
pybind11 @ 6d0b4708
Subproject commit 6d0b4708c6eb1be31b943419a73aec00095a2d64
......@@ -7,6 +7,7 @@ import sysconfig
import platform
import subprocess
import multiprocessing
import site
from distutils.version import LooseVersion
from setuptools import setup, Extension, find_packages
......@@ -25,29 +26,6 @@ class CMakeExtension(Extension):
openssl_root_dir = None
class InstallCommand(InstallCommandBase):
user_options = InstallCommandBase.user_options + [
('openssl-dir=', None, 'Specify OPENSSL_ROOT_DIR')
]
def initialize_options(self):
InstallCommandBase.initialize_options(self)
self.openssl_dir = '/usr/local/opt/openssl' if platform.system() == 'Darwin' else '/usr/lib64'
def finalize_options(self):
global openssl_root_dir
print('openssl ', self.openssl_dir)
openssl_root_dir = self.openssl_dir
InstallCommandBase.finalize_options(self)
def run(self):
InstallCommandBase.run(self)
self.do_egg_install()
subdirs = [name for name in os.listdir(self.install_lib)
if os.path.isdir(os.path.join(self.install_lib, name))
and 'xacc-0.1.0' in name and 'egg-info' not in name]
copyfile(env['HOME']+'/.xacc/lib/python/pyxacc.so', self.install_lib+subdirs[0]+'/pyxacc.so')
class CMakeBuild(build_ext):
def run(self):
try:
......@@ -70,9 +48,17 @@ class CMakeBuild(build_ext):
extdir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)))
script_path = os.path.dirname(os.path.realpath(__file__))
install_prefix = script_path + '/' + self.build_lib
print(dir(self))
print(self.build_lib)
cmake_args = ['-DPYTHON_EXECUTABLE=' + sys.executable,
'-DOPENSSL_ROOT_DIR='+openssl_root_dir,
'-DCMAKE_INSTALL_PREFIX='+env['HOME']+'/.xacc']
'-DCMAKE_INSTALL_PREFIX='+install_prefix,
'-DFROM_SETUP_PY=TRUE']
if not openssl_root_dir == None:
cmake_args.append('-DOPENSSL_ROOT_DIR='+openssl_root_dir)
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
......@@ -92,19 +78,46 @@ class CMakeBuild(build_ext):
os.makedirs(self.build_temp)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args,
subprocess.check_call(['cmake', '--build', '.', '--target', 'install'] + build_args,
cwd=self.build_temp)
print() # Add an empty line for cleaner output
class InstallCommand(InstallCommandBase):
user_options = InstallCommandBase.user_options + [
('openssl-dir=', None, 'Specify OPENSSL_ROOT_DIR')
]
def initialize_options(self):
InstallCommandBase.initialize_options(self)
self.openssl_dir = '/usr/local/opt/openssl' if platform.system() == 'Darwin' else '/usr/lib64'
def finalize_options(self):
global openssl_root_dir
openssl_root_dir = self.openssl_dir
InstallCommandBase.finalize_options(self)
def run(self):
InstallCommandBase.run(self)
s = setup(
name='xacc',
version='0.1.0',
author='Alex McCaskey',
author_email='xacc-dev@eclipse.org',
packages=find_packages('python'),
package_dir={'':'python'},
package_data={'':[env['HOME']+'/.xacc/lib/python/pyxacc.so']},
description='Hardware-agnostic quantum programming framework',
long_description='XACC provides a language and hardware agnostic programming framework for hybrid classical-quantum applications.',
scripts=['tools/plugins/xacc-install-plugins.py'],
ext_modules=[CMakeExtension('.')],
cmdclass={'build_ext':CMakeBuild, 'install':InstallCommand},
ext_modules=[CMakeExtension('pyxacc')],
cmdclass={'build_ext':CMakeBuild},# 'install':InstallCommand},
scripts=['tools/framework/xacc-framework'],
zip_safe=False
)
#try:
# import pyxacc as xacc
# xaccLocation = os.path.dirname(os.path.realpath(xacc.__file__))
#
#except:
# pass
......@@ -17,8 +17,14 @@ import os
import subprocess
import multiprocessing
try:
import pyxacc as xacc
except ImportError:
print('Error - cannot import XACC Python Bindings. Exiting')
sys.exit()
def parse_args(args):
parser = argparse.ArgumentParser(description="XACC Plugin Installer.",
parser = argparse.ArgumentParser(description="XACC Framework Utility.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
fromfile_prefix_chars='@')
parser.add_argument("-p", "--plugins", nargs='*', type=str, help="The XACC Plugins to install.", required=True)
......@@ -60,10 +66,13 @@ def mkdir_p(path):
def main(argv=None):
opts = parse_args(sys.argv[1:])
# This python script should be in ${XACC_ROOT}/bin,
# we need to get XACC_ROOT
# pyxacc can be installed in site-packages/xacc-...-egg or
# in ${XACC_DIR}/lib/python, we need to figure out which one
xaccLocation = os.path.dirname(os.path.realpath(xacc.__file__))
if os.path.basename(xaccLocation) == 'python':
xaccLocation = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
print('XACC Install Location = ', xaccLocation)
xacc_cwd = os.getcwd()
cpus = str(multiprocessing.cpu_count())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment