<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<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".<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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. 
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">#!/bin/bash<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">checkStatus() {<o:p></o:p></p>
<p class="MsoNormal">  if [ $? -ne 0 ]<o:p></o:p></p>
<p class="MsoNormal">  then<o:p></o:p></p>
<p class="MsoNormal">    echo Exit $wd with error $?: $1<o:p></o:p></p>
<p class="MsoNormal">    exit 127<o:p></o:p></p>
<p class="MsoNormal">  fi<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">INSTALLDIR=`pwd`/install<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">rm -rf build<o:p></o:p></p>
<p class="MsoNormal">rm -rf install<o:p></o:p></p>
<p class="MsoNormal">mkdir -p build<o:p></o:p></p>
<p class="MsoNormal">checkStatus "mkdir -p build"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">date<o:p></o:p></p>
<p class="MsoNormal">hostname<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">cd build<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">cmake \<o:p></o:p></p>
<p class="MsoNormal">  -G Ninja \<o:p></o:p></p>
<p class="MsoNormal">  ../llvm \<o:p></o:p></p>
<p class="MsoNormal">  -DCMAKE_BUILD_TYPE=Release \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_LIT_ARGS=-v \<o:p></o:p></p>
<p class="MsoNormal">  -DFLANG_ENABLE_WERROR=On \<o:p></o:p></p>
<p class="MsoNormal">  -DCMAKE_CXX_STANDARD=17 \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_ENABLE_PROJECTS="clang;mlir;flang;compiler-rt" \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_BUILD_TOOLS=On \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_INSTALL_UTILS=On \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_TARGETS_TO_BUILD=host \<o:p></o:p></p>
<p class="MsoNormal">  -DLLVM_ENABLE_ASSERTIONS=ON \<o:p></o:p></p>
<p class="MsoNormal">  -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$LD_LIBRARY_PATH" \<o:p></o:p></p>
<p class="MsoNormal">  -DCMAKE_INSTALL_PREFIX=$INSTALLDIR<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">checkStatus "cmake"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ninja<o:p></o:p></p>
<p class="MsoNormal">checkStatus "ninja"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ninja install<o:p></o:p></p>
<p class="MsoNormal">checkStatus "ninja install"<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> flang-dev <flang-dev-bounces@lists.llvm.org> <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> flang-dev@lists.llvm.org<br>
<b>Subject:</b> [flang-dev] Unknown CMake command "add_flang_library" error<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<table class="MsoNormalTable" border="1" cellpadding="0" style="background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .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><o:p></o:p></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">Hi Community,</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<o:p> </o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<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><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">-------------------------------------------------------------------------------------------------------</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">Make Warning (dev) in CMakeLists.txt:</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">No project() command is present. The top-level CMakeLists.txt file must</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">contain a literal, direct call to the project() command. Add a line of</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">code such as</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">project(ProjectName)</span> <o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">near the top of the file, but after cmake_minimum_required().</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">CMake is pretending there is a "project(Project)" command on the first</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">line.</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">This warning is for project developers. Use -Wno-dev to suppress it.</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<b><span style="font-family:"Arial",sans-serif">CMake Error at Common/CMakeLists.txt:2 (add_flang_library):</span></b><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<b><span style="font-family:"Arial",sans-serif">Unknown CMake command "add_flang_library".</span></b><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">CMake Warning (dev) in CMakeLists.txt:</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">No cmake_minimum_required command is present. A line of code such as</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">cmake_minimum_required(VERSION 3.16)</span>
<o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">should be added at the top of the file. The version specified may be lower</span>
<o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">if you wish to support older CMake versions for this project. For more</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">information run "cmake --help-policy CMP0000".</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">This warning is for project developers. Use -Wno-dev to suppress it.</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<span style="font-family:"Arial",sans-serif">-- Configuring incomplete, errors occurred!</span><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
-------------------------------------------------------------------------------------------------------<o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<o:p> </o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<b><span style="font-family:"Arial",sans-serif">Command used for building Flang :
</span></b><code><span style="font-size:10.0pt;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><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<code><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Clang, mlir and llvm were built in release mode before building Flang.</span></code><o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<code><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Please guide.</span></code>
<o:p></o:p></p>
<p style="margin-bottom:0in;background-attachment:scroll;background-position-x:0%;background-position-y:0%">
<code><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Thanks</span></code><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>