Could not find MLIR

My CMake project can find LLVM, but not find MLIR


I did install MLIR, along with LLVM. Here is my installation location
image
Below is my CMakeLists.txt

# CMakeList.txt: 
#
cmake_minimum_required (VERSION 3.10)

if (POLICY CMP0068)
	cmake_policy(SET CMP0068 NEW)
	set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif ()

if(POLICY CMP0075)
	cmake_policy(SET CMP0075 NEW)
endif()

if (POLICY CMP0077)
	cmake_policy(SET CMP0077 NEW)
endif ()

project("QMIRDemo")

set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")

set(MLIR_DIR /usr/local/llvm/)

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Found LLVNMConfig.cmake in: ${LLVM_DIR}")

find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)

include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
link_directories(${LLVM_BUILD_LIBRARY_DIR})

include_directories(${MLIR_INCLUDE_DIRS})

include_directories(include/)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)

add_subdirectory(include)

add_subdirectory(dialect)

set(LLVM_COMPONENTS Support)

get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS 
		${dialect_libs} 
		${conversion_libs} 
        MLIROptLib 
		MLIRQuantum 
		MLIRTargetLLVMIR
        MLIRExecutionEngine
        MLIRStandard
        MLIRAffine
        LLVMLinker
		)

add_llvm_executable(qmir main.cpp mlir/MLIRGen.cpp)

llvm_update_compile_flags(qmir)

target_link_libraries(qmir
  PRIVATE
	${LIBS}
    MLIRAnalysis 
    MLIRCallInterfaces 
    MLIRIR
    MLIRParser 
    MLIRPass
    MLIRSideEffectInterfaces
    MLIRTransforms)```

You need to set MLIR_DIR to the directory containing the MLIRConfig.cmake, apparently in your case:

set(MLIR_DIR /usr/local/llvm/lib/cmake/mlir)

Steve

1 Like

Iā€™d also highly recommend using something close to HEAD, if at all possible. :slight_smile:

1 Like

It workes. Thank you