# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

if(MSVC)
  add_compile_definitions(_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING)
endif()

function(mqt_mlir_apply_target_options target_name)
  target_link_libraries(${target_name} PRIVATE MQT::ProjectOptions)
  llvm_update_compile_flags(${target_name})
  mqt_llvm_target_disable_rtti(${target_name})

  include(CheckCXXCompilerFlag)
  check_cxx_compiler_flag("-Wno-cast-qual" COMPILER_SUPPORTS_WNO_CAST_QUAL)

  if(COMPILER_SUPPORTS_WNO_CAST_QUAL)
    target_compile_options(${target_name} PRIVATE -Wno-cast-qual)
  endif()
endfunction()

function(mqt_mlir_target_use_project_options target_name)
  if(NOT TARGET MQT::ProjectOptions)
    message(FATAL_ERROR "MQT::ProjectOptions must be defined before using mlir targets.")
  endif()

  if(TARGET ${target_name})
    mqt_mlir_apply_target_options(${target_name})
  endif()

  if(TARGET obj.${target_name})
    mqt_mlir_apply_target_options(obj.${target_name})
  endif()
endfunction()

# add main library code
add_subdirectory(bench)
add_subdirectory(include)

# Prepare generated headers for clang-tidy without compiling or linking the project.
add_dependencies(
  mqt-core-lint-headers
  mlir-headers
  mlir-generic-headers
  MLIRJeffEnumsIncGen
  JeffToNativeIncGen
  NativeToJeffIncGen
  JeffToQCOIncGen
  CBitToMemRefIncGen
  QCOToJeffIncGen
  QCOToQCIncGen
  QCToQCOIncGen
  QCToQIRAdaptiveIncGen
  QCToQIRBaseIncGen
  MLIRMQTTransformsIncGen
  MLIRQCTransformsIncGen
  MLIRQCOTransformsIncGen
  MLIRQIRTransformsIncGen
  MLIRQTensorTransformsIncGen)
add_subdirectory(lib)
add_subdirectory(tools)

# add test code
if(BUILD_MQT_CORE_TESTS)
  add_subdirectory(unittests)
endif()
