Unknown CMake command "add_flang_library" error

Hi Community,

I am building Flang out of tree but getting error related to add_flang_library i.e.

I’m not sure what’s causing your specific error message, but I notice that you’re not doing an out-of-tree build the same way that I do. After doing the full, in-tree build, I also create an install area using the command “make install” (actually, for me, “ninja install”) to create the mlir and clang libraries and include files on which the out-of-tree build depends. I first “cd” to the build directory that contains the full, in-tree build, and then execute “make install”. This creates and populates a directory called “install” parallel to the directory called “build”.

Wackily, in order to pick up the Google test related files, the out-of-tree build depends on the build area for the llvm files.

After creating the build and install areas for my full, in-tree build (called “base” below), I create a source directory that contains all of the flang (and llvm, clang, and mlir) source. I then “cd” to the directory above the “flang” directory and execute a script that looks like the commands below. Note that the directories for mlir and clang come from the install area and the directories from llvm come from the build area.


checkStatus() {

if [ $? -ne 0 ]


echo Exit $wd with error $?: $1

exit 127




rm -rf build

rm -rf install

mkdir -p build

checkStatus “mkdir -p build”



cd build

cmake \

-G Ninja \

…/llvm \





-DLLVM_ENABLE_PROJECTS=“clang;mlir;flang;compiler-rt” \







checkStatus “cmake”


checkStatus “ninja”

ninja install

checkStatus “ninja install”

You can also have a look at the commands that our out of tree buildbot is running:

Just navigate to the latest green build and you should be able to see everything it does.


Thanks, Diana.

But I’d be cautious about using the build bots. I don’t think we actually run any tests on the results of their builds.


Thanks Peter.

I would like to share how I am building flang using README.md document given in llvm-project/flang.

Before building flang in debug mode, I had built clang, mlir , llvm in release mode by using README.md documentation given in llvm-project.
The steps I have used to build clang,mlir,llvm in release mode are given below:

  1. ```git clone https://github.com/llvm/llvm-project.git`

2) cd llvm-project
3) mkdir build
4) cd build
5) ``cmake ../llvm -G ``Ninja`` -DLLVM_ENABLE_PROJECTS="clang;mlir``" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/llvm-project/build

6) ninja

It is working and after completion of build process of clang and mlir, I started out of tree debug build process for flang.

for this build process I followed the README.md document in flang github repository.
Steps are:
1) cd llvm-project
2) cd flang
3) mkdir build
4) cd build
5) ``cmake ``-DLLVM_DIR=/home/llvm-project/build/lib/cmake/``llvm -``D``CLANG``_DIR=/home/llvm-project/build/lib/cmake/``clang ``-D``MLIR``_DIR=/home/llvm-project/build/lib/cmake/``mlir ``../``lib

after running cmake , There is a error related to add_flang_library which was shared in previous email.

CMake Error at Common/CMakeLists.txt:2 (add_flang_library):
Unknown CMake command "add_flang_library".

I followed the steps according to README.md document.
Please guide according to the information given in github repo.

Is there any issue with the steps which I have used from github repo?

Thanks and Regards

** **


I think that the immediate problem is that step 5) for the out-of-tree build should end in “…” rather than “…/lib”.


I did the same and this time I got an error related to AddClang and clang_target_link_libraries.
CMake Error at CMakeLists.txt:77 (include):
include could not find load file:


– Flang version: 14.0.0
– Check if the system is big endian
– Searching 16 bit integer
– Looking for sys/types.h
– Looking for sys/types.h - found
– Looking for stdint.h
– Looking for stdint.h - found
– Looking for stddef.h
– Looking for stddef.h - found
– Check size of unsigned short
– Check size of unsigned short - done
– Using unsigned short
– Check if the system is big endian - little endian
CMake Error at tools/flang-driver/CMakeLists.txt:24 (clang_target_link_libraries):
Unknown CMake command “clang_target_link_libraries”.

Any hint why it is happening?

I’m not sure, but I suspect that you’re not using the install area from your out-of-tree build to specify the locations of the files from the clang and mlir builds. Refer to my message of 12/21 for more information.

When you do an out-of-tree build, the prebuilt libraries come from two places, the build area of the in-tree build on which your out-of-tree build is based, and the associated install area. So, after doing the complete build of the base, out-of-tree build, while you’re in the directory called “build”, do a “make install” or a “ninja install”. This will create and populate a directory called “install” that’s a sibling to the directory called “build”. Then, in your build script for the out-of-tree build, specify that the files from the llvm project come from the build area and the files from the clang and mlir projects come from the install area. Here are the commandx that I use for my out of tree builds to make that happen. While in the flang directory, I do

mkdir build

cd build

cmake \

-G Ninja \

-DLLVM_DIR=$base/build/lib/cmake/llvm \

-DCLANG_DIR=$base/install/lib/cmake/clang \

-DMLIR_DIR=$base/install/lib/cmake/mlir \

Let me know if you run into any difficulties.