Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/slurm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Build the MQT Core wheel
timeout-minutes: 15
run: uv build --wheel --out-dir test/slurm/dist
run: uv build --wheel --out-dir test/slurm/dist -Ccmake.define.DEPLOY=ON

- name: Test Slurm admission and QDMI execution
timeout-minutes: 15
Expand Down
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ endif()
# Add path for custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(BUILD_MQT_CORE_TESTS "Build tests for the MQT Core project" ${PROJECT_IS_TOP_LEVEL})

include(AddMQTPythonBinding)
include(StandardProjectSettings)
include(PreventInSourceBuilds)
Expand Down Expand Up @@ -55,7 +57,6 @@ if(BUILD_MQT_CORE_BINDINGS)
endif()

option(MQT_CORE_INSTALL "Generate installation instructions for MQT Core" ${PROJECT_IS_TOP_LEVEL})
option(BUILD_MQT_CORE_TESTS "Build tests for the MQT Core project" ${PROJECT_IS_TOP_LEVEL})
option(BUILD_MQT_CORE_SHARED_LIBS "Build MQT Core libraries as shared libraries"
${BUILD_SHARED_LIBS})
option(BUILD_MQT_CORE_MLIR "Build the MQT Core MLIR compiler infrastructure" ON)
Expand Down Expand Up @@ -116,7 +117,10 @@ if(MQT_CORE_INSTALL)
set(CMAKE_INSTALL_RPATH ${BASEPOINT} ${BASEPOINT}/${CMAKE_INSTALL_LIBDIR}
${BASEPOINT}/../${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(APPLE)
# Avoid invalidating code signatures by rewriting Mach-O libraries during installation.
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()
endif()

# add main library code
Expand Down Expand Up @@ -166,17 +170,18 @@ if(BUILD_MQT_CORE_MLIR)
COMMENT "Copying and cleaning up generated MLIR documentation"
VERBATIM)
endif()
foreach(binding dd qdmi)
add_dependencies(${MQT_CORE_TARGET_NAME}-${binding}-bindings mqt-core-docs)
endforeach()
if(BUILD_MQT_CORE_BINDINGS)
foreach(binding dd qdmi)
add_dependencies(${MQT_CORE_TARGET_NAME}-${binding}-bindings mqt-core-docs)
endforeach()
endif()
endif()
endif()

if(BUILD_MQT_CORE_BINDINGS)
set(MQT_CORE_WHEEL_TARGETS mqt-core-bench-bindings mqt-core-bench-library mqt-core-dd
mqt-core-dd-bindings mqt-core-qdmi-bindings)
set(MQT_CORE_WHEEL_TARGETS mqt-core-bench-bindings mqt-core-dd-bindings mqt-core-qdmi-bindings)
if(BUILD_MQT_CORE_MLIR)
list(APPEND MQT_CORE_WHEEL_TARGETS mqt-core-bench mqt-core-mlir-bindings)
list(APPEND MQT_CORE_WHEEL_TARGETS mqt-cc mqt-core-bench mqt-core-mlir-bindings)
endif()
if(BUILD_MQT_CORE_MLIR AND BUILD_MQT_CORE_QDMI_DDSIM_DEVICE)
list(APPEND MQT_CORE_WHEEL_TARGETS mqt-core-qdmi-ddsim-device)
Expand Down
2 changes: 1 addition & 1 deletion bindings/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-bench-bindings)
MQT::CoreBench)

# install the Python stub files in editable mode for better IDE support
if(SKBUILD_STATE STREQUAL "editable")
if(MQT_CORE_INSTALL AND SKBUILD_STATE STREQUAL "editable")
file(GLOB_RECURSE BENCH_PYI_FILES ${PROJECT_SOURCE_DIR}/python/mqt/core/bench/*.pyi)
install(
FILES ${BENCH_PYI_FILES}
Expand Down
4 changes: 2 additions & 2 deletions bindings/dd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ if(NOT TARGET ${MQT_CORE_TARGET_NAME}-dd-bindings)
INSTALL_DIR
.
LINK_LIBS
MQT::CoreDD)
MQT::CoreDDPython)

# install the Python stub file in editable mode for better IDE support
if(SKBUILD_STATE STREQUAL "editable")
if(MQT_CORE_INSTALL AND SKBUILD_STATE STREQUAL "editable")
install(
FILES ${PROJECT_SOURCE_DIR}/python/mqt/core/dd.pyi
DESTINATION .
Expand Down
4 changes: 2 additions & 2 deletions bindings/mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if(NOT TARGET ${TARGET_NAME})
MLIRMQTDialect
MLIRMQTUtils
MLIRQCTranslationSupport
MLIRQCODDFunctionality)
MLIRQCODDFunctionalityPython)

if(MQT_QISKIT_CAPI_CANDIDATE_VERSION)
target_compile_definitions(
Expand All @@ -94,7 +94,7 @@ if(NOT TARGET ${TARGET_NAME})
endif()

# install the Python stub file in editable mode for better IDE support
if(SKBUILD_STATE STREQUAL "editable")
if(MQT_CORE_INSTALL AND SKBUILD_STATE STREQUAL "editable")
install(
FILES ${PROJECT_SOURCE_DIR}/python/mqt/core/mlir.pyi
DESTINATION .
Expand Down
19 changes: 17 additions & 2 deletions cmake/AddMQTCoreLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function(add_mqt_core_library name)
elseif(BUILD_MQT_CORE_SHARED_LIBS)
add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS})
else()
add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
add_library(${name} STATIC ${ARG_UNPARSED_ARGUMENTS})
endif()

if(NOT ARG_ALIAS_NAME)
Expand All @@ -42,9 +42,16 @@ function(add_mqt_core_library name)
endif()
add_library(MQT::Core${ARG_ALIAS_NAME} ALIAS ${name})

get_target_property(target_type ${name} TYPE)
if(target_type STREQUAL "STATIC_LIBRARY")
string(TOUPPER "MQT_CORE_${ARG_ALIAS_NAME}_STATIC_DEFINE" static_define)
target_compile_definitions(${name} PUBLIC ${static_define})
endif()

target_compile_features(${name} PUBLIC cxx_std_20)

target_link_libraries(${name} PRIVATE MQT::ProjectWarnings MQT::ProjectOptions)
target_link_libraries(${name}
PRIVATE "$<BUILD_LOCAL_INTERFACE:MQT::ProjectWarnings;MQT::ProjectOptions>")

if(ARG_HIDDEN_VISIBILITY)
set_target_properties(
Expand All @@ -53,6 +60,14 @@ function(add_mqt_core_library name)
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
WINDOWS_EXPORT_ALL_SYMBOLS OFF)
elseif(WIN32)
if(target_type STREQUAL "SHARED_LIBRARY")
set_target_properties(${name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# CMake's automatic export scanner cannot read MSVC /GL objects.
set_target_properties(${name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF)
endif()
endif()
endif()

# Always compile with position-independent code to enable usage in shared libraries
Expand Down
16 changes: 10 additions & 6 deletions cmake/AddMQTPythonBinding.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function(add_mqt_python_binding package_name target_name)
${target_name}
# Enable free-threaded support
FREE_THREADED
# Keep computation in bindings optimized for speed.
NOMINSIZE
# Suppress compiler warnings from the nanobind library
NB_SUPPRESS_WARNINGS
# Use nanobind's shared runtime. Split mode enables the Stable ABI internally.
Expand All @@ -40,11 +42,11 @@ function(add_mqt_python_binding package_name target_name)

# Keep statically linked dependencies local.
if(APPLE)
# Restore the Python module namespace changed by HandleLLVMOptions, as in AddMLIRPython.
target_link_options(${target_name} PRIVATE "LINKER:-twolevel_namespace")
target_link_options(${target_name} PRIVATE "LINKER:-exported_symbol,_PyInit_${module_name}")
elseif(UNIX)
target_link_options(${target_name} PRIVATE "LINKER:--exclude-libs,ALL")
elseif(WIN32)
set_target_properties(${target_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS OFF)
endif()

# Add project libraries to the link libraries
Expand All @@ -58,8 +60,10 @@ function(add_mqt_python_binding package_name target_name)
endif()

# Install directive for scikit-build-core
install(
TARGETS ${target_name}
DESTINATION ${ARG_INSTALL_DIR}
COMPONENT ${MQT_${package_name}_TARGET_NAME}_Python)
if(MQT_CORE_INSTALL)
install(
TARGETS ${target_name}
DESTINATION ${ARG_INSTALL_DIR}
COMPONENT ${MQT_${package_name}_TARGET_NAME}_Python)
endif()
endfunction()
79 changes: 28 additions & 51 deletions cmake/AddMQTQDMIDevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ function(mqt_configure_qdmi_device target)
foreach(runtime_file IN LISTS ARG_RUNTIME_FILES)
get_filename_component(runtime_file_name "${runtime_file}" NAME)
list(APPEND runtime_file_names "${runtime_file_name}")
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${runtime_file}"
"$<TARGET_FILE_DIR:${target}>/${runtime_file_name}")
endforeach()

set(device_entries
Expand Down Expand Up @@ -98,11 +93,14 @@ function(mqt_configure_qdmi_device target)
"{\n \"schema-version\": 1,\n \"qdmi\": {\n \"devices\": [\n${device_entries}\n ]\n }\n}\n"
)

add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${fragment}"
"$<TARGET_FILE_DIR:${target}>/${target}.qdmi.json")
# Assets can change without relinking the device.
add_custom_target(
${target}-qdmi-assets
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${target}>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${fragment}" ${ARG_RUNTIME_FILES}
"$<TARGET_FILE_DIR:${target}>"
COMMAND_EXPAND_LISTS VERBATIM)
add_dependencies(${target} ${target}-qdmi-assets)
set_target_properties(
${target}
PROPERTIES QDMI_DEVICE_ID "${ARG_ID}"
Expand All @@ -122,19 +120,11 @@ function(mqt_configure_qdmi_device target)
else()
set(fragment_install_dir ${CMAKE_INSTALL_LIBDIR})
endif()
set(install_arguments)
if(MQT_CORE_TARGET_NAME)
list(APPEND install_arguments COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime)
endif()
install(
FILES "${fragment}"
DESTINATION ${fragment_install_dir}
${install_arguments})
if(ARG_RUNTIME_FILES)
if(MQT_CORE_INSTALL)
install(
FILES ${ARG_RUNTIME_FILES}
FILES "${fragment}" ${ARG_RUNTIME_FILES}
DESTINATION ${fragment_install_dir}
${install_arguments})
COMPONENT ${MQT_CORE_TARGET_NAME}_Runtime)
endif()
endfunction()

Expand All @@ -151,7 +141,9 @@ function(mqt_copy_qdmi_runtime target)
if(NOT TARGET ${target})
message(FATAL_ERROR "Unknown QDMI application target: ${target}")
endif()
set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH FALSE)
if(NOT (APPLE AND SKBUILD))
set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH FALSE)
endif()
set(devices ${ARGN})
if(NOT devices)
mqt_get_qdmi_device_targets(devices)
Expand All @@ -178,22 +170,15 @@ function(mqt_copy_qdmi_runtime target)
if(library_target STREQUAL "${target}" OR NOT library_type MATCHES "^(SHARED|MODULE)_LIBRARY$")
continue()
endif()
string(MAKE_C_IDENTIFIER "${target}-stage-${library_target}" staging_target)
if(TARGET ${staging_target})
continue()
endif()
get_target_property(imported ${library_target} IMPORTED)
set(files "$<TARGET_FILE:${library}>")
if(WIN32)
if(imported)
# TARGET_RUNTIME_DLLS needs a local target to traverse imported dependencies.
string(MAKE_C_IDENTIFIER "${library_target}-dependencies" dependency_target)
if(NOT TARGET ${dependency_target})
add_library(${dependency_target} MODULE EXCLUDE_FROM_ALL
"${CMAKE_CURRENT_FUNCTION_LIST_FILE}")
set_property(TARGET ${dependency_target} PROPERTY LINKER_LANGUAGE CXX)
target_link_libraries(${dependency_target} PRIVATE ${library})
endif()
set(files "$<TARGET_RUNTIME_DLLS:${dependency_target}>")
else()
list(APPEND files "$<TARGET_RUNTIME_DLLS:${library}>")
endif()
if(UNIX AND library_type STREQUAL "SHARED_LIBRARY")
# Source installations may use a versioned SONAME in linked applications.
list(APPEND files "$<TARGET_SONAME_FILE:${library}>")
endif()
if(library IN_LIST devices)
get_target_property(manifest_name ${library_target} QDMI_MANIFEST_NAME)
Expand Down Expand Up @@ -228,22 +213,14 @@ function(mqt_copy_qdmi_runtime target)
endforeach()
endif()
endif()
if(NOT imported)
add_dependencies(${target} ${library_target})
endif()
add_custom_command(
TARGET ${target}
POST_BUILD
add_custom_target(
${staging_target}
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${target}>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${files} "$<TARGET_FILE_DIR:${target}>"
COMMAND_EXPAND_LISTS)
if(NOT WIN32 AND imported)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND
${CMAKE_COMMAND} "-DLIBRARY=$<TARGET_FILE:${library}>"
"-DDESTINATION=$<TARGET_FILE_DIR:${target}>" -P
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/CopyQDMISharedDependencies.cmake")
COMMAND_EXPAND_LISTS VERBATIM)
if(NOT imported)
add_dependencies(${staging_target} ${library_target})
endif()
add_dependencies(${target} ${staging_target})
endforeach()
endfunction()
6 changes: 6 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
function(enable_project_options target_name)
include(CheckCXXCompilerFlag)

if(APPLE)
target_link_options(${target_name} INTERFACE "$<$<NOT:$<CONFIG:Debug>>:LINKER:-dead_strip>")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_options(${target_name} INTERFACE "$<$<NOT:$<CONFIG:Debug>>:LINKER:--gc-sections>")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE
"Enable -ftime-trace to generate time tracing .json files on clang" OFF)
Expand Down
21 changes: 0 additions & 21 deletions cmake/CopyQDMISharedDependencies.cmake

This file was deleted.

2 changes: 2 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ if(BUILD_MQT_CORE_MLIR)
# jeff's transitive Cap'n Proto dependency contains source files that cannot share a unity
# translation unit. Keep the complete dependency subtree out of unity builds.
set(CMAKE_UNITY_BUILD OFF)
# Cap'n Proto requires compiler extensions.
set(CMAKE_CXX_EXTENSIONS ON)
FetchContent_MakeAvailable(jeff-mlir)
endblock()
if(MSVC AND TARGET capnp)
Expand Down
20 changes: 6 additions & 14 deletions cmake/StandardProjectSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

# Require C++ standard
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD_REQUIRED ON)
set_property(GLOBAL PROPERTY CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Generate compile_commands.json to make it easier to work with clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS
Expand All @@ -49,11 +49,6 @@ if(DEFINED ENV{DEPLOY})
$ENV{DEPLOY}
CACHE BOOL "Use deployment configuration from environment" FORCE)
message(STATUS "Setting deployment configuration to '${DEPLOY}' from environment")
elseif(DEFINED ENV{CI})
set(DEPLOY
ON
CACHE BOOL "Set deployment configuration to ON for CI" FORCE)
message(STATUS "Setting deployment configuration to '${DEPLOY}' for CI")
endif()

# set deployment specific options
Expand All @@ -64,8 +59,10 @@ if(DEPLOY)
CACHE STRING "" FORCE)
endif()

# try to enable inter-procedural optimization per default for Release builds outside of deployment
if(NOT DEPLOY AND CMAKE_BUILD_TYPE STREQUAL "Release")
# MSVC /GL libraries repeat code generation at every test executable's link.
if(NOT DEPLOY
AND CMAKE_BUILD_TYPE STREQUAL "Release"
AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND BUILD_MQT_CORE_TESTS))
option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" ON)
else()
option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" OFF)
Expand All @@ -82,9 +79,4 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION
${ipo_supported}
CACHE BOOL "Enable Interprocedural Optimization" FORCE)

# export all symbols by default on Windows
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
ON
CACHE BOOL "Export all symbols on Windows")

set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
Loading
Loading