From 5f27ae721ec83dbdceb5aca184dff5a0098038fa Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Thu, 23 May 2024 17:50:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20make=20GMP=20dependency=20opt-in?= =?UTF-8?q?=20instead=20of=20used-if-found=20(#608)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This PR changes the CMake configuration so that GMP, which can be used in the ZX library, needs to be explicitly added (opt-in) instead of automatically being used (actually unconditionally, without an opt-out option). This has popped up in https://github.com/cda-tum/mqt-qcec/pull/396 since `delocate` fails to properly repair the produced wheel. This is a result of `gmp` being automatically installed on macOS runners via brew. However, this gets the latest system version, which is not compatible with the minimum macOS targets that we set. I believe this only popped up now, because there has been a `delocate` update that catches this. In lack of a better option at the moment, this PR makes GMP support entirely opt-in, which disables it for wheel builds and resolves the underlying issue. Anyone that wants to build MQT Core with GMP support, can now configure CMake with `-DMQT_CORE_WITH_GMP` In the future, it might be worth investigating whether there is a better way to do this, e.g., by manually building `gmp` with the required compatibility. ## Checklist: - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines. Signed-off-by: burgholzer --- .github/workflows/ci.yml | 2 ++ cmake/mqt-core-config.cmake.in | 5 ++--- src/CMakeLists.txt | 2 +- src/zx/CMakeLists.txt | 13 ++++--------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 702dc3c36..6130e9893 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,8 @@ jobs: needs: change-detection if: fromJSON(needs.change-detection.outputs.run-cpp-tests) uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-ci.yml@v1.0.0 + with: + cmake-args-macos: -DMQT_CORE_WITH_GMP=ON secrets: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/cmake/mqt-core-config.cmake.in b/cmake/mqt-core-config.cmake.in index 55575a49c..9666f5068 100644 --- a/cmake/mqt-core-config.cmake.in +++ b/cmake/mqt-core-config.cmake.in @@ -6,9 +6,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") include(CMakeFindDependencyMacro) find_dependency(nlohmann_json) -option(MQT_CORE_ZX_WITH_GMP "Library is configured to use GMP for ZX calculations" - @MQT_CORE_ZX_WITH_GMP@) -if(MQT_CORE_ZX_WITH_GMP) +option(MQT_CORE_WITH_GMP "Library is configured to use GMP" @MQT_CORE_WITH_GMP@) +if(MQT_CORE_WITH_GMP) find_dependency(GMP) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 526f2035c..e0516a00a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -184,7 +184,7 @@ if(MQT_CORE_INSTALL) configure_package_config_file( ${MQT_CORE_CMAKE_CONFIG_TEMPLATE} ${MQT_CORE_CMAKE_PROJECT_CONFIG_FILE} INSTALL_DESTINATION ${MQT_CORE_CONFIG_INSTALL_DIR} - PATH_VARS MQT_CORE_ZX_WITH_GMP + PATH_VARS MQT_CORE_WITH_GMP NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) write_basic_package_version_file( ${MQT_CORE_CMAKE_VERSION_CONFIG_FILE} diff --git a/src/zx/CMakeLists.txt b/src/zx/CMakeLists.txt index 290a78ecc..65475b3ce 100644 --- a/src/zx/CMakeLists.txt +++ b/src/zx/CMakeLists.txt @@ -51,18 +51,13 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-zx) target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PUBLIC MQT::Core MQT::Multiprecision) target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PRIVATE MQT::ProjectOptions MQT::ProjectWarnings) - find_package(GMP) - if(NOT GMP_FOUND) - message(NOTICE "Did not find GMP. Using Boost multiprecision library instead.") - endif() - # # link to GMP libraries if present - if(GMP_FOUND) + option(MQT_CORE_WITH_GMP "Whether to use GMP for multiprecision arithmetic" OFF) + if(MQT_CORE_WITH_GMP) + find_package(GMP REQUIRED) + # link to GMP libraries if present target_compile_definitions(${MQT_CORE_TARGET_NAME}-zx PUBLIC GMP) target_link_libraries(${MQT_CORE_TARGET_NAME}-zx PUBLIC GMP::gmp GMP::gmpxx) endif() - set(MQT_CORE_ZX_WITH_GMP - ${GMP_FOUND} - CACHE BOOL "Whether to use GMP for multiprecision arithmetic") # add MQT alias add_library(MQT::CoreZX ALIAS ${MQT_CORE_TARGET_NAME}-zx)