Commit c7723d24 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

updating service registry to be more dynamic in its plugin installs


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 6e530237
...@@ -110,6 +110,11 @@ if (OPENMP_FOUND) ...@@ -110,6 +110,11 @@ if (OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif() endif()
find_package(PythonLibs)
if(PYTHONLIBS_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXACC_HAS_PYTHON")
endif()
ExternalProject_Add(xacc-core ExternalProject_Add(xacc-core
DEPENDS cppmicroservices cpprestsdk DEPENDS cppmicroservices cpprestsdk
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xacc SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xacc
...@@ -118,25 +123,29 @@ ExternalProject_Add(xacc-core ...@@ -118,25 +123,29 @@ ExternalProject_Add(xacc-core
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_ROOT=${BOOST_ROOT}
-DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR} -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
-DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR} -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
-DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR} -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR} -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} #-DXACC_HAS_PYTHON=${PYTHONLIBS_FOUND}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} -DXACC_PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} -DXACC_PYTHON_LIBRARIES=${PYTHON_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY} -DPYBIND11_DIR=${CMAKE_SOURCE_DIR}/python/pybind11
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1 BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install # DESTDIR=${CMAKE_BINARY_DIR}/stage INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install # DESTDIR=${CMAKE_BINARY_DIR}/stage
TEST_BEFORE_INSTALL 1 TEST_BEFORE_INSTALL 1
) )
set(XACC_BASE_DIR ${CMAKE_BINARY_DIR}/stage${CMAKE_INSTALL_PREFIX}) #set(XACC_BASE_DIR ${CMAKE_BINARY_DIR}/stage${CMAKE_INSTALL_PREFIX})
set(XACC_INCLUDE_DIR ${XACC_BASE_DIR}/include/xacc) #set(XACC_INCLUDE_DIR ${XACC_BASE_DIR}/include/xacc)
set(XACC_LIBRARY_DIR ${XACC_BASE_DIR}/lib) #set(XACC_LIBRARY_DIR ${XACC_BASE_DIR}/lib)
string (REPLACE ";" " " XACC_Boost_LIBRARIES "${Boost_LIBRARIES}") #string (REPLACE ";" " " XACC_Boost_LIBRARIES "${Boost_LIBRARIES}")
string (REPLACE ";" " " XACC_MPI_INCLUDE_PATHS "${MPI_CXX_INCLUDE_PATH}") #string (REPLACE ";" " " XACC_MPI_INCLUDE_PATHS "${MPI_CXX_INCLUDE_PATH}")
ExternalProject_Add(xacc-quantum ExternalProject_Add(xacc-quantum
DEPENDS xacc-core DEPENDS xacc-core
...@@ -145,22 +154,23 @@ ExternalProject_Add(xacc-quantum ...@@ -145,22 +154,23 @@ ExternalProject_Add(xacc-quantum
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR} -DXACC_ROOT=${CMAKE_CURRENT_SOURCE_DIR}
-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_ROOT=${BOOST_ROOT}
-DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR} -DCPPUS_INCLUDE_DIR=${CppMicroServices_INCLUDE_DIR}
-DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR} -DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
-DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc -DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib -DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR} -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY} -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1 BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
TEST_AFTER_INSTALL 1 TEST_AFTER_INSTALL 1
) )
if(PYTHONLIBS_FOUND)
ExternalProject_Add(xacc-python ExternalProject_Add(xacc-python
DEPENDS xacc-core xacc-quantum DEPENDS xacc-core xacc-quantum
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/python
...@@ -176,6 +186,7 @@ ExternalProject_Add(xacc-python ...@@ -176,6 +186,7 @@ ExternalProject_Add(xacc-python
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR} -DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib #${XACC_LIBRARY_DIR}
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DFROM_SETUP_PY=${FROM_SETUP_PY} -DFROM_SETUP_PY=${FROM_SETUP_PY}
-DXACC_PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR} -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
...@@ -185,12 +196,13 @@ ExternalProject_Add(xacc-python ...@@ -185,12 +196,13 @@ ExternalProject_Add(xacc-python
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
TEST_AFTER_INSTALL 1 TEST_AFTER_INSTALL 1
) )
endif()
# Install the config file for external projects to use # Install the config file for external projects to use
# This is cool, users just add find_package(XACC REQUIRED) to # This is cool, users just add find_package(XACC REQUIRED) to
# their CMake builds, and pass -DXACC_DIR=/path/to/install/xacc # their CMake builds, and pass -DXACC_DIR=/path/to/install/xacc
# and CMake loads include paths, libs, etc # and CMake loads include paths, libs, etc
configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config.cmake") configure_file("${CMAKE_SOURCE_DIR}/cmake/xacc-config.cmake.in" "${CMAKE_BINARY_DIR}/xacc-config.cmake" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/xacc-config.cmake" DESTINATION .) install(FILES "${CMAKE_BINARY_DIR}/xacc-config.cmake" DESTINATION .)
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/xacc/) install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/tests.cmake" DESTINATION share/xacc/)
INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include ) INSTALL( DIRECTORY "${CMAKE_SOURCE_DIR}/tpls/spdlog" DESTINATION include )
......
set (XACC_ROOT "@CMAKE_INSTALL_PREFIX@") # - Config file for XACC
set (XACC_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/cppmicroservices3;@CMAKE_INSTALL_PREFIX@/include/xacc;@CMAKE_INSTALL_PREFIX@/include/quantum/gate;@CMAKE_INSTALL_PREFIX@/include/quantum/aqc;@CMAKE_INSTALL_PREFIX@/include/spdlog;@CMAKE_INSTALL_PREFIX@/include/eigen;@CMAKE_INSTALL_PREFIX@/include/rapidjson/include;@CMAKE_INSTALL_PREFIX@/include;@OPENSSL_INCLUDE_DIR@") # To point to your install of XACC, pass the
set (XACC_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib") # XACC_ROOT flag to your cmake configure.
#
# It defines the following variables
# XACC_INCLUDE_DIRS - include directories for XACC
# XACC_LIBRARIES - libraries to link against
# XACC_LIBRARY_DIR - the XACC library directory
if (NOT XACC_ROOT)
get_filename_component(XACC_ROOT "${CMAKE_CURRENT_LIST_FILE}" PATH)
endif()
set (XACC_INCLUDE_DIRS "${XACC_ROOT}/include/cppmicroservices3;${XACC_ROOT}/include/xacc;${XACC_ROOT}/include/quantum/gate;${XACC_ROOT}/include/quantum/aqc;${XACC_ROOT}/include/spdlog;${XACC_ROOT}/include/eigen;${XACC_ROOT}/include/rapidjson/include;${XACC_ROOT}/include;@OPENSSL_INCLUDE_DIR@")
set (XACC_LIBRARY_DIR "${XACC_ROOT}/lib")
set(CppUsLib CppMicroServicesd) set(CppUsLib CppMicroServicesd)
link_directories("@CMAKE_INSTALL_PREFIX@/lib") link_directories("${XACC_ROOT}/lib")
find_library(cppus_has_d_suffix CppMicroServicesd PATHS @CMAKE_INSTALL_PREFIX@/lib) find_library(cppus_has_d_suffix CppMicroServicesd PATHS ${XACC_ROOT}/lib)
if (NOT cppus_has_d_suffix) if (NOT cppus_has_d_suffix)
set (XACC_LIBRARIES "xacc;xacc-quantum-gate;xacc-quantum-aqc;CppMicroServices;cpprest;@OPENSSL_LIBRARIES@") set (XACC_LIBRARIES "xacc;xacc-quantum-gate;xacc-quantum-aqc;CppMicroServices;cpprest;@OPENSSL_LIBRARIES@")
else() else()
......
...@@ -9,8 +9,8 @@ message(STATUS "C++ version ${CXX_STANDARD} configured.") ...@@ -9,8 +9,8 @@ message(STATUS "C++ version ${CXX_STANDARD} configured.")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
find_package(PythonLibs) #find_package(PythonLibs)
if(PythonLibs_FOUND) #if(PythonLibs_FOUND)
set(CppMicroServices_DIR "${CPPUS_LIBRARY_DIR}/../share/cppmicroservices3/cmake") set(CppMicroServices_DIR "${CPPUS_LIBRARY_DIR}/../share/cppmicroservices3/cmake")
...@@ -34,7 +34,7 @@ include_directories(${XACC_ROOT}/tpls/rapidjson/include) ...@@ -34,7 +34,7 @@ include_directories(${XACC_ROOT}/tpls/rapidjson/include)
include_directories(${XACC_ROOT}/tpls/eigen) include_directories(${XACC_ROOT}/tpls/eigen)
include_directories(${XACC_ROOT}/tpls/pybind11/include) include_directories(${XACC_ROOT}/tpls/pybind11/include)
include_directories(${XACC_ROOT}/tpls/spdlog) include_directories(${XACC_ROOT}/tpls/spdlog)
include_directories(${PYTHON_INCLUDE_DIR}) include_directories(${XACC_PYTHON_INCLUDE_DIR})
link_directories(${XACC_LIBRARY_DIR}) link_directories(${XACC_LIBRARY_DIR})
add_subdirectory(pybind11) add_subdirectory(pybind11)
...@@ -56,4 +56,4 @@ else() ...@@ -56,4 +56,4 @@ else()
install(TARGETS pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python) install(TARGETS pyxacc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python)
endif() endif()
endif() #endif()
...@@ -37,6 +37,10 @@ include_directories("${CMAKE_SOURCE_DIR}/accelerator") ...@@ -37,6 +37,10 @@ include_directories("${CMAKE_SOURCE_DIR}/accelerator")
include_directories("${CMAKE_SOURCE_DIR}/utils") include_directories("${CMAKE_SOURCE_DIR}/utils")
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR}) include_directories(${CMAKE_BINARY_DIR})
include_directories(${PYBIND11_DIR}/include)
#find_package(PythonLibs REQUIRED)
include_directories(${XACC_PYTHON_INCLUDE_DIR})
# Create a xacc config header file # Create a xacc config header file
configure_file("${XACC_ROOT}/cmake/xacc_config.hpp.in" "${CMAKE_BINARY_DIR}/xacc_config.hpp") configure_file("${XACC_ROOT}/cmake/xacc_config.hpp.in" "${CMAKE_BINARY_DIR}/xacc_config.hpp")
...@@ -64,7 +68,7 @@ if (APPLE) ...@@ -64,7 +68,7 @@ if (APPLE)
set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${OPENSSL_CRYPTO_LIBRARY}") set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${OPENSSL_CRYPTO_LIBRARY}")
endif() endif()
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} ${OPENSSL_LIBRARIES} cpprest) target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} ${OPENSSL_LIBRARIES} cpprest ${XACC_PYTHON_LIBRARIES})
# Get the test files # Get the test files
file(GLOB test_files utils/tests/*Tester.cpp accelerator/tests/*Tester.cpp) file(GLOB test_files utils/tests/*Tester.cpp accelerator/tests/*Tester.cpp)
......
#include "ServiceRegistry.hpp" #include "ServiceRegistry.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <pybind11/embed.h>
namespace xacc { namespace xacc {
void ServiceRegistry::initialize() { void ServiceRegistry::initialize() {
if (!initialized) { if (!initialized) {
// XACCLogger::instance()->info("Creating CppUs Framework.");
framework = FrameworkFactory().NewFramework(); framework = FrameworkFactory().NewFramework();
// Initialize the framework, such that we can call // Initialize the framework, such that we can call
// GetBundleContext() later. // GetBundleContext() later.
// XACCLogger::instance()->info("Running Framework.Init.");
framework.Init(); framework.Init();
// XACCLogger::instance()->info("Getting the Framework Bundle Context.");
context = framework.GetBundleContext(); context = framework.GetBundleContext();
if (!context) { if (!context) {
XACCLogger::instance()->error( XACCLogger::instance()->error(
"Invalid XACC Framework plugin context."); "Invalid XACC Framework plugin context.");
} }
const std::string xaccLibDir = std::string(XACC_INSTALL_DIR) + std::string("/lib"); std::string xaccLibDir = "";
#ifdef XACC_HAS_PYTHON
namespace py = pybind11;
auto getInstallDir = []() -> std::string {
auto locals = py::dict();
py::exec(R"(
import os
imported = True
try:
import pyxacc as xacc
except ImportError:
imported = False
if imported:
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__)))
)", py::globals(), locals);
bool foundPythonInstall = locals["imported"].cast<bool>();
if (foundPythonInstall) {
return locals["xaccLocation"].cast<std::string>() + std::string("/lib");
} else {
XACCLogger::instance()->error("ServiceRegistry Error, invalid pyxacc install");
return "";
}
};
if(!Py_IsInitialized()) {
py::scoped_interpreter guard{};
xaccLibDir = getInstallDir();
} else {
xaccLibDir = getInstallDir();
}
#else
xaccLibDir = std::string(XACC_INSTALL_DIR) + std::string("/lib");
#endif
XACCLogger::instance()->enqueueLog("XACC Library Directory: " + xaccLibDir); XACCLogger::instance()->enqueueLog("XACC Library Directory: " + xaccLibDir);
for (auto &entry : boost::filesystem::directory_iterator(xaccLibDir)) { for (auto &entry : boost::filesystem::directory_iterator(xaccLibDir)) {
...@@ -31,6 +64,7 @@ void ServiceRegistry::initialize() { ...@@ -31,6 +64,7 @@ void ServiceRegistry::initialize() {
auto name = entry.path().filename().string(); auto name = entry.path().filename().string();
boost::replace_all(name,"lib",""); boost::replace_all(name,"lib","");
boost::replace_all(name,".so",""); boost::replace_all(name,".so","");
boost::replace_all(name,".dy","");
XACCLogger::instance()->enqueueLog("Installing base plugin " + name); XACCLogger::instance()->enqueueLog("Installing base plugin " + name);
context.InstallBundles(entry.path().string()); context.InstallBundles(entry.path().string());
} }
...@@ -38,8 +72,7 @@ void ServiceRegistry::initialize() { ...@@ -38,8 +72,7 @@ void ServiceRegistry::initialize() {
// Add external plugins... // Add external plugins...
boost::filesystem::directory_iterator end_itr; boost::filesystem::directory_iterator end_itr;
boost::filesystem::path xaccPluginPath( boost::filesystem::path xaccPluginPath(xaccLibDir + std::string("/plugins"));
std::string(XACC_INSTALL_DIR) + std::string("/lib/plugins"));
if (boost::filesystem::exists(xaccPluginPath)) { if (boost::filesystem::exists(xaccPluginPath)) {
for (auto& entry : boost::filesystem::directory_iterator(xaccPluginPath)) { for (auto& entry : boost::filesystem::directory_iterator(xaccPluginPath)) {
auto p = entry.path(); auto p = entry.path();
...@@ -48,6 +81,7 @@ void ServiceRegistry::initialize() { ...@@ -48,6 +81,7 @@ void ServiceRegistry::initialize() {
auto name = subentry.path().filename().string(); auto name = subentry.path().filename().string();
boost::replace_all(name,"lib",""); boost::replace_all(name,"lib","");
boost::replace_all(name,".so",""); boost::replace_all(name,".so","");
boost::replace_all(name,".dy","");
XACCLogger::instance()->enqueueLog("Installing 3rd party plugin " + name); XACCLogger::instance()->enqueueLog("Installing 3rd party plugin " + name);
context.InstallBundles(subentry.path().string()); context.InstallBundles(subentry.path().string());
} }
......
Markdown is supported
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