Standalone mlir project

I was trying to make MLIR’s toy tutorial a standalone project, but I got an error in cmake. This is my error message


This is my CMakeList.txt

# CMakeList.txt: Cmake
#
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 ("MLIRDemo")

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

find_package(LLVM REQUIRED CONFIG)

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

find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MILRConfig.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})

include_directories(${MLIR_INCLUDE_DIRS})

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

add_subdirectory(include)


add_mlir_dialect_library(toyLib 
        mlir/Dialect.cpp 
        mlir/MLIRGen.cpp
        
        ADDITIONAL_HEADER_DIRS 
        ${PROJECT_SOURCE_DIR}/include/toy 
        
        DEPENDS 
        ToyCh2OpsIncGen)

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
        toyLib
        )

add_llvm_executable(main-opt main.cpp parser/AST.cpp)
target_link_libraries(main-opt PRIVATE ${LIBS})

This is myCMakeLists.txt under include/toy

set(LLVM_TARGET_DEFINITIONS Ops.td)
mlir_tablegen(Ops.h.inc -gen-op-decls)
mlir_tablegen(Ops.cpp.inc -gen-op-defs)
add_public_tablegen_target(ToyCh2OpsIncGen)

Here is the structure of my project:
image

1 Like

With the directory layout as you have it, you should move this into a CMakeLists.txt in the mlir directory. LLVM rules that add libraries check their current directory to verify that all cpp sources were included (intending one library per directory). You can override this by adding PARTIAL_SOURCES_INTENDED to the add_*_library but it is better to comply with the directory structure the project likes.

Thank you for your reply. I did not choose to build Example when build the LLVM project. So I don’t include example in my LLVM and MLIR library. Because the LLVM project is huge and takes too long to compile, I don’t want to compile it all again. I am now copying CMakeLists.txt in MLIR and it works normally now