<div dir="ltr"><div>Thanks Peter.</div><div><br></div><div>I would like to share how I am building flang using README.md document given in llvm-project/flang.</div><div><br></div><div>Before building flang in debug mode, I had built clang, mlir , llvm in release mode by using README.md documentation given in llvm-project.</div><div>The steps I have used to build clang,mlir,llvm in release mode are given below:</div><div>1)  <code>


        
        <span></span></code><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><font face="arial, sans-serif">git clone
<a href="https://github.com/llvm/llvm-project.git" style="color:rgb(0,0,128);text-decoration:underline">https://github.com/llvm/llvm-project.git</a><br></font></code></div><div><code><font face="arial, sans-serif">2) cd llvm-project</font></code></div><div><code><font face="arial, sans-serif">3) mkdir build</font></code></div><div><code><font face="arial, sans-serif">4) cd build</font></code></div><div><code><font face="arial, sans-serif">5) </font></code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">cmake ../llvm -G </code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">Ninja</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">
-DLLVM_ENABLE_PROJECTS="clang;mlir</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">"
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=/home/llvm-project/build <br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">6) ninja</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">It is working and after completion of build process of clang and mlir, I started <code class="gmail-western" style="font-family:"Liberation Mono",monospace">out of tree </code>debug build process for flang.</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">for this build process I followed the README.md document in flang github repository.</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">Steps are:</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">1) cd llvm-project</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">2) cd flang</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">3) mkdir build</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">4) cd build</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">5) 


        
        <span></span></code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">cmake </code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">-DLLVM_DIR=/home/llvm-project/build/lib/cmake/</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">llvm -</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">D</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">CLANG</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">_DIR=/home/llvm-project/build/lib/cmake/</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">clang </code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">-D</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">MLIR</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">_DIR=/home/llvm-project/build/lib/cmake/</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">mlir </code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">../</code><code class="gmail-western" style="font-family:"Liberation Mono",monospace">lib</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">after running cmake , There is a error related to add_flang_library which was shared in previous email.<br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><b><code class="gmail-western" style="font-family:"Liberation Mono",monospace">  CMake Error at Common/CMakeLists.txt:2 (add_flang_library):<br>    Unknown CMake command "add_flang_library".<br></code></b></div><div><b><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></b></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">I followed the steps according to README.md document.</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">Please guide according to the information given in github repo.</code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">Is there any issue with the steps which I have used from github repo?<br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace">Thanks and Regards<br></code></div><div><b><code class="gmail-western" style="font-family:"Liberation Mono",monospace"></code></b></div><div><b><code class="gmail-western" style="font-family:"Liberation Mono",monospace"></code></b>

</div><div><code class="gmail-western" style="font-family:"Liberation Mono",monospace"><br></code></div><div>
<code></code>

</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 22 Dec 2021 at 03:14, 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 style="overflow-wrap: break-word;" lang="EN-US">
<div class="gmail-m_-7294062177181518359WordSection1">
<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-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;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 style="background:rgb(255,235,156) none repeat scroll 0% 0%" cellpadding="0" border="1">
<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>
<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>