diff --git a/.clang-format b/.clang-format index d307bbb..6122dd6 100644 --- a/.clang-format +++ b/.clang-format @@ -135,5 +135,8 @@ StatementMacros: - QT_REQUIRE_VERSION TabWidth: 8 UseTab: Never +--- +Language: Json +DisableFormat: true ... # vim: set ft=yaml ts=2 sw=2 : diff --git a/.github/workflows/build-fast.yml b/.github/workflows/build-fast.yml index d8c1fa7..9cdfd1a 100644 --- a/.github/workflows/build-fast.yml +++ b/.github/workflows/build-fast.yml @@ -10,7 +10,7 @@ concurrency: jobs: linux: - name: ${{matrix.runner}}-${{matrix.compiler}}-${{matrix.version}}-llvm${{matrix.llvm}} + name: ${{matrix.runner}}-${{matrix.compiler}}-${{matrix.version}}-${{ matrix.shared && 'shared' || 'static' }}-llvm${{matrix.llvm}} strategy: matrix: include: @@ -18,10 +18,17 @@ jobs: compiler: gcc version: 12 llvm: 14 + shared: true + - runner: jammy + compiler: gcc + version: 12 + llvm: 14 + shared: false - runner: jammy compiler: clang version: 15 llvm: 15 + shared: true runs-on: >- ${{ matrix.runner == 'focal' && 'ubuntu-20.04' || matrix.runner == 'jammy' && 'ubuntu-22.04' @@ -67,6 +74,7 @@ jobs: -DQIREE_BUILD_TESTS:BOOL=ON \ -DQIREE_DEBUG:BOOL=ON \ -DQIREE_USE_XACC:BOOL=OFF \ + -DQIREE_SHARED_LIBS:BOOL=${{ matrix.shared }} \ -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install" \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1987c4d..fdc33e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,8 @@ repos: - id: check-shebang-scripts-are-executable - id: check-json - id: check-yaml + # .clang-format contains multiple documents for different languages + args: ['--allow-multiple-documents'] - id: end-of-file-fixer exclude: '\.(diff|patch)$' - id: trailing-whitespace diff --git a/CMakeLists.txt b/CMakeLists.txt index a8b2ea6..9a95984 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,8 @@ set(QIREE_RUNTIME_OUTPUT_DIRECTORY enable_language(C) # Needed for LLVM find_package(LLVM REQUIRED) if((LLVM_VERSION VERSION_LESS 14) - OR (LLVM_VERSION VERSION_GREATER_EQUAL 21)) - message(WARNING "QIR-EE is only tested with LLVM 14-20: found version ${LLVM_VERSION}") + OR (LLVM_VERSION VERSION_GREATER_EQUAL 22)) + message(WARNING "QIR-EE is only tested with LLVM 14-21: found version ${LLVM_VERSION}") endif() if(QIREE_USE_QSIM) diff --git a/CMakePresets.json b/CMakePresets.json index 8de704f..bc1785c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,10 +13,6 @@ "binaryDir": "${sourceDir}/build-${presetName}", "generator": "Ninja", "cacheVariables": { - "BUILD_SHARED_LIBS": { - "type": "BOOL", - "value": "ON" - }, "CMAKE_BUILD_TYPE": { "type": "STRING", "value": "Debug" diff --git a/README.md b/README.md index da88e2a..8a247d0 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ doc` (user) or `make doxygen` (developer). There are two dependencies for QIR-EE to work properly. Please make sure to download and install the most current versions of: -1. [LLVM](https://releases.llvm.org/) (we have tested versions 14 through 18) +1. [LLVM](https://releases.llvm.org/) (we have tested versions 14 through 21) 2. [XACC](https://github.com/ORNL-QCI/xacc) (repo that is actively maintained -- not the eclipse one; currently required for execution in this version of qir-ee; we recommend setting option `-DQIREE_MINIMAL_BUILD=ON` diff --git a/src/cqiree/CMakeLists.txt b/src/cqiree/CMakeLists.txt index 6304753..f060fd9 100644 --- a/src/cqiree/CMakeLists.txt +++ b/src/cqiree/CMakeLists.txt @@ -12,7 +12,15 @@ if(QIREE_USE_QSIM) list(APPEND _CQIREE_LIBS QIREE::qirqsim) endif() -qiree_add_library(cqiree MODULE +if(BUILD_SHARED_LIBS) + # When building with shared libs, this should be a shared library that can + # be dlopen()'d. + set(_LIB_TYPE MODULE) +else() + set(_LIB_TYPE) +endif() + +qiree_add_library(cqiree ${_LIB_TYPE} CQiree.cc QireeManager.cc ) @@ -28,10 +36,10 @@ target_link_libraries(cqiree #----------------------------------------------------------------------------# # C/C++ source headers -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cqiree" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cqiree" COMPONENT development - FILES_MATCHING REGEX ".*\\.hh$" + FILES_MATCHING REGEX ".*\\.h$" ) #-----------------------------------------------------------------------------# diff --git a/src/cqiree/CQiree.h b/src/cqiree/CQiree.h index dea82f3..1a558f3 100644 --- a/src/cqiree/CQiree.h +++ b/src/cqiree/CQiree.h @@ -7,14 +7,13 @@ //---------------------------------------------------------------------------// #pragma once -#include +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include - /* Opaque pointer to QireeManager */ typedef struct CQiree_s CQiree; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6c90dcb..492eaa6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,7 +69,13 @@ qiree_add_test(qiree ResultDistribution) #---------------------------------------------------------------------------## qiree_add_test(cqiree CQiree) -add_dependencies(cqiree_CQireeTest cqiree) +if(BUILD_SHARED_LIBS) + # Tester uses dlopen() + add_dependencies(cqiree_CQireeTest cqiree) +else() + # Statically link tester with cqiree + target_link_libraries(cqiree_CQireeTest cqiree) +endif() #---------------------------------------------------------------------------## # QIRXACC TESTS diff --git a/test/cqiree/CQiree.test.cc b/test/cqiree/CQiree.test.cc index a2840ae..4496f13 100644 --- a/test/cqiree/CQiree.test.cc +++ b/test/cqiree/CQiree.test.cc @@ -7,6 +7,7 @@ //---------------------------------------------------------------------------// #include "cqiree/CQiree.h" +#include #include #include #include @@ -14,7 +15,9 @@ #include #include +#include "qiree_config.h" #include "qiree_targets.h" +#include "qiree_test_config.h" #include "qiree/Assert.hh" #include "qiree_test.hh" @@ -43,15 +46,21 @@ class CQireeTest : public ::qiree::test::Test protected: void SetUp() override { +#if BUILD_SHARED_LIBS lib_handle_ = dlopen(cqiree_library_path, RTLD_LAZY); ASSERT_NE(lib_handle_, nullptr) << "Failed to load libcqiree: " << dlerror(); - -#define LOAD_FUNCPTR(FUNC) \ - FUNC##_fn_ = reinterpret_cast( \ - dlsym(lib_handle_, "qiree_" #FUNC)); \ - ASSERT_NE(FUNC##_fn_, nullptr) \ - << "Failed to load " << #FUNC << ": " << dlerror(); +#endif + +#if BUILD_SHARED_LIBS +# define LOAD_FUNCPTR(FUNC) \ + FUNC##_fn_ = reinterpret_cast( \ + dlsym(lib_handle_, "qiree_" #FUNC)); \ + ASSERT_NE(FUNC##_fn_, nullptr) \ + << "Failed to load " << #FUNC << ": " << dlerror(); +#else +# define LOAD_FUNCPTR(FUNC) FUNC##_fn_ = qiree_##FUNC; +#endif LOAD_FUNCPTR(create); LOAD_FUNCPTR(load_module_from_memory); LOAD_FUNCPTR(load_module_from_file); diff --git a/test/qiree_test_config.h.in b/test/qiree_test_config.h.in index bc2d42c..b5999f9 100644 --- a/test/qiree_test_config.h.in +++ b/test/qiree_test_config.h.in @@ -9,6 +9,8 @@ #ifndef qiree_test_config_h #define qiree_test_config_h +#cmakedefine01 BUILD_SHARED_LIBS + static char const qiree_source_dir[] = "@QIREE_SOURCE_DIR@"; #endif /* qiree_test_config_h */