Skip to content

Commit 8cec5ca

Browse files
authored
📦 Switch to component-based installation for the MQT Core Python package (#1596)
## Description This PR switches the MQT Core Python package build to use component-based installation. This is a first step towards enabling MLIR as part of the Python package. The majority of the work in this PR was to properly define our external dependencies (nlohmann_json, spdlog, QDMI) in a way that they can be included as part of our installation components configuration. This requires defining our own installation instructions for these libraries (except for QDMI). One of the big plus points of this is that it allows us to drop all the `DISABLE_INSTALL` in the MLIR code, as the respective code is not added to any of the components we define at the moment. ## 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 focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have updated the documentation to reflect these changes. - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] I have added migration instructions to the upgrade guide (if needed). - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. **If PR contains AI-assisted content:** - [x] I have disclosed the use of AI tools in the PR description as per our [AI Usage Guidelines](https://github.com/munich-quantum-toolkit/core/blob/main/docs/ai_usage.md). - [x] AI-assisted commits include an `Assisted-by: [Model Name] via [Tool Name]` footer. - [x] I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it. --------- Signed-off-by: burgholzer <burgholzer@me.com>
1 parent bd9f9cb commit 8cec5ca

20 files changed

Lines changed: 148 additions & 54 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
2020

2121
### Changed
2222

23+
- 📦 Switch to component-based installation for the MQT Core Python package ([#1596]) ([**@burgholzer**])
2324
- ⬆️ Update QDMI to latest version from stable `v1.2.x` branch ([#1593]) ([**@burgholzer**])
2425
- ⬆️ Update `clang-tidy` to version 22 ([#1564]) ([**@denialhaag**], [**@burgholzer**])
2526
- 👷 Build on `macos-26`/`macos-26-intel` by default and `macos-15`/`macos-15-intel` for extensive tests ([#1571]) ([**@denialhaag**])
@@ -334,6 +335,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
334335

335336
<!-- PR links -->
336337

338+
[#1596]: https://github.com/munich-quantum-toolkit/core/pull/1596
337339
[#1593]: https://github.com/munich-quantum-toolkit/core/pull/1593
338340
[#1588]: https://github.com/munich-quantum-toolkit/core/pull/1588
339341
[#1583]: https://github.com/munich-quantum-toolkit/core/pull/1583

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ project(
9595
VERSION ${MQT_CORE_VERSION}
9696
DESCRIPTION "MQT Core - The Backbone of the Munich Quantum Toolkit")
9797

98+
set(MQT_CORE_TARGET_NAME "mqt-core")
99+
98100
if(BUILD_MQT_CORE_MLIR)
99101
include(SetupMLIR)
100102
endif()
@@ -116,8 +118,6 @@ if(MQT_CORE_INSTALL)
116118
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
117119
endif()
118120

119-
set(MQT_CORE_TARGET_NAME "mqt-core")
120-
121121
cmake_dependent_option(BUILD_MQT_CORE_QIR_RUNNER "Build the QIR runner of the MQT Core project" ON
122122
"BUILD_MQT_CORE_MLIR" OFF)
123123

cmake/ExternalDependencies.cmake

Lines changed: 121 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ set(JSON_URL https://github.com/nlohmann/json/releases/download/v${JSON_VERSION}
5252
set(JSON_SystemInclude
5353
ON
5454
CACHE INTERNAL "Treat the library headers like system headers")
55-
cmake_dependent_option(JSON_Install "Install nlohmann_json library" ON "MQT_CORE_INSTALL" OFF)
55+
cmake_dependent_option(MQT_CORE_JSON_INSTALL "Install nlohmann_json library" ON "MQT_CORE_INSTALL"
56+
OFF)
57+
# Disable upstream nlohmann_json install rules and install with explicit MQT components below.
58+
set(JSON_Install
59+
OFF
60+
CACHE BOOL "Disable upstream nlohmann_json install rules; handled by mqt-core" FORCE)
5661
FetchContent_Declare(nlohmann_json URL ${JSON_URL} FIND_PACKAGE_ARGS ${JSON_VERSION})
5762
list(APPEND FETCH_PACKAGES nlohmann_json)
5863

@@ -117,7 +122,11 @@ set(SPDLOG_BUILD_PIC ON)
117122
set(SPDLOG_SYSTEM_INCLUDES
118123
ON
119124
CACHE INTERNAL "Treat the library headers like system headers")
120-
cmake_dependent_option(SPDLOG_INSTALL "Install spdlog library" ON "MQT_CORE_INSTALL" OFF)
125+
cmake_dependent_option(MQT_CORE_SPDLOG_INSTALL "Install spdlog library" ON "MQT_CORE_INSTALL" OFF)
126+
# Disable upstream spdlog install rules and install with explicit MQT components below.
127+
set(SPDLOG_INSTALL
128+
OFF
129+
CACHE BOOL "Disable upstream spdlog install rules; handled by mqt-core" FORCE)
121130
cmake_dependent_option(SPDLOG_BUILD_SHARED "Build spdlog as shared library" ON
122131
"BUILD_MQT_CORE_SHARED_LIBS" OFF)
123132
FetchContent_Declare(spdlog URL ${SPDLOG_URL} FIND_PACKAGE_ARGS ${SPDLOG_VERSION})
@@ -145,6 +154,62 @@ if(_eigen_target)
145154
endif()
146155
endif()
147156

157+
# Install nlohmann_json with explicit MQT components.
158+
if(MQT_CORE_JSON_INSTALL AND TARGET nlohmann_json)
159+
set(MQT_CORE_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/nlohmann_json")
160+
set(MQT_CORE_JSON_TARGETS_EXPORT_NAME "nlohmann_jsonTargets")
161+
set(MQT_CORE_JSON_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfig.cmake")
162+
set(MQT_CORE_JSON_VERSION_CONFIG_FILE
163+
"${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfigVersion.cmake")
164+
165+
# nlohmann_json's upstream templates expect these names.
166+
set(_mqt_core_saved_project_name "${PROJECT_NAME}")
167+
set(_mqt_core_saved_project_version "${PROJECT_VERSION}")
168+
set(_mqt_core_saved_project_version_major "${PROJECT_VERSION_MAJOR}")
169+
set(PROJECT_NAME "nlohmann_json")
170+
set(PROJECT_VERSION "${JSON_VERSION}")
171+
string(REGEX MATCH "^[0-9]+" PROJECT_VERSION_MAJOR "${JSON_VERSION}")
172+
set(NLOHMANN_JSON_TARGET_NAME "nlohmann_json")
173+
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${MQT_CORE_JSON_TARGETS_EXPORT_NAME}")
174+
175+
configure_file(${nlohmann_json_SOURCE_DIR}/cmake/config.cmake.in ${MQT_CORE_JSON_CONFIG_FILE}
176+
@ONLY)
177+
configure_file(${nlohmann_json_SOURCE_DIR}/cmake/nlohmann_jsonConfigVersion.cmake.in
178+
${MQT_CORE_JSON_VERSION_CONFIG_FILE} @ONLY)
179+
180+
set(PROJECT_NAME "${_mqt_core_saved_project_name}")
181+
set(PROJECT_VERSION "${_mqt_core_saved_project_version}")
182+
set(PROJECT_VERSION_MAJOR "${_mqt_core_saved_project_version_major}")
183+
unset(_mqt_core_saved_project_name)
184+
unset(_mqt_core_saved_project_version)
185+
unset(_mqt_core_saved_project_version_major)
186+
unset(NLOHMANN_JSON_TARGET_NAME)
187+
unset(NLOHMANN_JSON_TARGETS_EXPORT_NAME)
188+
189+
install(
190+
DIRECTORY ${nlohmann_json_SOURCE_DIR}/include/
191+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
192+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
193+
194+
install(
195+
TARGETS nlohmann_json
196+
EXPORT ${MQT_CORE_JSON_TARGETS_EXPORT_NAME}
197+
INCLUDES
198+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
199+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
200+
201+
install(
202+
EXPORT ${MQT_CORE_JSON_TARGETS_EXPORT_NAME}
203+
NAMESPACE nlohmann_json::
204+
DESTINATION ${MQT_CORE_JSON_CONFIG_INSTALL_DIR}
205+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
206+
207+
install(
208+
FILES ${MQT_CORE_JSON_CONFIG_FILE} ${MQT_CORE_JSON_VERSION_CONFIG_FILE}
209+
DESTINATION ${MQT_CORE_JSON_CONFIG_INSTALL_DIR}
210+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
211+
endif()
212+
148213
# Ensure external shared libraries end up in a common lib layout used by our RUNPATH
149214
if(TARGET spdlog)
150215
set_target_properties(
@@ -154,17 +219,59 @@ if(TARGET spdlog)
154219
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
155220
endif()
156221

157-
# Patch for spdlog cmake files to be installed in a common cmake directory
158-
if(SPDLOG_INSTALL)
222+
# Install spdlog with explicit MQT components.
223+
if(MQT_CORE_SPDLOG_INSTALL
224+
AND TARGET spdlog
225+
AND TARGET spdlog_header_only)
226+
include(CMakePackageConfigHelpers)
227+
228+
set(MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/spdlog")
229+
set(MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE "spdlogConfigTargets.cmake")
230+
set(MQT_CORE_SPDLOG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
231+
set(MQT_CORE_SPDLOG_VERSION_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
232+
233+
install(
234+
TARGETS spdlog spdlog_header_only
235+
EXPORT spdlog
236+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime
237+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
238+
COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime
239+
NAMELINK_COMPONENT ${MQT_CORE_TARGET_NAME}_Development
240+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
241+
242+
install(
243+
DIRECTORY ${spdlog_SOURCE_DIR}/include/
244+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
245+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development
246+
PATTERN "fmt/bundled" EXCLUDE)
247+
248+
if(NOT SPDLOG_USE_STD_FORMAT
249+
AND NOT SPDLOG_FMT_EXTERNAL
250+
AND NOT SPDLOG_FMT_EXTERNAL_HO)
251+
install(
252+
DIRECTORY ${spdlog_SOURCE_DIR}/include/spdlog/fmt/bundled/
253+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spdlog/fmt/bundled
254+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
255+
endif()
256+
257+
install(
258+
EXPORT spdlog
259+
FILE ${MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE}
260+
NAMESPACE spdlog::
261+
DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR}
262+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
263+
264+
set(config_targets_file ${MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE})
265+
configure_package_config_file(
266+
${spdlog_SOURCE_DIR}/cmake/spdlogConfig.cmake.in ${MQT_CORE_SPDLOG_CONFIG_FILE}
267+
INSTALL_DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR})
268+
write_basic_package_version_file(
269+
${MQT_CORE_SPDLOG_VERSION_CONFIG_FILE}
270+
VERSION ${SPDLOG_VERSION}
271+
COMPATIBILITY SameMajorVersion)
272+
159273
install(
160-
CODE "
161-
file(GLOB SPDLOG_CMAKE_FILES
162-
\"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/spdlog/*\")
163-
if(SPDLOG_CMAKE_FILES)
164-
file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/cmake/spdlog\")
165-
file(COPY \${SPDLOG_CMAKE_FILES}
166-
DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/cmake/spdlog\")
167-
file(REMOVE_RECURSE \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/spdlog\")
168-
endif()
169-
")
274+
FILES ${MQT_CORE_SPDLOG_CONFIG_FILE} ${MQT_CORE_SPDLOG_VERSION_CONFIG_FILE}
275+
DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR}
276+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
170277
endif()

mlir/lib/Compiler/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ add_mlir_library(
2020
MLIRQCToQCO
2121
MLIRQCOToQC
2222
MLIRQCToQIR
23-
MQT::MLIRSupport
24-
DISABLE_INSTALL)
23+
MQT::MLIRSupport)
2524

2625
mqt_mlir_target_use_project_options(MQTCompilerPipeline)
2726

mlir/lib/Conversion/JeffToQCO/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ add_mlir_conversion_library(
1717
MLIRJeff
1818
MLIRJeffToNative
1919
MLIRQCODialect
20-
MLIRTransforms
21-
DISABLE_INSTALL)
20+
MLIRTransforms)

mlir/lib/Conversion/QCOToJeff/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ add_mlir_conversion_library(
1818
MLIRJeff
1919
MLIRNativeToJeff
2020
MLIRQCODialect
21-
MLIRTransforms
22-
DISABLE_INSTALL)
21+
MLIRTransforms)
2322

2423
if(TARGET MLIRQCOToJeff)
2524
target_compile_definitions(MLIRQCOToJeff PRIVATE MQT_CORE_VERSION="${MQT_CORE_VERSION}")

mlir/lib/Conversion/QCOToQC/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ add_mlir_conversion_library(
2020
MLIRArithDialect
2121
MLIRFuncDialect
2222
MLIRTransforms
23-
MLIRFuncTransforms
24-
DISABLE_INSTALL)
23+
MLIRFuncTransforms)
2524

2625
mqt_mlir_target_use_project_options(MLIRQCOToQC)

mlir/lib/Conversion/QCToQCO/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ add_mlir_conversion_library(
2020
MLIRArithDialect
2121
MLIRFuncDialect
2222
MLIRTransforms
23-
MLIRFuncTransforms
24-
DISABLE_INSTALL)
23+
MLIRFuncTransforms)
2524

2625
mqt_mlir_target_use_project_options(MLIRQCToQCO)

mlir/lib/Conversion/QCToQIR/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ add_mlir_conversion_library(
2121
MLIRTransforms
2222
MLIRFuncDialect
2323
MLIRFuncToLLVM
24-
MLIRReconcileUnrealizedCasts
25-
DISABLE_INSTALL)
24+
MLIRReconcileUnrealizedCasts)
2625

2726
mqt_mlir_target_use_project_options(MLIRQCToQIR)

mlir/lib/Dialect/QC/Builder/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ add_mlir_library(
1414
MLIRArithDialect
1515
MLIRFuncDialect
1616
MLIRSCFDialect
17-
MLIRQCDialect
18-
DISABLE_INSTALL)
17+
MLIRQCDialect)
1918

2019
mqt_mlir_target_use_project_options(MLIRQCProgramBuilder)
2120

0 commit comments

Comments
 (0)