Ninja: error: unknown target check-mlir


I am completely new to LLVM or MLIR world. I was trying to build the llvm-project using the standard instruction from here (Getting started with MLIR).

And following is my cmake build config

cmake   \
    -G Ninja    \
    -S ../llvm  \
    -B .    \
    -DCMAKE_BUILD_TYPE=Release      \
    -DCMAKE_INSTALL_PREFIX=../installation  \
    -DCMAKE_C_COMPILER=clang    \
    -DCMAKE_CXX_COMPILER=clang++    \
    -DLLVM_USE_SANITIZER="Address;Undefined"    \

# ninja -j$(nproc)
cmake --build . --target check-mlir
# ninja install -j$(nproc)

And giving me this error

ninja: error: unknown target check-mlir

But if I use use ninja -j$(nproc) instead of cmake --build . --target check-mlir, it works perfectly. Could anyone please tell me why is this happening? And what actually this --target check-mlir does? I beg your pardon in advance for such naive question.

Following infos might help you to understand the problem

OS: Ubuntu server 22.04
cmake: 3.27.0
llvm prebuilt bins: 16.0.0
llvm-project clone: release/16.x
ninja bin: 1.11.1

Thanks in advance!


This works! Thanks @PeimingLiu
But another build issue arrives, and build is failing :confused:

mlir/unittests/Support/MathExtrasTest.cpp:10:10: fatal error: 'gmock/gmock.h' file not found
#include "gmock/gmock.h"

Any idea on this one?

And another question, for starting with MLIR, do I really need to use this unit tests while it is building?
My goal is to first work with the Toy example, then start to explore how to write dialects. And then writing my own transformations targeting HWs (e.g. HLS for Xilinx, CUDA for GPU).

Your thoughts?

-DLLVM_BUILD_TESTS=OFF is likely the cause of your problem here.

The standard instructions you linked should look like this:

cmake -G Ninja ../llvm \

I don’t know why you added options like “-DCLANG_BOOTSTRAP_PASSTHROUGH”?

Thanks a lot for pointing me to the right direction. :smiley:

Actually I’m a complete noob to this LLVM/MLIR world, trying to understand things by Trail & Error approach. My mistake. :neutral_face:

Following your given settings and @PeimingLiu , this is the configuration I’ve tried


Though I have a question. In your given cmake configuration, I am not seeing any cmake test configs are written. So does that mean, for a out-of-tree MLIR dev, I donot have to include these test configs?

And finally, this was my very first topics to this platform. I am really grateful that I have got such quick reply from @PeimingLiu and from a legend like you.

Thanks again.

I cannot set both of your answers as solution, So I choose final one from @mehdi_amini .

@PeimingLiu , I choose the last one, so that if a new comer arrives, and face similar problem, they can go through the whole discussion, and find the complete answer. So I beg your pardon, not for choosing your one. :innocent:


The default settings in cmake should include the right level of tests

1 Like

Sure thing! You should always pick Medhi’s suggestion, and welcome to the community!

1 Like