Skip to content

Commit 8ac203d

Browse files
committed
📦 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> (cherry picked from commit 8cec5ca) Signed-off-by: burgholzer <burgholzer@me.com> # Conflicts: # CMakeLists.txt # cmake/ExternalDependencies.cmake # mlir/lib/Compiler/CMakeLists.txt # mlir/lib/Conversion/MQTOptToMQTRef/CMakeLists.txt # mlir/lib/Conversion/MQTRefToMQTOpt/CMakeLists.txt # mlir/lib/Conversion/MQTRefToQIR/CMakeLists.txt # mlir/lib/Conversion/QCOToJeff/CMakeLists.txt # mlir/lib/Conversion/QIRToMQTRef/CMakeLists.txt # mlir/lib/Dialect/MQTOpt/IR/CMakeLists.txt # mlir/lib/Dialect/MQTRef/IR/CMakeLists.txt # mlir/lib/Dialect/MQTRef/Translation/CMakeLists.txt # mlir/lib/Dialect/QC/Builder/CMakeLists.txt # mlir/lib/Dialect/QC/Translation/CMakeLists.txt # mlir/lib/Dialect/QCO/IR/CMakeLists.txt # mlir/lib/Dialect/QCO/Utils/CMakeLists.txt # mlir/lib/Dialect/QIR/Builder/CMakeLists.txt # mlir/lib/Dialect/QIR/Utils/CMakeLists.txt # mlir/lib/Support/CMakeLists.txt
1 parent 59d5a50 commit 8ac203d

12 files changed

Lines changed: 168 additions & 64 deletions

File tree

CHANGELOG.md

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

1616
### Changed
1717

18+
- 📦 Switch to component-based installation for the MQT Core Python package ([#1596]) ([**@burgholzer**])
1819
- ⬆️ Update QDMI to latest version from stable `v1.2.x` branch ([#1593]) ([**@burgholzer**])
1920

2021
## [3.4.1] - 2026-02-01
@@ -320,6 +321,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
320321

321322
<!-- PR links -->
322323

324+
[#1596]: https://github.com/munich-quantum-toolkit/core/pull/1596
323325
[#1593]: https://github.com/munich-quantum-toolkit/core/pull/1593
324326
[#1507]: https://github.com/munich-quantum-toolkit/core/pull/1507
325327
[#1481]: https://github.com/munich-quantum-toolkit/core/pull/1481

CMakeLists.txt

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ option(MQT_CORE_INSTALL "Generate installation instructions for MQT Core"
6363
option(BUILD_MQT_CORE_TESTS "Build tests for the MQT Core project" ${MQT_CORE_MASTER_PROJECT})
6464
option(BUILD_MQT_CORE_SHARED_LIBS "Build MQT Core libraries as shared libraries"
6565
${BUILD_SHARED_LIBS})
66+
option(BUILD_MQT_CORE_MLIR "Build the MLIR submodule of the MQT Core project" OFF)
67+
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
68+
set(BUILD_MQT_CORE_MLIR
69+
OFF
70+
CACHE BOOL
71+
"Disable MLIR build on macOS with GCC to avoid ABI issues between STL and libstdc++"
72+
FORCE)
73+
message(
74+
WARNING "Disabling MLIR build on macOS with GCC to avoid ABI issues between STL and libstdc++")
75+
endif()
76+
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
77+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0.0")
78+
set(BUILD_MQT_CORE_MLIR
79+
OFF
80+
CACHE
81+
BOOL
82+
"Disable MLIR build on macOS with Apple Clang < 17 due to missing complete C++20 support"
83+
FORCE)
84+
message(
85+
WARNING
86+
"Disabling MLIR build on macOS with Apple Clang < 17 due to missing complete C++20 support")
87+
endif()
88+
endif()
6689

6790
# try to determine the project version
6891
include(GetVersion)
@@ -74,6 +97,12 @@ project(
7497
VERSION ${MQT_CORE_VERSION}
7598
DESCRIPTION "MQT Core - The Backbone of the Munich Quantum Toolkit")
7699

100+
set(MQT_CORE_TARGET_NAME "mqt-core")
101+
102+
if(BUILD_MQT_CORE_MLIR)
103+
include(SetupMLIR)
104+
endif()
105+
77106
include(cmake/ExternalDependencies.cmake)
78107

79108
# set the include directory for the build tree
@@ -91,34 +120,6 @@ if(MQT_CORE_INSTALL)
91120
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
92121
endif()
93122

94-
set(MQT_CORE_TARGET_NAME "mqt-core")
95-
96-
option(BUILD_MQT_CORE_MLIR "Build the MLIR submodule of the MQT Core project" OFF)
97-
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
98-
set(BUILD_MQT_CORE_MLIR
99-
OFF
100-
CACHE BOOL
101-
"Disable MLIR build on macOS with GCC to avoid ABI issues between STL and libstdc++"
102-
FORCE)
103-
message(
104-
WARNING "Disabling MLIR build on macOS with GCC to avoid ABI issues between STL and libstdc++")
105-
endif()
106-
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
107-
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0.0")
108-
set(BUILD_MQT_CORE_MLIR
109-
OFF
110-
CACHE
111-
BOOL
112-
"Disable MLIR build on macOS with Apple Clang < 17 due to missing complete C++20 support"
113-
FORCE)
114-
message(
115-
WARNING
116-
"Disabling MLIR build on macOS with Apple Clang < 17 due to missing complete C++20 support")
117-
endif()
118-
endif()
119-
if(BUILD_MQT_CORE_MLIR)
120-
include(SetupMLIR)
121-
endif()
122123
cmake_dependent_option(BUILD_MQT_CORE_QIR_RUNNER "Build the QIR runner of the MQT Core project" ON
123124
"BUILD_MQT_CORE_MLIR" OFF)
124125

cmake/ExternalDependencies.cmake

Lines changed: 121 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ set(JSON_URL https://github.com/nlohmann/json/releases/download/v${JSON_VERSION}
2929
set(JSON_SystemInclude
3030
ON
3131
CACHE INTERNAL "Treat the library headers like system headers")
32-
cmake_dependent_option(JSON_Install "Install nlohmann_json library" ON "MQT_CORE_INSTALL" OFF)
32+
cmake_dependent_option(MQT_CORE_JSON_INSTALL "Install nlohmann_json library" ON "MQT_CORE_INSTALL"
33+
OFF)
34+
# Disable upstream nlohmann_json install rules and install with explicit MQT components below.
35+
set(JSON_Install
36+
OFF
37+
CACHE BOOL "Disable upstream nlohmann_json install rules; handled by mqt-core" FORCE)
3338
FetchContent_Declare(nlohmann_json URL ${JSON_URL} FIND_PACKAGE_ARGS ${JSON_VERSION})
3439
list(APPEND FETCH_PACKAGES nlohmann_json)
3540

@@ -94,7 +99,11 @@ set(SPDLOG_BUILD_PIC ON)
9499
set(SPDLOG_SYSTEM_INCLUDES
95100
ON
96101
CACHE INTERNAL "Treat the library headers like system headers")
97-
cmake_dependent_option(SPDLOG_INSTALL "Install spdlog library" ON "MQT_CORE_INSTALL" OFF)
102+
cmake_dependent_option(MQT_CORE_SPDLOG_INSTALL "Install spdlog library" ON "MQT_CORE_INSTALL" OFF)
103+
# Disable upstream spdlog install rules and install with explicit MQT components below.
104+
set(SPDLOG_INSTALL
105+
OFF
106+
CACHE BOOL "Disable upstream spdlog install rules; handled by mqt-core" FORCE)
98107
cmake_dependent_option(SPDLOG_BUILD_SHARED "Build spdlog as shared library" ON
99108
"BUILD_MQT_CORE_SHARED_LIBS" OFF)
100109
FetchContent_Declare(spdlog URL ${SPDLOG_URL} FIND_PACKAGE_ARGS ${SPDLOG_VERSION})
@@ -103,6 +112,62 @@ list(APPEND FETCH_PACKAGES spdlog)
103112
# Make all declared dependencies available.
104113
FetchContent_MakeAvailable(${FETCH_PACKAGES})
105114

115+
# Install nlohmann_json with explicit MQT components.
116+
if(MQT_CORE_JSON_INSTALL AND TARGET nlohmann_json)
117+
set(MQT_CORE_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/nlohmann_json")
118+
set(MQT_CORE_JSON_TARGETS_EXPORT_NAME "nlohmann_jsonTargets")
119+
set(MQT_CORE_JSON_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfig.cmake")
120+
set(MQT_CORE_JSON_VERSION_CONFIG_FILE
121+
"${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfigVersion.cmake")
122+
123+
# nlohmann_json's upstream templates expect these names.
124+
set(_mqt_core_saved_project_name "${PROJECT_NAME}")
125+
set(_mqt_core_saved_project_version "${PROJECT_VERSION}")
126+
set(_mqt_core_saved_project_version_major "${PROJECT_VERSION_MAJOR}")
127+
set(PROJECT_NAME "nlohmann_json")
128+
set(PROJECT_VERSION "${JSON_VERSION}")
129+
string(REGEX MATCH "^[0-9]+" PROJECT_VERSION_MAJOR "${JSON_VERSION}")
130+
set(NLOHMANN_JSON_TARGET_NAME "nlohmann_json")
131+
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${MQT_CORE_JSON_TARGETS_EXPORT_NAME}")
132+
133+
configure_file(${nlohmann_json_SOURCE_DIR}/cmake/config.cmake.in ${MQT_CORE_JSON_CONFIG_FILE}
134+
@ONLY)
135+
configure_file(${nlohmann_json_SOURCE_DIR}/cmake/nlohmann_jsonConfigVersion.cmake.in
136+
${MQT_CORE_JSON_VERSION_CONFIG_FILE} @ONLY)
137+
138+
set(PROJECT_NAME "${_mqt_core_saved_project_name}")
139+
set(PROJECT_VERSION "${_mqt_core_saved_project_version}")
140+
set(PROJECT_VERSION_MAJOR "${_mqt_core_saved_project_version_major}")
141+
unset(_mqt_core_saved_project_name)
142+
unset(_mqt_core_saved_project_version)
143+
unset(_mqt_core_saved_project_version_major)
144+
unset(NLOHMANN_JSON_TARGET_NAME)
145+
unset(NLOHMANN_JSON_TARGETS_EXPORT_NAME)
146+
147+
install(
148+
DIRECTORY ${nlohmann_json_SOURCE_DIR}/include/
149+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
150+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
151+
152+
install(
153+
TARGETS nlohmann_json
154+
EXPORT ${MQT_CORE_JSON_TARGETS_EXPORT_NAME}
155+
INCLUDES
156+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
157+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
158+
159+
install(
160+
EXPORT ${MQT_CORE_JSON_TARGETS_EXPORT_NAME}
161+
NAMESPACE nlohmann_json::
162+
DESTINATION ${MQT_CORE_JSON_CONFIG_INSTALL_DIR}
163+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
164+
165+
install(
166+
FILES ${MQT_CORE_JSON_CONFIG_FILE} ${MQT_CORE_JSON_VERSION_CONFIG_FILE}
167+
DESTINATION ${MQT_CORE_JSON_CONFIG_INSTALL_DIR}
168+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
169+
endif()
170+
106171
# Ensure external shared libraries end up in a common lib layout used by our RUNPATH
107172
if(TARGET spdlog)
108173
set_target_properties(
@@ -112,17 +177,59 @@ if(TARGET spdlog)
112177
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
113178
endif()
114179

115-
# Patch for spdlog cmake files to be installed in a common cmake directory
116-
if(SPDLOG_INSTALL)
180+
# Install spdlog with explicit MQT components.
181+
if(MQT_CORE_SPDLOG_INSTALL
182+
AND TARGET spdlog
183+
AND TARGET spdlog_header_only)
184+
include(CMakePackageConfigHelpers)
185+
186+
set(MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/spdlog")
187+
set(MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE "spdlogConfigTargets.cmake")
188+
set(MQT_CORE_SPDLOG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
189+
set(MQT_CORE_SPDLOG_VERSION_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
190+
191+
install(
192+
TARGETS spdlog spdlog_header_only
193+
EXPORT spdlog
194+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime
195+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
196+
COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime
197+
NAMELINK_COMPONENT ${MQT_CORE_TARGET_NAME}_Development
198+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
199+
200+
install(
201+
DIRECTORY ${spdlog_SOURCE_DIR}/include/
202+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
203+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development
204+
PATTERN "fmt/bundled" EXCLUDE)
205+
206+
if(NOT SPDLOG_USE_STD_FORMAT
207+
AND NOT SPDLOG_FMT_EXTERNAL
208+
AND NOT SPDLOG_FMT_EXTERNAL_HO)
209+
install(
210+
DIRECTORY ${spdlog_SOURCE_DIR}/include/spdlog/fmt/bundled/
211+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spdlog/fmt/bundled
212+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
213+
endif()
214+
215+
install(
216+
EXPORT spdlog
217+
FILE ${MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE}
218+
NAMESPACE spdlog::
219+
DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR}
220+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
221+
222+
set(config_targets_file ${MQT_CORE_SPDLOG_CONFIG_TARGETS_FILE})
223+
configure_package_config_file(
224+
${spdlog_SOURCE_DIR}/cmake/spdlogConfig.cmake.in ${MQT_CORE_SPDLOG_CONFIG_FILE}
225+
INSTALL_DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR})
226+
write_basic_package_version_file(
227+
${MQT_CORE_SPDLOG_VERSION_CONFIG_FILE}
228+
VERSION ${SPDLOG_VERSION}
229+
COMPATIBILITY SameMajorVersion)
230+
117231
install(
118-
CODE "
119-
file(GLOB SPDLOG_CMAKE_FILES
120-
\"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/spdlog/*\")
121-
if(SPDLOG_CMAKE_FILES)
122-
file(MAKE_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/cmake/spdlog\")
123-
file(COPY \${SPDLOG_CMAKE_FILES}
124-
DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/cmake/spdlog\")
125-
file(REMOVE_RECURSE \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/spdlog\")
126-
endif()
127-
")
232+
FILES ${MQT_CORE_SPDLOG_CONFIG_FILE} ${MQT_CORE_SPDLOG_VERSION_CONFIG_FILE}
233+
DESTINATION ${MQT_CORE_SPDLOG_CONFIG_INSTALL_DIR}
234+
COMPONENT ${MQT_CORE_TARGET_NAME}_Development)
128235
endif()

mlir/lib/Conversion/MQTOptToMQTRef/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ add_mlir_library(
1919
MLIRMemRefDialect
2020
MLIRTransforms
2121
MLIRFuncDialect
22-
MLIRFuncTransforms
23-
DISABLE_INSTALL)
22+
MLIRFuncTransforms)

mlir/lib/Conversion/MQTRefToMQTOpt/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ add_mlir_library(
1919
MLIRMemRefDialect
2020
MLIRTransforms
2121
MLIRFuncDialect
22-
MLIRFuncTransforms
23-
DISABLE_INSTALL)
22+
MLIRFuncTransforms)

mlir/lib/Conversion/MQTRefToQIR/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ add_mlir_library(
1919
MLIRTransforms
2020
MLIRLLVMDialect
2121
MLIRFuncToLLVM
22-
MLIRReconcileUnrealizedCasts
23-
DISABLE_INSTALL)
22+
MLIRReconcileUnrealizedCasts)

mlir/lib/Conversion/QIRToMQTRef/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ add_mlir_library(
1717
MLIRMQTRef
1818
MLIRMemRefDialect
1919
MLIRTransforms
20-
MLIRLLVMDialect
21-
DISABLE_INSTALL)
20+
MLIRLLVMDialect)

mlir/lib/Dialect/MQTOpt/IR/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ add_mlir_dialect_library(
1414
MLIRMQTOptInterfacesIncGen
1515
LINK_LIBS
1616
MLIRIR
17-
MLIRInferTypeOpInterface
18-
DISABLE_INSTALL)
17+
MLIRInferTypeOpInterface)
1918

2019
# collect header files
2120
file(GLOB_RECURSE IR_HEADERS_SOURCE "${MQT_MLIR_SOURCE_INCLUDE_DIR}/mlir/Dialect/MQTOpt/IR/*.h")

mlir/lib/Dialect/MQTOpt/Transforms/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ set(LIBRARIES ${dialect_libs} MQT::CoreIR)
1111

1212
file(GLOB_RECURSE TRANSFORMS_SOURCES *.cpp)
1313

14-
add_mlir_library(
15-
MLIRMQTOptTransforms
16-
${TRANSFORMS_SOURCES}
17-
LINK_LIBS
18-
${LIBRARIES}
19-
DEPENDS
20-
MLIRMQTOptTransformsIncGen
21-
DISABLE_INSTALL)
14+
add_mlir_library(MLIRMQTOptTransforms ${TRANSFORMS_SOURCES} LINK_LIBS ${LIBRARIES} DEPENDS
15+
MLIRMQTOptTransformsIncGen)
2216

2317
# collect header files
2418
file(GLOB_RECURSE TRANSFORMS_HEADERS_SOURCE

mlir/lib/Dialect/MQTRef/IR/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ add_mlir_dialect_library(
1414
MLIRMQTRefInterfacesIncGen
1515
LINK_LIBS
1616
MLIRIR
17-
MLIRInferTypeOpInterface
18-
DISABLE_INSTALL)
17+
MLIRInferTypeOpInterface)
1918

2019
# collect header files
2120
file(GLOB_RECURSE IR_HEADERS_SOURCE "${MQT_MLIR_SOURCE_INCLUDE_DIR}/mlir/Dialect/MQTRef/IR/*.h")

0 commit comments

Comments
 (0)