Skip to content

Commit

Permalink
🩹 make GMP dependency opt-in instead of used-if-found (#608)
Browse files Browse the repository at this point in the history
## 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 cda-tum/mqt-qcec#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:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [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 <burgholzer@me.com>
  • Loading branch information
burgholzer authored May 23, 2024
1 parent acb8895 commit 5f27ae7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
5 changes: 2 additions & 3 deletions cmake/mqt-core-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 4 additions & 9 deletions src/zx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5f27ae7

Please sign in to comment.