<div dir="ltr">I did the same and this time I got an error related to AddClang and 

clang_target_link_libraries.<div><b>CMake Error at CMakeLists.txt:77 (include):<br>  include could not find load file:<br><br>    AddClang</b><br></div><div><b><br></b></div><div>-- Flang version: 14.0.0<br>-- Check if the system is big endian<br>-- Searching 16 bit integer<br>-- Looking for sys/types.h<br>-- Looking for sys/types.h - found<br>-- Looking for stdint.h<br>-- Looking for stdint.h - found<br>-- Looking for stddef.h<br>-- Looking for stddef.h - found<br>-- Check size of unsigned short<br>-- Check size of unsigned short - done<br>-- Using unsigned short<br>-- Check if the system is big endian - little endian<br>-- Performing Test CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG<br>-- Performing Test CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG - Success<br>-- Performing Test CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG<br>-- Performing Test CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG - Failed<br>-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG<br>-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Failed<br><b>CMake Error at tools/flang-driver/CMakeLists.txt:24 (clang_target_link_libraries):<br>  Unknown CMake command "clang_target_link_libraries".<br></b></div><div><b><br></b></div><div><b>Any hint why it is happening?</b></div><div><b><br></b></div><div><b><br></b></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 26 Dec 2021 at 10:34, Peter Steinfeld <<a href="mailto:psteinfeld@nvidia.com">psteinfeld@nvidia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="gmail-m_-7260266975640266456WordSection1">
<p class="MsoNormal">I think that the immediate problem is that step 5) for the out-of-tree build should end in “..” rather than “../lib”.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Pete<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> a sk <<a href="mailto:sacodework@gmail.com" target="_blank">sacodework@gmail.com</a>> <br>
<b>Sent:</b> Thursday, December 23, 2021 9:14 AM<br>
<b>To:</b> Peter Steinfeld <<a href="mailto:psteinfeld@nvidia.com" target="_blank">psteinfeld@nvidia.com</a>><br>
<b>Cc:</b> flang-dev on LLVM <<a href="mailto:flang-dev@lists.llvm.org" target="_blank">flang-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [flang-dev] Unknown CMake command "add_flang_library" error<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<table border="1" cellspacing="3" cellpadding="0" style="background:rgb(255,235,156)">
<tbody>
<tr>
<td style="padding:0.75pt">
<p class="MsoNormal"><b><span style="font-size:7.5pt;font-family:Verdana,sans-serif;color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt;font-family:Verdana,sans-serif;color:black">
</span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal">Thanks Peter.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I would like to share how I am building flang using README.md document given in llvm-project/flang.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Before building flang in debug mode, I had built clang, mlir , llvm in release mode by using README.md documentation given in llvm-project.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">The steps I have used to build clang,mlir,llvm in release mode are given below:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">1)  <code><span style="font-size:10pt;font-family:Arial,sans-serif">git clone
<a href="https://github.com/llvm/llvm-project.git" target="_blank"><span style="color:navy">https://github.com/llvm/llvm-project.git</span></a></span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:Arial,sans-serif">2) cd llvm-project</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:Arial,sans-serif">3) mkdir build</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:Arial,sans-serif">4) cd build</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt;font-family:Arial,sans-serif">5)
</span></code><code><span style="font-size:10pt">cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang;mlir" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/llvm-project/build
</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">6) ninja</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">It is working and after completion of build process of clang and mlir, I started out of tree debug build process for flang.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">for this build process I followed the README.md document in flang github repository.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">Steps are:</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">1) cd llvm-project</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">2) cd flang</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">3) mkdir build</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">4) cd build</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">5) cmake -DLLVM_DIR=/home/llvm-project/build/lib/cmake/llvm -DCLANG_DIR=/home/llvm-project/build/lib/cmake/clang -DMLIR_DIR=/home/llvm-project/build/lib/cmake/mlir ../lib</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">after running cmake , There is a error related to add_flang_library which was shared in previous email.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><b><span style="font-size:10pt">  CMake Error at Common/CMakeLists.txt:2 (add_flang_library):</span></b></code><b><span style="font-size:10pt;font-family:"Courier New""><br>
<code>    Unknown CMake command "add_flang_library".</code></span></b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">I followed the steps according to README.md document.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">Please guide according to the information given in github repo.</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">Is there any issue with the steps which I have used from github repo?</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><code><span style="font-size:10pt">Thanks and Regards</span></code><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, 22 Dec 2021 at 03:14, Peter Steinfeld <<a href="mailto:psteinfeld@nvidia.com" target="_blank">psteinfeld@nvidia.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">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".<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">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. 
<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">#!/bin/bash<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">checkStatus() {<u></u><u></u></p>
<p class="MsoNormal">  if [ $? -ne 0 ]<u></u><u></u></p>
<p class="MsoNormal">  then<u></u><u></u></p>
<p class="MsoNormal">    echo Exit $wd with error $?: $1<u></u><u></u></p>
<p class="MsoNormal">    exit 127<u></u><u></u></p>
<p class="MsoNormal">  fi<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">INSTALLDIR=`pwd`/install<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">rm -rf build<u></u><u></u></p>
<p class="MsoNormal">rm -rf install<u></u><u></u></p>
<p class="MsoNormal">mkdir -p build<u></u><u></u></p>
<p class="MsoNormal">checkStatus "mkdir -p build"<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">date<u></u><u></u></p>
<p class="MsoNormal">hostname<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">cd build<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">cmake \<u></u><u></u></p>
<p class="MsoNormal">  -G Ninja \<u></u><u></u></p>
<p class="MsoNormal">  ../llvm \<u></u><u></u></p>
<p class="MsoNormal">  -DCMAKE_BUILD_TYPE=Release \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_LIT_ARGS=-v \<u></u><u></u></p>
<p class="MsoNormal">  -DFLANG_ENABLE_WERROR=On \<u></u><u></u></p>
<p class="MsoNormal">  -DCMAKE_CXX_STANDARD=17 \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_ENABLE_PROJECTS="clang;mlir;flang;compiler-rt" \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_BUILD_TOOLS=On \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_INSTALL_UTILS=On \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_TARGETS_TO_BUILD=host \<u></u><u></u></p>
<p class="MsoNormal">  -DLLVM_ENABLE_ASSERTIONS=ON \<u></u><u></u></p>
<p class="MsoNormal">  -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$LD_LIBRARY_PATH" \<u></u><u></u></p>
<p class="MsoNormal">  -DCMAKE_INSTALL_PREFIX=$INSTALLDIR<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">checkStatus "cmake"<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">ninja<u></u><u></u></p>
<p class="MsoNormal">checkStatus "ninja"<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">ninja install<u></u><u></u></p>
<p class="MsoNormal">checkStatus "ninja install"<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div style="border-right:none currentcolor;border-bottom:none currentcolor;border-left:none currentcolor;border-top:1pt solid currentcolor;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> flang-dev <<a href="mailto:flang-dev-bounces@lists.llvm.org" target="_blank">flang-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>a sk via flang-dev<br>
<b>Sent:</b> Tuesday, December 21, 2021 9:07 AM<br>
<b>To:</b> <a href="mailto:flang-dev@lists.llvm.org" target="_blank">flang-dev@lists.llvm.org</a><br>
<b>Subject:</b> [flang-dev] Unknown CMake command "add_flang_library" error<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<table border="1" cellspacing="3" cellpadding="0" style="background:rgb(255,235,156)">
<tbody>
<tr>
<td style="padding:0.75pt">
<p class="MsoNormal"><b><span style="font-size:7.5pt;font-family:Verdana,sans-serif;color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt;font-family:Verdana,sans-serif;color:black">
</span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="color:white"> </span><u></u><u></u></p>
<div>
<div>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">Hi Community,</span><u></u><u></u></p>
<p style="margin-bottom:0in"> <u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">I am building Flang out of tree but getting error related to add_flang_library i.e.
</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">-------------------------------------------------------------------------------------------------------</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">Make Warning (dev) in CMakeLists.txt:</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">No project() command is present. The top-level CMakeLists.txt file must</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">contain a literal, direct call to the project() command. Add a line of</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">code such as</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">project(ProjectName)</span>
<u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">near the top of the file, but after cmake_minimum_required().</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">CMake is pretending there is a "project(Project)" command on the first</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">line.</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">This warning is for project developers. Use -Wno-dev to suppress it.</span><u></u><u></u></p>
<p style="margin-bottom:0in"><b><span style="font-family:Arial,sans-serif">CMake Error at Common/CMakeLists.txt:2 (add_flang_library):</span></b><u></u><u></u></p>
<p style="margin-bottom:0in"><b><span style="font-family:Arial,sans-serif">Unknown CMake command "add_flang_library".</span></b><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">CMake Warning (dev) in CMakeLists.txt:</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">No cmake_minimum_required command is present. A line of code such as</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">cmake_minimum_required(VERSION 3.16)</span>
<u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">should be added at the top of the file. The version specified may be lower</span>
<u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">if you wish to support older CMake versions for this project. For more</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">information run "cmake --help-policy CMP0000".</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">This warning is for project developers. Use -Wno-dev to suppress it.</span><u></u><u></u></p>
<p style="margin-bottom:0in"><span style="font-family:Arial,sans-serif">-- Configuring incomplete, errors occurred!</span><u></u><u></u></p>
<p style="margin-bottom:0in">-------------------------------------------------------------------------------------------------------<u></u><u></u></p>
<p style="margin-bottom:0in"> <u></u><u></u></p>
<p style="margin-bottom:0in"><b><span style="font-family:Arial,sans-serif">Command used for building Flang :
</span></b><code><span style="font-size:10pt;font-family:Arial,sans-serif">cmake -DLLVM_DIR=llvm-project/build/lib/cmake/llvm -DCLANG_DIR=llvm-project/build/lib/cmake/clang -DMLIR_DIR=llvm-project/build/lib/cmake/mlir -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=llvm-project/flang/build
 ../lib</span></code><u></u><u></u></p>
<p style="margin-bottom:0in"><code><span style="font-size:10pt;font-family:Arial,sans-serif">Clang, mlir and llvm were built in release mode before building Flang.</span></code><u></u><u></u></p>
<p style="margin-bottom:0in"><code><span style="font-size:10pt;font-family:Arial,sans-serif">Please guide.</span></code>
<u></u><u></u></p>
<p style="margin-bottom:0in"><code><span style="font-size:10pt;font-family:Arial,sans-serif">Thanks</span></code><u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>

</blockquote></div>