File tree Expand file tree Collapse file tree 6 files changed +33
-14
lines changed Expand file tree Collapse file tree 6 files changed +33
-14
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ option(QIREE_BUILD_TESTS "Build QIR-EE unit tests" ON)
3838option (QIREE_BUILD_EXAMPLES "Build QIR-EE examples" OFF )
3939option (QIREE_USE_QSIM "Download and build Google qsim backend" OFF )
4040option (QIREE_USE_XACC "Build XACC interface" ON )
41+ option (QIREE_SHARED_LIBS "Build shared libraries, not static libraries" ON )
4142
4243qiree_set_default(BUILD_TESTING ${QIREE_BUILD_TESTS} )
4344
@@ -77,10 +78,10 @@ qiree_set_default(CMAKE_CXX_EXTENSIONS OFF)
7778
7879### Linking flags ###
7980# Default to building shared libraries (*not* a cache variable)
80- qiree_set_default(BUILD_SHARED_LIBS ON )
81+ qiree_set_default(BUILD_SHARED_LIBS ${QIREE_SHARED_LIBS} )
8182# Inform installed binaries of external library rpaths
8283qiree_set_default(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON )
83- if (BUILD_SHARED_LIBS )
84+ if (QIREE_SHARED_LIBS )
8485 # Inform installed binaries of internal library rpaths
8586 qiree_set_default(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR} " )
8687 # Do not relink libs/binaries when dependent shared libs change
Original file line number Diff line number Diff line change 1313 "binaryDir" : " ${sourceDir}/build-${presetName}" ,
1414 "generator" : " Ninja" ,
1515 "cacheVariables" : {
16- "BUILD_SHARED_LIBS" : {
17- "type" : " BOOL" ,
18- "value" : " ON"
19- },
2016 "CMAKE_BUILD_TYPE" : {
2117 "type" : " STRING" ,
2218 "value" : " Debug"
Original file line number Diff line number Diff line change @@ -12,7 +12,15 @@ if(QIREE_USE_QSIM)
1212 list (APPEND _CQIREE_LIBS QIREE::qirqsim)
1313endif ()
1414
15- qiree_add_library(cqiree
15+ if (QIREE_SHARED_LIBS)
16+ # When building with shared libs, this should be a shared library that can
17+ # be dlopen()'d.
18+ set (_LIB_TYPE MODULE)
19+ else ()
20+ set (_LIB_TYPE)
21+ endif ()
22+
23+ qiree_add_library(cqiree ${_LIB_TYPE}
1624 CQiree.cc
1725 QireeManager.cc
1826)
Original file line number Diff line number Diff line change 1212#cmakedefine01 QIREE_DEBUG
1313#cmakedefine01 QIREE_USE_QSIM
1414#cmakedefine01 QIREE_USE_XACC
15+ #cmakedefine01 QIREE_SHARED_LIBS
1516
1617#endif /* qiree_config_h */
Original file line number Diff line number Diff line change @@ -69,7 +69,13 @@ qiree_add_test(qiree ResultDistribution)
6969#---------------------------------------------------------------------------##
7070
7171qiree_add_test(cqiree CQiree)
72- add_dependencies (cqiree_CQireeTest cqiree)
72+ if (QIREE_SHARED_LIBS)
73+ # Tester uses dlopen()
74+ add_dependencies (cqiree_CQireeTest cqiree)
75+ else ()
76+ # Statically link tester with cqiree
77+ target_link_libraries (cqiree_CQireeTest cqiree)
78+ endif ()
7379
7480#---------------------------------------------------------------------------##
7581# QIRXACC TESTS
Original file line number Diff line number Diff line change 1515#include < vector>
1616#include < dlfcn.h>
1717
18+ #include " qiree_config.h"
1819#include " qiree_targets.h"
1920
2021#include " qiree/Assert.hh"
@@ -44,15 +45,21 @@ class CQireeTest : public ::qiree::test::Test
4445 protected:
4546 void SetUp () override
4647 {
48+ #if QIREE_SHARED_LIBS
4749 lib_handle_ = dlopen (cqiree_library_path, RTLD_LAZY);
4850 ASSERT_NE (lib_handle_, nullptr )
4951 << " Failed to load libcqiree: " << dlerror ();
50-
51- #define LOAD_FUNCPTR (FUNC ) \
52- FUNC##_fn_ = reinterpret_cast <qiree_##FUNC##_t>( \
53- dlsym (lib_handle_, " qiree_" #FUNC)); \
54- ASSERT_NE (FUNC##_fn_, nullptr ) \
55- << " Failed to load " << #FUNC << " : " << dlerror ();
52+ #endif
53+
54+ #if QIREE_SHARED_LIBS
55+ # define LOAD_FUNCPTR (FUNC ) \
56+ FUNC##_fn_ = reinterpret_cast <qiree_##FUNC##_t>( \
57+ dlsym (lib_handle_, " qiree_" #FUNC)); \
58+ ASSERT_NE (FUNC##_fn_, nullptr ) \
59+ << " Failed to load " << #FUNC << " : " << dlerror ();
60+ #else
61+ # define LOAD_FUNCPTR (FUNC ) FUNC##_fn_ = qiree_##FUNC;
62+ #endif
5663 LOAD_FUNCPTR (create);
5764 LOAD_FUNCPTR (load_module_from_memory);
5865 LOAD_FUNCPTR (load_module_from_file);
You can’t perform that action at this time.
0 commit comments