diff --git a/CMakeLists.txt b/CMakeLists.txt index b039e24e8b..94119e2396 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ endif() option(BUILD_MQT_CORE_MLIR "Build the MLIR submodule of the MQT Core project" OFF) if(BUILD_MQT_CORE_MLIR) + include(SetupMLIR) add_subdirectory(mlir) endif() diff --git a/cmake/SetupMLIR.cmake b/cmake/SetupMLIR.cmake new file mode 100644 index 0000000000..45a39682d7 --- /dev/null +++ b/cmake/SetupMLIR.cmake @@ -0,0 +1,44 @@ +# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM +# Copyright (c) 2025 Munich Quantum Software Company GmbH +# All rights reserved. +# +# SPDX-License-Identifier: MIT +# +# Licensed under the MIT License + +# set the include directory for the build tree +set(MQT_MLIR_INCLUDE_BUILD_DIR "${CMAKE_SOURCE_DIR}/mlir/include") +set(MQT_MLIR_MIN_VERSION 19.0) + +# MLIR must be installed on the system +find_package(MLIR REQUIRED CONFIG) +if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION) + message(FATAL_ERROR "MLIR version must be at least ${MQT_MLIR_MIN_VERSION}") +endif() +message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + +# Add the paths to the MLIR and LLVM CMake modules. +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + +# Include the TableGen, LLVM and MLIR CMake modules. +include(TableGen) +include(AddLLVM) +include(AddMLIR) +include(HandleLLVMOptions) + +include_directories(${LLVM_INCLUDE_DIRS}) +include_directories(${MLIR_INCLUDE_DIRS}) +include_directories(${MQT_MLIR_INCLUDE_BUILD_DIR}) +include_directories(${CMAKE_BINARY_DIR}/mlir/include) +link_directories(${LLVM_BUILD_LIBRARY_DIR}) +add_definitions(${LLVM_DEFINITIONS}) + +string(REPLACE "." ";" MLIR_VERSION_COMPONENTS ${MLIR_VERSION}) +list(GET MLIR_VERSION_COMPONENTS 0 MLIR_VERSION_MAJOR) +add_compile_definitions(MLIR_VERSION_MAJOR=${MLIR_VERSION_MAJOR}) + +# set the binary directory for the build tree such that, e.g., docs can be generated in the build +# tree +set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt index 91e4de8d00..f74a4ad202 100644 --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -6,43 +6,6 @@ # # Licensed under the MIT License -# set the include directory for the build tree -set(MQT_MLIR_INCLUDE_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") -set(MQT_MLIR_MIN_VERSION 19.0) - -# MLIR must be installed on the system -find_package(MLIR REQUIRED CONFIG) -if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION) - message(FATAL_ERROR "MLIR version must be at least ${MQT_MLIR_MIN_VERSION}") -endif() -message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - -# Add the paths to the MLIR and LLVM CMake modules. -list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") -list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") - -string(REPLACE "." ";" MLIR_VERSION_COMPONENTS ${MLIR_VERSION}) -list(GET MLIR_VERSION_COMPONENTS 0 MLIR_VERSION_MAJOR) -add_compile_definitions(MLIR_VERSION_MAJOR=${MLIR_VERSION_MAJOR}) - -# Include the TableGen, LLVM and MLIR CMake modules. -include(TableGen) -include(AddLLVM) -include(AddMLIR) -include(HandleLLVMOptions) - -include_directories(${LLVM_INCLUDE_DIRS}) -include_directories(${MLIR_INCLUDE_DIRS}) -include_directories(${MQT_MLIR_INCLUDE_BUILD_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) -link_directories(${LLVM_BUILD_LIBRARY_DIR}) -add_definitions(${LLVM_DEFINITIONS}) - -# set the binary directory for the build tree such that, e.g., docs can be generated in the build -# tree -set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) - # add a compile feature for C++17 set(CMAKE_CXX_STANDARD 17)