1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Building LLVM with CMake — LLVM 13 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="CMake Primer" href="CMakePrimer.html" />
<link rel="prev" title="Control Flow Verification Tool Design Document" href="CFIVerify.html" />
<style type="text/css">
table.right { float: right; margin-left: 20px; }
table.right td { border: 1px solid #ccc; }
</style>
</head><body>
<div class="logo">
<a href="index.html">
<img src="_static/logo.png"
alt="LLVM Logo" width="250" height="88"/></a>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="CMakePrimer.html" title="CMake Primer"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="CFIVerify.html" title="Control Flow Verification Tool Design Document"
accesskey="P">previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="UserGuides.html" accesskey="U">User Guides</a> »</li>
<li class="nav-item nav-item-this"><a href="">Building LLVM with CMake</a></li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3>Documentation</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/GettingStartedTutorials.html">Getting Started/Tutorials</a></li>
<li><a href="https://llvm.org/docs/UserGuides.html">User Guides</a></li>
<li><a href="https://llvm.org/docs/Reference.html">Reference</a></li>
</ul>
<h3>Getting Involved</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/Contributing.html">Contributing to LLVM</a></li>
<li><a href="https://llvm.org/docs/HowToSubmitABug.html">Submitting Bug Reports</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#mailing-lists">Mailing Lists</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#irc">IRC</a></li>
<li><a href="https://llvm.org/docs/GettingInvolved.html#meetups-and-social-events">Meetups and Social Events</a></li>
</ul>
<h3>Additional Links</h3>
<ul class="want-points">
<li><a href="https://llvm.org/docs/FAQ.html">FAQ</a></li>
<li><a href="https://llvm.org/docs/Lexicon.html">Glossary</a></li>
<li><a href="https://llvm.org/pubs">Publications</a></li>
<li><a href="https://github.com/llvm/llvm-project//">Github Repository</a></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/CMake.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="building-llvm-with-cmake">
<h1>Building LLVM with CMake<a class="headerlink" href="#building-llvm-with-cmake" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#introduction" id="id7">Introduction</a></p></li>
<li><p><a class="reference internal" href="#quick-start" id="id8">Quick start</a></p></li>
<li><p><a class="reference internal" href="#usage" id="id9">Basic CMake usage</a></p></li>
<li><p><a class="reference internal" href="#options-and-variables" id="id10">Options and variables</a></p>
<ul>
<li><p><a class="reference internal" href="#frequently-used-cmake-variables" id="id11">Frequently-used CMake variables</a></p></li>
<li><p><a class="reference internal" href="#frequently-used-llvm-related-variables" id="id12">Frequently Used LLVM-related variables</a></p></li>
<li><p><a class="reference internal" href="#rarely-used-cmake-variables" id="id13">Rarely-used CMake variables</a></p></li>
<li><p><a class="reference internal" href="#llvm-related-variables" id="id14">LLVM-related variables</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#cmake-caches" id="id15">CMake Caches</a></p></li>
<li><p><a class="reference internal" href="#executing-the-tests" id="id16">Executing the Tests</a></p></li>
<li><p><a class="reference internal" href="#cross-compiling" id="id17">Cross compiling</a></p></li>
<li><p><a class="reference internal" href="#embedding-llvm-in-your-project" id="id18">Embedding LLVM in your project</a></p>
<ul>
<li><p><a class="reference internal" href="#developing-llvm-passes-out-of-source" id="id19">Developing LLVM passes out of source</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#compiler-platform-specific-topics" id="id20">Compiler/Platform-specific topics</a></p>
<ul>
<li><p><a class="reference internal" href="#microsoft-visual-c" id="id21">Microsoft Visual C++</a></p></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id7">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.cmake.org/">CMake</a> is a cross-platform build-generator tool. CMake
does not build the project, it generates the files needed by your build tool
(GNU make, Visual Studio, etc.) for building LLVM.</p>
<p>If <strong>you are a new contributor</strong>, please start with the <a class="reference internal" href="GettingStarted.html"><span class="doc">Getting Started with the LLVM System</span></a>
page. This page is geared for existing contributors moving from the
legacy configure/make system.</p>
<p>If you are really anxious about getting a functional LLVM build, go to the
<a class="reference internal" href="#quick-start">Quick start</a> section. If you are a CMake novice, start with <a class="reference internal" href="#basic-cmake-usage">Basic CMake usage</a>
and then go back to the <a class="reference internal" href="#quick-start">Quick start</a> section once you know what you are doing. The
<a class="reference internal" href="#options-and-variables">Options and variables</a> section is a reference for customizing your build. If
you already have experience with CMake, this is the recommended starting point.</p>
<p>This page is geared towards users of the LLVM CMake build. If you’re looking for
information about modifying the LLVM CMake build system you may want to see the
<a class="reference internal" href="CMakePrimer.html"><span class="doc">CMake Primer</span></a> page. It has a basic overview of the CMake language.</p>
</div>
<div class="section" id="quick-start">
<span id="id1"></span><h2><a class="toc-backref" href="#id8">Quick start</a><a class="headerlink" href="#quick-start" title="Permalink to this headline">¶</a></h2>
<p>We use here the command-line, non-interactive CMake interface.</p>
<ol class="arabic">
<li><p><a class="reference external" href="http://www.cmake.org/cmake/resources/software.html">Download</a> and install
CMake. Version 3.13.4 is the minimum required.</p></li>
<li><p>Open a shell. Your development tools must be reachable from this shell
through the PATH environment variable.</p></li>
<li><p>Create a build directory. Building LLVM in the source
directory is not supported. cd to this directory:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> mkdir mybuilddir
<span class="gp">$</span> <span class="nb">cd</span> mybuilddir
</pre></div>
</div>
</li>
<li><p>Execute this command in the shell replacing <cite>path/to/llvm/source/root</cite> with
the path to the root of your LLVM source tree:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake path/to/llvm/source/root
</pre></div>
</div>
<p>CMake will detect your development environment, perform a series of tests, and
generate the files required for building LLVM. CMake will use default values
for all build parameters. See the <a class="reference internal" href="#options-and-variables">Options and variables</a> section for
a list of build parameters that you can modify.</p>
<p>This can fail if CMake can’t detect your toolset, or if it thinks that the
environment is not sane enough. In this case, make sure that the toolset that
you intend to use is the only one reachable from the shell, and that the shell
itself is the correct one for your development environment. CMake will refuse
to build MinGW makefiles if you have a POSIX shell reachable through the PATH
environment variable, for instance. You can force CMake to use a given build
tool; for instructions, see the <a class="reference internal" href="#usage">Usage</a> section, below. You may
also wish to control which targets LLVM enables, or which LLVM
components are built; see the <a class="reference internal" href="#frequently-used-llvm-related-variables">Frequently Used LLVM-related
variables</a> below.</p>
</li>
<li><p>After CMake has finished running, proceed to use IDE project files, or start
the build from the build directory:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake --build .
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">--build</span></code> option tells <code class="docutils literal notranslate"><span class="pre">cmake</span></code> to invoke the underlying build
tool (<code class="docutils literal notranslate"><span class="pre">make</span></code>, <code class="docutils literal notranslate"><span class="pre">ninja</span></code>, <code class="docutils literal notranslate"><span class="pre">xcodebuild</span></code>, <code class="docutils literal notranslate"><span class="pre">msbuild</span></code>, etc.)</p>
<p>The underlying build tool can be invoked directly, of course, but
the <code class="docutils literal notranslate"><span class="pre">--build</span></code> option is portable.</p>
</li>
<li><p>After LLVM has finished building, install it from the build directory:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake --build . --target install
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">--target</span></code> option with <code class="docutils literal notranslate"><span class="pre">install</span></code> parameter in addition to
the <code class="docutils literal notranslate"><span class="pre">--build</span></code> option tells <code class="docutils literal notranslate"><span class="pre">cmake</span></code> to build the <code class="docutils literal notranslate"><span class="pre">install</span></code> target.</p>
<p>It is possible to set a different install prefix at installation time
by invoking the <code class="docutils literal notranslate"><span class="pre">cmake_install.cmake</span></code> script generated in the
build directory:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -DCMAKE_INSTALL_PREFIX<span class="o">=</span>/tmp/llvm -P cmake_install.cmake
</pre></div>
</div>
</li>
</ol>
</div>
<div class="section" id="usage">
<span id="basic-cmake-usage"></span><span id="id2"></span><h2><a class="toc-backref" href="#id9">Basic CMake usage</a><a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>This section explains basic aspects of CMake
which you may need in your day-to-day usage.</p>
<p>CMake comes with extensive documentation, in the form of html files, and as
online help accessible via the <code class="docutils literal notranslate"><span class="pre">cmake</span></code> executable itself. Execute <code class="docutils literal notranslate"><span class="pre">cmake</span>
<span class="pre">--help</span></code> for further help options.</p>
<p>CMake allows you to specify a build tool (e.g., GNU make, Visual Studio,
or Xcode). If not specified on the command line, CMake tries to guess which
build tool to use, based on your environment. Once it has identified your
build tool, CMake uses the corresponding <em>Generator</em> to create files for your
build tool (e.g., Makefiles or Visual Studio or Xcode project files). You can
explicitly specify the generator with the command line option <code class="docutils literal notranslate"><span class="pre">-G</span> <span class="pre">"Name</span> <span class="pre">of</span> <span class="pre">the</span>
<span class="pre">generator"</span></code>. To see a list of the available generators on your system, execute</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake --help
</pre></div>
</div>
<p>This will list the generator names at the end of the help text.</p>
<p>Generators’ names are case-sensitive, and may contain spaces. For this reason,
you should enter them exactly as they are listed in the <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--help</span></code>
output, in quotes. For example, to generate project files specifically for
Visual Studio 12, you can execute:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -G <span class="s2">"Visual Studio 12"</span> path/to/llvm/source/root
</pre></div>
</div>
<p>For a given development platform there can be more than one adequate
generator. If you use Visual Studio, “NMake Makefiles” is a generator you can use
for building with NMake. By default, CMake chooses the most specific generator
supported by your development environment. If you want an alternative generator,
you must tell this to CMake with the <code class="docutils literal notranslate"><span class="pre">-G</span></code> option.</p>
</div>
<div class="section" id="options-and-variables">
<span id="id4"></span><h2><a class="toc-backref" href="#id10">Options and variables</a><a class="headerlink" href="#options-and-variables" title="Permalink to this headline">¶</a></h2>
<p>Variables customize how the build will be generated. Options are boolean
variables, with possible values ON/OFF. Options and variables are defined on the
CMake command line like this:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -DVARIABLE<span class="o">=</span>value path/to/llvm/source
</pre></div>
</div>
<p>You can set a variable after the initial CMake invocation to change its
value. You can also undefine a variable:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -UVARIABLE path/to/llvm/source
</pre></div>
</div>
<p>Variables are stored in the CMake cache. This is a file named <code class="docutils literal notranslate"><span class="pre">CMakeCache.txt</span></code>
stored at the root of your build directory that is generated by <code class="docutils literal notranslate"><span class="pre">cmake</span></code>.
Editing it yourself is not recommended.</p>
<p>Variables are listed in the CMake cache and later in this document with
the variable name and type separated by a colon. You can also specify the
variable and type on the CMake command line:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -DVARIABLE:TYPE<span class="o">=</span>value path/to/llvm/source
</pre></div>
</div>
<div class="section" id="frequently-used-cmake-variables">
<h3><a class="toc-backref" href="#id11">Frequently-used CMake variables</a><a class="headerlink" href="#frequently-used-cmake-variables" title="Permalink to this headline">¶</a></h3>
<p>Here are some of the CMake variables that are used often, along with a
brief explanation. For full documentation, consult the CMake manual,
or execute <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--help-variable</span> <span class="pre">VARIABLE_NAME</span></code>. See <a class="reference internal" href="#frequently-used-llvm-related-variables">Frequently
Used LLVM-related Variables</a> below for information about commonly
used variables that control features of LLVM and enabled subprojects.</p>
<dl class="simple">
<dt><strong>CMAKE_BUILD_TYPE</strong>:STRING</dt><dd><p>Sets the build type for <code class="docutils literal notranslate"><span class="pre">make</span></code>-based generators. Possible values are
Release, Debug, RelWithDebInfo and MinSizeRel. If you are using an IDE such as
Visual Studio, you should use the IDE settings to set the build type.
Be aware that Release and RelWithDebInfo use different optimization levels on
most platforms. Be aware that Release and
RelWithDebInfo use different optimization levels on most
platforms, and that the default value of <code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_ASSERTIONS</span></code>
is affected.</p>
</dd>
<dt><strong>CMAKE_INSTALL_PREFIX</strong>:PATH</dt><dd><p>Path where LLVM will be installed when the “install” target is built.</p>
</dd>
<dt><strong>CMAKE_{C,CXX}_FLAGS</strong>:STRING</dt><dd><p>Extra flags to use when compiling C and C++ source files respectively.</p>
</dd>
<dt><strong>CMAKE_{C,CXX}_COMPILER</strong>:STRING</dt><dd><p>Specify the C and C++ compilers to use. If you have multiple
compilers installed, CMake might not default to the one you wish to
use.</p>
</dd>
</dl>
</div>
<div class="section" id="frequently-used-llvm-related-variables">
<span id="id5"></span><h3><a class="toc-backref" href="#id12">Frequently Used LLVM-related variables</a><a class="headerlink" href="#frequently-used-llvm-related-variables" title="Permalink to this headline">¶</a></h3>
<p>The default configuration may not match your requirements. Here are
LLVM variables that are frequently used to control that. The full
description is in <a class="reference internal" href="#llvm-related-variables">LLVM-related variables</a> below.</p>
<dl class="simple">
<dt><strong>LLVM_ENABLE_PROJECTS</strong>:STRING</dt><dd><p>Control which projects are enabled. For example you may want to work on clang
or lldb by specifying <code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_PROJECTS="clang;lldb"</span></code>.</p>
</dd>
<dt><strong>LLVM_LIBDIR_SUFFIX</strong>:STRING</dt><dd><p>Extra suffix to append to the directory where libraries are to be
installed. On a 64-bit architecture, one could use <code class="docutils literal notranslate"><span class="pre">-DLLVM_LIBDIR_SUFFIX=64</span></code>
to install libraries to <code class="docutils literal notranslate"><span class="pre">/usr/lib64</span></code>.</p>
</dd>
<dt><strong>LLVM_PARALLEL_{COMPILE,LINK}_JOBS</strong>:STRING</dt><dd><p>Building the llvm toolchain can use a lot of resources, particularly
linking. These options, when you use the Ninja generator, allow you
to restrict the parallelism. For example, to avoid OOMs or going
into swap, permit only one link job per 15GB of RAM available on a
32GB machine, specify <code class="docutils literal notranslate"><span class="pre">-G</span> <span class="pre">Ninja</span> <span class="pre">-DLLVM_PARALLEL_LINK_JOBS=2</span></code>.</p>
</dd>
<dt><strong>LLVM_TARGETS_TO_BUILD</strong>:STRING</dt><dd><p>Control which targets are enabled. For example you may only need to enable
your native target with, for example, <code class="docutils literal notranslate"><span class="pre">-DLLVM_TARGETS_TO_BUILD=X86</span></code>.</p>
</dd>
<dt><strong>LLVM_USE_LINKER</strong>:STRING</dt><dd><p>Override the system’s default linker. For instance use <code class="docutils literal notranslate"><span class="pre">lld</span></code> with
<code class="docutils literal notranslate"><span class="pre">-DLLVM_USE_LINKER=lld</span></code>.</p>
</dd>
</dl>
</div>
<div class="section" id="rarely-used-cmake-variables">
<h3><a class="toc-backref" href="#id13">Rarely-used CMake variables</a><a class="headerlink" href="#rarely-used-cmake-variables" title="Permalink to this headline">¶</a></h3>
<p>Here are some of the CMake variables that are rarely used, along with a brief
explanation and LLVM-related notes. For full documentation, consult the CMake
manual, or execute <code class="docutils literal notranslate"><span class="pre">cmake</span> <span class="pre">--help-variable</span> <span class="pre">VARIABLE_NAME</span></code>.</p>
<dl class="simple">
<dt><strong>CMAKE_CXX_STANDARD</strong>:STRING</dt><dd><p>Sets the C++ standard to conform to when building LLVM. Possible values are
14, 17, 20. LLVM Requires C++ 14 or higher. This defaults to 14.</p>
</dd>
</dl>
</div>
<div class="section" id="llvm-related-variables">
<span id="id6"></span><h3><a class="toc-backref" href="#id14">LLVM-related variables</a><a class="headerlink" href="#llvm-related-variables" title="Permalink to this headline">¶</a></h3>
<p>These variables provide fine control over the build of LLVM and
enabled sub-projects. Nearly all of these variable names begin with
<code class="docutils literal notranslate"><span class="pre">LLVM_</span></code>.</p>
<dl>
<dt><strong>BUILD_SHARED_LIBS</strong>:BOOL</dt><dd><p>Flag indicating if each LLVM component (e.g. Support) is built as a shared
library (ON) or as a static library (OFF). Its default value is OFF. On
Windows, shared libraries may be used when building with MinGW, including
mingw-w64, but not when building with the Microsoft toolchain.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>BUILD_SHARED_LIBS is only recommended for use by LLVM developers.
If you want to build LLVM as a shared library, you should use the
<code class="docutils literal notranslate"><span class="pre">LLVM_BUILD_LLVM_DYLIB</span></code> option.</p>
</div>
</dd>
<dt><strong>LLVM_ABI_BREAKING_CHECKS</strong>:STRING</dt><dd><p>Used to decide if LLVM should be built with ABI breaking checks or
not. Allowed values are <cite>WITH_ASSERTS</cite> (default), <cite>FORCE_ON</cite> and
<cite>FORCE_OFF</cite>. <cite>WITH_ASSERTS</cite> turns on ABI breaking checks in an
assertion enabled build. <cite>FORCE_ON</cite> (<cite>FORCE_OFF</cite>) turns them on
(off) irrespective of whether normal (<cite>NDEBUG</cite>-based) assertions are
enabled or not. A version of LLVM built with ABI breaking checks
is not ABI compatible with a version built without it.</p>
</dd>
<dt><strong>LLVM_APPEND_VC_REV</strong>:BOOL</dt><dd><p>Embed version control revision info (Git revision id).
The version info is provided by the <code class="docutils literal notranslate"><span class="pre">LLVM_REVISION</span></code> macro in
<code class="docutils literal notranslate"><span class="pre">llvm/include/llvm/Support/VCSRevision.h</span></code>. Developers using git who don’t
need revision info can disable this option to avoid re-linking most binaries
after a branch switch. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_BUILD_32_BITS</strong>:BOOL</dt><dd><p>Build 32-bit executables and libraries on 64-bit systems. This option is
available only on some 64-bit Unix systems. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_BUILD_BENCHMARKS</strong>:BOOL</dt><dd><p>Adds benchmarks to the list of default targets. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_BUILD_DOCS</strong>:BOOL</dt><dd><p>Adds all <em>enabled</em> documentation targets (i.e. Doxgyen and Sphinx targets) as
dependencies of the default build targets. This results in all of the (enabled)
documentation targets being as part of a normal build. If the <code class="docutils literal notranslate"><span class="pre">install</span></code>
target is run then this also enables all built documentation targets to be
installed. Defaults to OFF. To enable a particular documentation target, see
see LLVM_ENABLE_SPHINX and LLVM_ENABLE_DOXYGEN.</p>
</dd>
<dt><strong>LLVM_BUILD_EXAMPLES</strong>:BOOL</dt><dd><p>Build LLVM examples. Defaults to OFF. Targets for building each example are
generated in any case. See documentation for <em>LLVM_BUILD_TOOLS</em> above for more
details.</p>
</dd>
<dt><strong>LLVM_BUILD_INSTRUMENTED_COVERAGE</strong>:BOOL</dt><dd><p>If enabled, <a class="reference external" href="https://clang.llvm.org/docs/SourceBasedCodeCoverage.html">source-based code coverage</a> instrumentation
is enabled while building llvm. If CMake can locate the code coverage
scripts and the llvm-cov and llvm-profdata tools that pair to your compiler,
the build will also generate the <cite>generate-coverage-report</cite> target to generate
the code coverage report for LLVM, and the <cite>clear-profile-data</cite> utility target
to delete captured profile data. See documentation for
<em>LLVM_CODE_COVERAGE_TARGETS</em> and <em>LLVM_COVERAGE_SOURCE_DIRS</em> for more
information on configuring code coverage reports.</p>
</dd>
<dt><strong>LLVM_CODE_COVERAGE_TARGETS</strong>:STRING</dt><dd><p>If set to a semicolon separated list of targets, those targets will be used
to drive the code coverage reports. If unset, the target list will be
constructed using the LLVM build’s CMake export list.</p>
</dd>
<dt><strong>LLVM_COVERAGE_SOURCE_DIRS</strong>:STRING</dt><dd><p>If set to a semicolon separated list of directories, the coverage reports
will limit code coverage summaries to just the listed directories. If unset,
coverage reports will include all sources identified by the tooling.</p>
</dd>
<dt><strong>LLVM_BUILD_LLVM_DYLIB</strong>:BOOL</dt><dd><p>If enabled, the target for building the libLLVM shared library is added.
This library contains all of LLVM’s components in a single shared library.
Defaults to OFF. This cannot be used in conjunction with BUILD_SHARED_LIBS.
Tools will only be linked to the libLLVM shared library if LLVM_LINK_LLVM_DYLIB
is also ON.
The components in the library can be customised by setting LLVM_DYLIB_COMPONENTS
to a list of the desired components.
This option is not available on Windows.</p>
</dd>
<dt><strong>LLVM_BUILD_TESTS</strong>:BOOL</dt><dd><p>Include LLVM unit tests in the ‘all’ build target. Defaults to OFF. Targets
for building each unit test are generated in any case. You can build a
specific unit test using the targets defined under <em>unittests</em>, such as
ADTTests, IRTests, SupportTests, etc. (Search for <code class="docutils literal notranslate"><span class="pre">add_llvm_unittest</span></code> in
the subdirectories of <em>unittests</em> for a complete list of unit tests.) It is
possible to build all unit tests with the target <em>UnitTests</em>.</p>
</dd>
<dt><strong>LLVM_BUILD_TOOLS</strong>:BOOL</dt><dd><p>Build LLVM tools. Defaults to ON. Targets for building each tool are generated
in any case. You can build a tool separately by invoking its target. For
example, you can build <em>llvm-as</em> with a Makefile-based system by executing <em>make
llvm-as</em> at the root of your build directory.</p>
</dd>
<dt><strong>LLVM_CCACHE_BUILD</strong>:BOOL</dt><dd><p>If enabled and the <code class="docutils literal notranslate"><span class="pre">ccache</span></code> program is available, then LLVM will be
built using <code class="docutils literal notranslate"><span class="pre">ccache</span></code> to speed up rebuilds of LLVM and its components.
Defaults to OFF. The size and location of the cache maintained
by <code class="docutils literal notranslate"><span class="pre">ccache</span></code> can be adjusted via the LLVM_CCACHE_MAXSIZE and LLVM_CCACHE_DIR
options, which are passed to the CCACHE_MAXSIZE and CCACHE_DIR environment
variables, respectively.</p>
</dd>
<dt><strong>LLVM_CREATE_XCODE_TOOLCHAIN</strong>:BOOL</dt><dd><p>macOS Only: If enabled CMake will generate a target named
‘install-xcode-toolchain’. This target will create a directory at
$CMAKE_INSTALL_PREFIX/Toolchains containing an xctoolchain directory which can
be used to override the default system tools.</p>
</dd>
<dt><strong>LLVM_DOXYGEN_QCH_FILENAME</strong>:STRING</dt><dd><p>The filename of the Qt Compressed Help file that will be generated when
<code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN=ON</span></code> and
<code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code> are given. Defaults to
<code class="docutils literal notranslate"><span class="pre">org.llvm.qch</span></code>.
This option is only useful in combination with
<code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>;
otherwise it has no effect.</p>
</dd>
<dt><strong>LLVM_DOXYGEN_QHELPGENERATOR_PATH</strong>:STRING</dt><dd><p>The path to the <code class="docutils literal notranslate"><span class="pre">qhelpgenerator</span></code> executable. Defaults to whatever CMake’s
<code class="docutils literal notranslate"><span class="pre">find_program()</span></code> can find. This option is only useful in combination with
<code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>; otherwise it has no
effect.</p>
</dd>
<dt><strong>LLVM_DOXYGEN_QHP_CUST_FILTER_NAME</strong>:STRING</dt><dd><p>See <a class="reference external" href="http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters">Qt Help Project</a> for
more information. Defaults to the CMake variable <code class="docutils literal notranslate"><span class="pre">${PACKAGE_STRING}</span></code> which
is a combination of the package name and version string. This filter can then
be used in Qt Creator to select only documentation from LLVM when browsing
through all the help files that you might have loaded. This option is only
useful in combination with <code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>;
otherwise it has no effect.</p>
</dd>
</dl>
<dl>
<dt><strong>LLVM_DOXYGEN_QHP_NAMESPACE</strong>:STRING</dt><dd><p>Namespace under which the intermediate Qt Help Project file lives. See <a class="reference external" href="http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters">Qt
Help Project</a>
for more information. Defaults to “org.llvm”. This option is only useful in
combination with <code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>; otherwise
it has no effect.</p>
</dd>
<dt><strong>LLVM_DOXYGEN_SVG</strong>:BOOL</dt><dd><p>Uses .svg files instead of .png files for graphs in the Doxygen output.
Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_ASSERTIONS</strong>:BOOL</dt><dd><p>Enables code assertions. Defaults to ON if and only if <code class="docutils literal notranslate"><span class="pre">CMAKE_BUILD_TYPE</span></code>
is <em>Debug</em>.</p>
</dd>
<dt><strong>LLVM_ENABLE_BINDINGS</strong>:BOOL</dt><dd><p>If disabled, do not try to build the OCaml and go bindings.</p>
</dd>
<dt><strong>LLVM_ENABLE_DIA_SDK</strong>:BOOL</dt><dd><p>Enable building with MSVC DIA SDK for PDB debugging support. Available
only with MSVC. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_DOXYGEN</strong>:BOOL</dt><dd><p>Enables the generation of browsable HTML documentation using doxygen.
Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_DOXYGEN_QT_HELP</strong>:BOOL</dt><dd><p>Enables the generation of a Qt Compressed Help file. Defaults to OFF.
This affects the make target <code class="docutils literal notranslate"><span class="pre">doxygen-llvm</span></code>. When enabled, apart from
the normal HTML output generated by doxygen, this will produce a QCH file
named <code class="docutils literal notranslate"><span class="pre">org.llvm.qch</span></code>. You can then load this file into Qt Creator.
This option is only useful in combination with <code class="docutils literal notranslate"><span class="pre">-DLLVM_ENABLE_DOXYGEN=ON</span></code>;
otherwise this has no effect.</p>
</dd>
<dt><strong>LLVM_ENABLE_EH</strong>:BOOL</dt><dd><p>Build LLVM with exception-handling support. This is necessary if you wish to
link against LLVM libraries and make use of C++ exceptions in your own code
that need to propagate through LLVM code. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_EXPENSIVE_CHECKS</strong>:BOOL</dt><dd><p>Enable additional time/memory expensive checking. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_FFI</strong>:BOOL</dt><dd><p>Indicates whether the LLVM Interpreter will be linked with the Foreign Function
Interface library (libffi) in order to enable calling external functions.
If the library or its headers are installed in a custom
location, you can also set the variables FFI_INCLUDE_DIR and
FFI_LIBRARY_DIR to the directories where ffi.h and libffi.so can be found,
respectively. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_IDE</strong>:BOOL</dt><dd><p>Tell the build system that an IDE is being used. This in turn disables the
creation of certain convenience build system targets, such as the various
<code class="docutils literal notranslate"><span class="pre">install-*</span></code> and <code class="docutils literal notranslate"><span class="pre">check-*</span></code> targets, since IDEs don’t always deal well with
a large number of targets. This is usually autodetected, but it can be
configured manually to explicitly control the generation of those targets. One
scenario where a manual override may be desirable is when using Visual Studio
2017’s CMake integration, which would not be detected as an IDE otherwise.</p>
</dd>
<dt><strong>LLVM_ENABLE_LIBCXX</strong>:BOOL</dt><dd><p>If the host compiler and linker supports the stdlib flag, -stdlib=libc++ is
passed to invocations of both so that the project is built using libc++
instead of stdlibc++. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_LIBPFM</strong>:BOOL</dt><dd><p>Enable building with libpfm to support hardware counter measurements in LLVM
tools.
Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_LLD</strong>:BOOL</dt><dd><p>This option is equivalent to <cite>-DLLVM_USE_LINKER=lld</cite>, except during a 2-stage
build where a dependency is added from the first stage to the second ensuring
that lld is built before stage2 begins.</p>
</dd>
<dt><strong>LLVM_ENABLE_LTO</strong>:STRING</dt><dd><p>Add <code class="docutils literal notranslate"><span class="pre">-flto</span></code> or <code class="docutils literal notranslate"><span class="pre">-flto=</span></code> flags to the compile and link command
lines, enabling link-time optimization. Possible values are <code class="docutils literal notranslate"><span class="pre">Off</span></code>,
<code class="docutils literal notranslate"><span class="pre">On</span></code>, <code class="docutils literal notranslate"><span class="pre">Thin</span></code> and <code class="docutils literal notranslate"><span class="pre">Full</span></code>. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_MODULES</strong>:BOOL</dt><dd><p>Compile with <a class="reference external" href="https://clang.llvm.org/docs/Modules.html">Clang Header Modules</a>.</p>
</dd>
<dt><strong>LLVM_ENABLE_PEDANTIC</strong>:BOOL</dt><dd><p>Enable pedantic mode. This disables compiler-specific extensions, if
possible. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_PIC</strong>:BOOL</dt><dd><p>Add the <code class="docutils literal notranslate"><span class="pre">-fPIC</span></code> flag to the compiler command-line, if the compiler supports
this flag. Some systems, like Windows, do not need this flag. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_PROJECTS</strong>:STRING</dt><dd><p>Semicolon-separated list of projects to build, or <em>all</em> for building all
(clang, libcxx, libcxxabi, lldb, compiler-rt, lld, polly, etc) projects.
This flag assumes that projects are checked out side-by-side and not nested,
i.e. clang needs to be in parallel of llvm instead of nested in <cite>llvm/tools</cite>.
This feature allows to have one build for only LLVM and another for clang+llvm
using the same source checkout.
The full list is:
<code class="docutils literal notranslate"><span class="pre">clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;libcxx;libcxxabi;libunwind;lld;lldb;openmp;parallel-libs;polly;pstl</span></code></p>
</dd>
<dt><strong>LLVM_ENABLE_RUNTIMES</strong>:STRING</dt><dd><p>Build libc++, libc++abi or other projects using that a just-built compiler.
This is the correct way to build libc++ when putting together a toolchain.
It will build the builtins separately from the other runtimes to preserve
correct dependency ordering.
Note: the list should not have duplicates with <cite>LLVM_ENABLE_PROJECTS</cite>.
The full list is:
<code class="docutils literal notranslate"><span class="pre">compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp</span></code>
To enable all of them, use:
<code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_RUNTIMES=all</span></code></p>
</dd>
<dt><strong>LLVM_ENABLE_RTTI</strong>:BOOL</dt><dd><p>Build LLVM with run-time type information. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_SPHINX</strong>:BOOL</dt><dd><p>If specified, CMake will search for the <code class="docutils literal notranslate"><span class="pre">sphinx-build</span></code> executable and will make
the <code class="docutils literal notranslate"><span class="pre">SPHINX_OUTPUT_HTML</span></code> and <code class="docutils literal notranslate"><span class="pre">SPHINX_OUTPUT_MAN</span></code> CMake options available.
Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_THREADS</strong>:BOOL</dt><dd><p>Build with threads support, if available. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_UNWIND_TABLES</strong>:BOOL</dt><dd><p>Enable unwind tables in the binary. Disabling unwind tables can reduce the
size of the libraries. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_WARNINGS</strong>:BOOL</dt><dd><p>Enable all compiler warnings. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_ENABLE_WERROR</strong>:BOOL</dt><dd><p>Stop and fail the build, if a compiler warning is triggered. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_ENABLE_Z3_SOLVER</strong>:BOOL</dt><dd><p>If enabled, the Z3 constraint solver is activated for the Clang static analyzer.
A recent version of the z3 library needs to be available on the system.</p>
</dd>
<dt><strong>LLVM_ENABLE_ZLIB</strong>:BOOL</dt><dd><p>Enable building with zlib to support compression/uncompression in LLVM tools.
Defaults to ON.</p>
</dd>
<dt><strong>LLVM_EXPERIMENTAL_TARGETS_TO_BUILD</strong>:STRING</dt><dd><p>Semicolon-separated list of experimental targets to build and linked into
llvm. This will build the experimental target without needing it to add to the
list of all the targets available in the LLVM’s main CMakeLists.txt.</p>
</dd>
<dt><strong>LLVM_EXTERNAL_{CLANG,LLD,POLLY}_SOURCE_DIR</strong>:PATH</dt><dd><p>These variables specify the path to the source directory for the external
LLVM projects Clang, lld, and Polly, respectively, relative to the top-level
source directory. If the in-tree subdirectory for an external project
exists (e.g., llvm/tools/clang for Clang), then the corresponding variable
will not be used. If the variable for an external project does not point
to a valid path, then that project will not be built.</p>
</dd>
<dt><strong>LLVM_EXTERNAL_PROJECTS</strong>:STRING</dt><dd><p>Semicolon-separated list of additional external projects to build as part of
llvm. For each project LLVM_EXTERNAL_<NAME>_SOURCE_DIR have to be specified
with the path for the source code of the project. Example:
<code class="docutils literal notranslate"><span class="pre">-DLLVM_EXTERNAL_PROJECTS="Foo;Bar"</span>
<span class="pre">-DLLVM_EXTERNAL_FOO_SOURCE_DIR=/src/foo</span>
<span class="pre">-DLLVM_EXTERNAL_BAR_SOURCE_DIR=/src/bar</span></code>.</p>
</dd>
<dt><strong>LLVM_EXTERNALIZE_DEBUGINFO</strong>:BOOL</dt><dd><p>Generate dSYM files and strip executables and libraries (Darwin Only).
Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_FORCE_USE_OLD_TOOLCHAIN</strong>:BOOL</dt><dd><p>If enabled, the compiler and standard library versions won’t be checked. LLVM
may not compile at all, or might fail at runtime due to known bugs in these
toolchains.</p>
</dd>
<dt><strong>LLVM_INCLUDE_BENCHMARKS</strong>:BOOL</dt><dd><p>Generate build targets for the LLVM benchmarks. Defaults to ON.</p>
</dd>
<dt><strong>LLVM_INCLUDE_EXAMPLES</strong>:BOOL</dt><dd><p>Generate build targets for the LLVM examples. Defaults to ON. You can use this
option to disable the generation of build targets for the LLVM examples.</p>
</dd>
<dt><strong>LLVM_INCLUDE_TESTS</strong>:BOOL</dt><dd><p>Generate build targets for the LLVM unit tests. Defaults to ON. You can use
this option to disable the generation of build targets for the LLVM unit
tests.</p>
</dd>
<dt><strong>LLVM_INCLUDE_TOOLS</strong>:BOOL</dt><dd><p>Generate build targets for the LLVM tools. Defaults to ON. You can use this
option to disable the generation of build targets for the LLVM tools.</p>
</dd>
<dt><strong>LLVM_INSTALL_BINUTILS_SYMLINKS</strong>:BOOL</dt><dd><p>Install symlinks from the binutils tool names to the corresponding LLVM tools.
For example, ar will be symlinked to llvm-ar.</p>
</dd>
<dt><strong>LLVM_INSTALL_CCTOOLS_SYMLINKS</strong>:BOOL</dt><dd><p>Install symliks from the cctools tool names to the corresponding LLVM tools.
For example, lipo will be symlinked to llvm-lipo.</p>
</dd>
<dt><strong>LLVM_INSTALL_OCAMLDOC_HTML_DIR</strong>:STRING</dt><dd><p>The path to install OCamldoc-generated HTML documentation to. This path can
either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
<cite>share/doc/llvm/ocaml-html</cite>.</p>
</dd>
<dt><strong>LLVM_INSTALL_SPHINX_HTML_DIR</strong>:STRING</dt><dd><p>The path to install Sphinx-generated HTML documentation to. This path can
either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
<cite>share/doc/llvm/html</cite>.</p>
</dd>
<dt><strong>LLVM_INSTALL_UTILS</strong>:BOOL</dt><dd><p>If enabled, utility binaries like <code class="docutils literal notranslate"><span class="pre">FileCheck</span></code> and <code class="docutils literal notranslate"><span class="pre">not</span></code> will be installed
to CMAKE_INSTALL_PREFIX.</p>
</dd>
<dt><strong>LLVM_INTEGRATED_CRT_ALLOC</strong>:PATH</dt><dd><p>On Windows, allows embedding a different C runtime allocator into the LLVM
tools and libraries. Using a lock-free allocator such as the ones listed below
greatly decreases ThinLTO link time by about an order of magnitude. It also
midly improves Clang build times, by about 5-10%. At the moment, rpmalloc,
snmalloc and mimalloc are supported. Use the path to <cite>git clone</cite> to select
the respective allocator, for example:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> D:<span class="se">\g</span>it> git clone https://github.com/mjansson/rpmalloc
<span class="gp">$</span> D:<span class="se">\l</span>lvm-project> cmake ... -DLLVM_INTEGRATED_CRT_ALLOC<span class="o">=</span>D:<span class="se">\g</span>it<span class="se">\r</span>pmalloc
</pre></div>
</div>
<p>This flag needs to be used along with the static CRT, ie. if building the
Release target, add -DLLVM_USE_CRT_RELEASE=MT.</p>
</dd>
<dt><strong>LLVM_INSTALL_DOXYGEN_HTML_DIR</strong>:STRING</dt><dd><p>The path to install Doxygen-generated HTML documentation to. This path can
either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to
<cite>share/doc/llvm/doxygen-html</cite>.</p>
</dd>
<dt><strong>LLVM_LINK_LLVM_DYLIB</strong>:BOOL</dt><dd><p>If enabled, tools will be linked with the libLLVM shared library. Defaults
to OFF. Setting LLVM_LINK_LLVM_DYLIB to ON also sets LLVM_BUILD_LLVM_DYLIB
to ON.
This option is not available on Windows.</p>
</dd>
<dt><strong>LLVM_LIT_ARGS</strong>:STRING</dt><dd><p>Arguments given to lit. <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">check</span></code> and <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">clang-test</span></code> are affected.
By default, <code class="docutils literal notranslate"><span class="pre">'-sv</span> <span class="pre">--no-progress-bar'</span></code> on Visual C++ and Xcode, <code class="docutils literal notranslate"><span class="pre">'-sv'</span></code> on
others.</p>
</dd>
<dt><strong>LLVM_LIT_TOOLS_DIR</strong>:PATH</dt><dd><p>The path to GnuWin32 tools for tests. Valid on Windows host. Defaults to
the empty string, in which case lit will look for tools needed for tests
(e.g. <code class="docutils literal notranslate"><span class="pre">grep</span></code>, <code class="docutils literal notranslate"><span class="pre">sort</span></code>, etc.) in your %PATH%. If GnuWin32 is not in your
%PATH%, then you can set this variable to the GnuWin32 directory so that
lit can find tools needed for tests in that directory.</p>
</dd>
<dt><strong>LLVM_OPTIMIZED_TABLEGEN</strong>:BOOL</dt><dd><p>If enabled and building a debug or asserts build the CMake build system will
generate a Release build tree to build a fully optimized tablegen for use
during the build. Enabling this option can significantly speed up build times
especially when building LLVM in Debug configurations.</p>
</dd>
<dt><strong>LLVM_PARALLEL_COMPILE_JOBS</strong>:STRING</dt><dd><p>Define the maximum number of concurrent compilation jobs.</p>
</dd>
<dt><strong>LLVM_PARALLEL_LINK_JOBS</strong>:STRING</dt><dd><p>Define the maximum number of concurrent link jobs.</p>
</dd>
<dt><strong>LLVM_PROFDATA_FILE</strong>:PATH</dt><dd><p>Path to a profdata file to pass into clang’s -fprofile-instr-use flag. This
can only be specified if you’re building with clang.</p>
</dd>
<dt><strong>LLVM_REVERSE_ITERATION</strong>:BOOL</dt><dd><p>If enabled, all supported unordered llvm containers would be iterated in
reverse order. This is useful for uncovering non-determinism caused by
iteration of unordered containers.</p>
</dd>
<dt><strong>LLVM_STATIC_LINK_CXX_STDLIB</strong>:BOOL</dt><dd><p>Statically link to the C++ standard library if possible. This uses the flag
“-static-libstdc++”, but a Clang host compiler will statically link to libc++
if used in conjunction with the <strong>LLVM_ENABLE_LIBCXX</strong> flag. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_TABLEGEN</strong>:STRING</dt><dd><p>Full path to a native TableGen executable (usually named <code class="docutils literal notranslate"><span class="pre">llvm-tblgen</span></code>). This is
intended for cross-compiling: if the user sets this variable, no native
TableGen will be created.</p>
</dd>
<dt><strong>LLVM_TARGET_ARCH</strong>:STRING</dt><dd><p>LLVM target to use for native code generation. This is required for JIT
generation. It defaults to “host”, meaning that it shall pick the architecture
of the machine where LLVM is being built. If you are cross-compiling, set it
to the target architecture name.</p>
</dd>
<dt><strong>LLVM_TARGETS_TO_BUILD</strong>:STRING</dt><dd><p>Semicolon-separated list of targets to build, or <em>all</em> for building all
targets. Case-sensitive. Defaults to <em>all</em>. Example:
<code class="docutils literal notranslate"><span class="pre">-DLLVM_TARGETS_TO_BUILD="X86;PowerPC"</span></code>.</p>
</dd>
<dt><strong>LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN</strong>:BOOL</dt><dd><p>If enabled, the compiler version check will only warn when using a toolchain
which is about to be deprecated, instead of emitting an error.</p>
</dd>
<dt><strong>LLVM_UBSAN_FLAGS</strong>:STRING</dt><dd><p>Defines the set of compile flags used to enable UBSan. Only used if
<code class="docutils literal notranslate"><span class="pre">LLVM_USE_SANITIZER</span></code> contains <code class="docutils literal notranslate"><span class="pre">Undefined</span></code>. This can be used to override
the default set of UBSan flags.</p>
</dd>
<dt><strong>LLVM_USE_CRT_{target}</strong>:STRING</dt><dd><p>On Windows, tells which version of the C runtime library (CRT) should be used.
For example, -DLLVM_USE_CRT_RELEASE=MT would statically link the CRT into the
LLVM tools and library.</p>
</dd>
<dt><strong>LLVM_USE_INTEL_JITEVENTS</strong>:BOOL</dt><dd><p>Enable building support for Intel JIT Events API. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_USE_LINKER</strong>:STRING</dt><dd><p>Add <code class="docutils literal notranslate"><span class="pre">-fuse-ld={name}</span></code> to the link invocation. The possible value depend on
your compiler, for clang the value can be an absolute path to your custom
linker, otherwise clang will prefix the name with <code class="docutils literal notranslate"><span class="pre">ld.</span></code> and apply its usual
search. For example to link LLVM with the Gold linker, cmake can be invoked
with <code class="docutils literal notranslate"><span class="pre">-DLLVM_USE_LINKER=gold</span></code>.</p>
</dd>
<dt><strong>LLVM_USE_NEWPM</strong>:BOOL</dt><dd><p>If enabled, use the experimental new pass manager.</p>
</dd>
<dt><strong>LLVM_USE_OPROFILE</strong>:BOOL</dt><dd><p>Enable building OProfile JIT support. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_USE_PERF</strong>:BOOL</dt><dd><p>Enable building support for Perf (linux profiling tool) JIT support. Defaults to OFF.</p>
</dd>
<dt><strong>LLVM_USE_RELATIVE_PATHS_IN_FILES</strong>:BOOL</dt><dd><p>Rewrite absolute source paths in sources and debug info to relative ones. The
source prefix can be adjusted via the LLVM_SOURCE_PREFIX variable.</p>
</dd>
<dt><strong>LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO</strong>:BOOL</dt><dd><p>Rewrite absolute source paths in debug info to relative ones. The source prefix
can be adjusted via the LLVM_SOURCE_PREFIX variable.</p>
</dd>
<dt><strong>LLVM_USE_SANITIZER</strong>:STRING</dt><dd><p>Define the sanitizer used to build LLVM binaries and tests. Possible values
are <code class="docutils literal notranslate"><span class="pre">Address</span></code>, <code class="docutils literal notranslate"><span class="pre">Memory</span></code>, <code class="docutils literal notranslate"><span class="pre">MemoryWithOrigins</span></code>, <code class="docutils literal notranslate"><span class="pre">Undefined</span></code>, <code class="docutils literal notranslate"><span class="pre">Thread</span></code>,
<code class="docutils literal notranslate"><span class="pre">DataFlow</span></code>, and <code class="docutils literal notranslate"><span class="pre">Address;Undefined</span></code>. Defaults to empty string.</p>
</dd>
<dt><strong>SPHINX_EXECUTABLE</strong>:STRING</dt><dd><p>The path to the <code class="docutils literal notranslate"><span class="pre">sphinx-build</span></code> executable detected by CMake.
For installation instructions, see
<a class="reference external" href="https://www.sphinx-doc.org/en/master/usage/installation.html">https://www.sphinx-doc.org/en/master/usage/installation.html</a></p>
</dd>
<dt><strong>SPHINX_OUTPUT_HTML</strong>:BOOL</dt><dd><p>If enabled (and <code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_SPHINX</span></code> is enabled) then the targets for
building the documentation as html are added (but not built by default unless
<code class="docutils literal notranslate"><span class="pre">LLVM_BUILD_DOCS</span></code> is enabled). There is a target for each project in the
source tree that uses sphinx (e.g. <code class="docutils literal notranslate"><span class="pre">docs-llvm-html</span></code>, <code class="docutils literal notranslate"><span class="pre">docs-clang-html</span></code>
and <code class="docutils literal notranslate"><span class="pre">docs-lld-html</span></code>). Defaults to ON.</p>
</dd>
<dt><strong>SPHINX_OUTPUT_MAN</strong>:BOOL</dt><dd><p>If enabled (and <code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_SPHINX</span></code> is enabled) the targets for building
the man pages are added (but not built by default unless <code class="docutils literal notranslate"><span class="pre">LLVM_BUILD_DOCS</span></code>
is enabled). Currently the only target added is <code class="docutils literal notranslate"><span class="pre">docs-llvm-man</span></code>. Defaults
to ON.</p>
</dd>
<dt><strong>SPHINX_WARNINGS_AS_ERRORS</strong>:BOOL</dt><dd><p>If enabled then sphinx documentation warnings will be treated as
errors. Defaults to ON.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="cmake-caches">
<h2><a class="toc-backref" href="#id15">CMake Caches</a><a class="headerlink" href="#cmake-caches" title="Permalink to this headline">¶</a></h2>
<p>Recently LLVM and Clang have been adding some more complicated build system
features. Utilizing these new features often involves a complicated chain of
CMake variables passed on the command line. Clang provides a collection of CMake
cache scripts to make these features more approachable.</p>
<p>CMake cache files are utilized using CMake’s -C flag:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -C <path to cache file> <path to sources>
</pre></div>
</div>
<p>CMake cache scripts are processed in an isolated scope, only cached variables
remain set when the main configuration runs. CMake cached variables do not reset
variables that are already set unless the FORCE option is specified.</p>
<p>A few notes about CMake Caches:</p>
<ul class="simple">
<li><p>Order of command line arguments is important</p>
<ul>
<li><p>-D arguments specified before -C are set before the cache is processed and
can be read inside the cache file</p></li>
<li><p>-D arguments specified after -C are set after the cache is processed and
are unset inside the cache file</p></li>
</ul>
</li>
<li><p>All -D arguments will override cache file settings</p></li>
<li><p>CMAKE_TOOLCHAIN_FILE is evaluated after both the cache file and the command
line arguments</p></li>
<li><p>It is recommended that all -D options should be specified <em>before</em> -C</p></li>
</ul>
<p>For more information about some of the advanced build configurations supported
via Cache files see <a class="reference internal" href="AdvancedBuilds.html"><span class="doc">Advanced Build Configurations</span></a>.</p>
</div>
<div class="section" id="executing-the-tests">
<h2><a class="toc-backref" href="#id16">Executing the Tests</a><a class="headerlink" href="#executing-the-tests" title="Permalink to this headline">¶</a></h2>
<p>Testing is performed when the <em>check-all</em> target is built. For instance, if you are
using Makefiles, execute this command in the root of your build directory:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> make check-all
</pre></div>
</div>
<p>On Visual Studio, you may run tests by building the project “check-all”.
For more information about testing, see the <a class="reference internal" href="TestingGuide.html"><span class="doc">LLVM Testing Infrastructure Guide</span></a>.</p>
</div>
<div class="section" id="cross-compiling">
<h2><a class="toc-backref" href="#id17">Cross compiling</a><a class="headerlink" href="#cross-compiling" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference external" href="https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling">this wiki page</a> for
generic instructions on how to cross-compile with CMake. It goes into detailed
explanations and may seem daunting, but it is not. On the wiki page there are
several examples including toolchain files. Go directly to the
<code class="docutils literal notranslate"><span class="pre">Information</span> <span class="pre">how</span> <span class="pre">to</span> <span class="pre">set</span> <span class="pre">up</span> <span class="pre">various</span> <span class="pre">cross</span> <span class="pre">compiling</span> <span class="pre">toolchains</span></code> section
for a quick solution.</p>
<p>Also see the <a class="reference internal" href="#llvm-related-variables">LLVM-related variables</a> section for variables used when
cross-compiling.</p>
</div>
<div class="section" id="embedding-llvm-in-your-project">
<h2><a class="toc-backref" href="#id18">Embedding LLVM in your project</a><a class="headerlink" href="#embedding-llvm-in-your-project" title="Permalink to this headline">¶</a></h2>
<p>From LLVM 3.5 onwards the CMake build system exports LLVM libraries as
importable CMake targets. This means that clients of LLVM can now reliably use
CMake to develop their own LLVM-based projects against an installed version of
LLVM regardless of how it was built.</p>
<p>Here is a simple example of a CMakeLists.txt file that imports the LLVM libraries
and uses them to build a simple application <code class="docutils literal notranslate"><span class="pre">simple-tool</span></code>.</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">cmake_minimum_required</span><span class="p">(</span><span class="s">VERSION</span> <span class="s">3.13.4</span><span class="p">)</span>
<span class="nb">project</span><span class="p">(</span><span class="s">SimpleProject</span><span class="p">)</span>
<span class="nb">find_package</span><span class="p">(</span><span class="s">LLVM</span> <span class="s">REQUIRED</span> <span class="s">CONFIG</span><span class="p">)</span>
<span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">"Found LLVM ${LLVM_PACKAGE_VERSION}"</span><span class="p">)</span>
<span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">"Using LLVMConfig.cmake in: ${LLVM_DIR}"</span><span class="p">)</span>
<span class="c"># Set your project compile flags.</span>
<span class="c"># E.g. if using the C++ header files</span>
<span class="c"># you will need to enable C++11 support</span>
<span class="c"># for your compiler.</span>
<span class="nb">include_directories</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_INCLUDE_DIRS</span><span class="o">}</span><span class="p">)</span>
<span class="nb">separate_arguments</span><span class="p">(</span><span class="s">LLVM_DEFINITIONS_LIST</span> <span class="s">NATIVE_COMMAND</span> <span class="o">${</span><span class="nv">LLVM_DEFINITIONS</span><span class="o">}</span><span class="p">)</span>
<span class="nb">add_definitions</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_DEFINITIONS_LIST</span><span class="o">}</span><span class="p">)</span>
<span class="c"># Now build our tools</span>
<span class="nb">add_executable</span><span class="p">(</span><span class="s">simple-tool</span> <span class="s">tool.cpp</span><span class="p">)</span>
<span class="c"># Find the libraries that correspond to the LLVM components</span>
<span class="c"># that we wish to use</span>
<span class="nb">llvm_map_components_to_libnames</span><span class="p">(</span><span class="s">llvm_libs</span> <span class="s">support</span> <span class="s">core</span> <span class="s">irreader</span><span class="p">)</span>
<span class="c"># Link against LLVM libraries</span>
<span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">simple-tool</span> <span class="o">${</span><span class="nv">llvm_libs</span><span class="o">}</span><span class="p">)</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">find_package(...)</span></code> directive when used in CONFIG mode (as in the above
example) will look for the <code class="docutils literal notranslate"><span class="pre">LLVMConfig.cmake</span></code> file in various locations (see
cmake manual for details). It creates a <code class="docutils literal notranslate"><span class="pre">LLVM_DIR</span></code> cache entry to save the
directory where <code class="docutils literal notranslate"><span class="pre">LLVMConfig.cmake</span></code> is found or allows the user to specify the
directory (e.g. by passing <code class="docutils literal notranslate"><span class="pre">-DLLVM_DIR=/usr/lib/cmake/llvm</span></code> to
the <code class="docutils literal notranslate"><span class="pre">cmake</span></code> command or by setting it directly in <code class="docutils literal notranslate"><span class="pre">ccmake</span></code> or <code class="docutils literal notranslate"><span class="pre">cmake-gui</span></code>).</p>
<p>This file is available in two different locations.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre"><INSTALL_PREFIX>/lib/cmake/llvm/LLVMConfig.cmake</span></code> where
<code class="docutils literal notranslate"><span class="pre"><INSTALL_PREFIX></span></code> is the install prefix of an installed version of LLVM.
On Linux typically this is <code class="docutils literal notranslate"><span class="pre">/usr/lib/cmake/llvm/LLVMConfig.cmake</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre"><LLVM_BUILD_ROOT>/lib/cmake/llvm/LLVMConfig.cmake</span></code> where
<code class="docutils literal notranslate"><span class="pre"><LLVM_BUILD_ROOT></span></code> is the root of the LLVM build tree. <strong>Note: this is only
available when building LLVM with CMake.</strong></p></li>
</ul>
<p>If LLVM is installed in your operating system’s normal installation prefix (e.g.
on Linux this is usually <code class="docutils literal notranslate"><span class="pre">/usr/</span></code>) <code class="docutils literal notranslate"><span class="pre">find_package(LLVM</span> <span class="pre">...)</span></code> will
automatically find LLVM if it is installed correctly. If LLVM is not installed
or you wish to build directly against the LLVM build tree you can use
<code class="docutils literal notranslate"><span class="pre">LLVM_DIR</span></code> as previously mentioned.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">LLVMConfig.cmake</span></code> file sets various useful variables. Notable variables
include</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_CMAKE_DIR</span></code></dt><dd><p>The path to the LLVM CMake directory (i.e. the directory containing
LLVMConfig.cmake).</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_DEFINITIONS</span></code></dt><dd><p>A list of preprocessor defines that should be used when building against LLVM.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_ASSERTIONS</span></code></dt><dd><p>This is set to ON if LLVM was built with assertions, otherwise OFF.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_EH</span></code></dt><dd><p>This is set to ON if LLVM was built with exception handling (EH) enabled,
otherwise OFF.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_ENABLE_RTTI</span></code></dt><dd><p>This is set to ON if LLVM was built with run time type information (RTTI),
otherwise OFF.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_INCLUDE_DIRS</span></code></dt><dd><p>A list of include paths to directories containing LLVM header files.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_PACKAGE_VERSION</span></code></dt><dd><p>The LLVM version. This string can be used with CMake conditionals, e.g., <code class="docutils literal notranslate"><span class="pre">if</span>
<span class="pre">(${LLVM_PACKAGE_VERSION}</span> <span class="pre">VERSION_LESS</span> <span class="pre">"3.5")</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LLVM_TOOLS_BINARY_DIR</span></code></dt><dd><p>The path to the directory containing the LLVM tools (e.g. <code class="docutils literal notranslate"><span class="pre">llvm-as</span></code>).</p>
</dd>
</dl>
<p>Notice that in the above example we link <code class="docutils literal notranslate"><span class="pre">simple-tool</span></code> against several LLVM
libraries. The list of libraries is determined by using the
<code class="docutils literal notranslate"><span class="pre">llvm_map_components_to_libnames()</span></code> CMake function. For a list of available
components look at the output of running <code class="docutils literal notranslate"><span class="pre">llvm-config</span> <span class="pre">--components</span></code>.</p>
<p>Note that for LLVM < 3.5 <code class="docutils literal notranslate"><span class="pre">llvm_map_components_to_libraries()</span></code> was
used instead of <code class="docutils literal notranslate"><span class="pre">llvm_map_components_to_libnames()</span></code>. This is now deprecated
and will be removed in a future version of LLVM.</p>
<div class="section" id="developing-llvm-passes-out-of-source">
<span id="cmake-out-of-source-pass"></span><h3><a class="toc-backref" href="#id19">Developing LLVM passes out of source</a><a class="headerlink" href="#developing-llvm-passes-out-of-source" title="Permalink to this headline">¶</a></h3>
<p>It is possible to develop LLVM passes out of LLVM’s source tree (i.e. against an
installed or built LLVM). An example of a project layout is provided below.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><project dir>/
|
CMakeLists.txt
<pass name>/
|
CMakeLists.txt
Pass.cpp
...
</pre></div>
</div>
<p>Contents of <code class="docutils literal notranslate"><span class="pre"><project</span> <span class="pre">dir>/CMakeLists.txt</span></code>:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">find_package</span><span class="p">(</span><span class="s">LLVM</span> <span class="s">REQUIRED</span> <span class="s">CONFIG</span><span class="p">)</span>
<span class="nb">separate_arguments</span><span class="p">(</span><span class="s">LLVM_DEFINITIONS_LIST</span> <span class="s">NATIVE_COMMAND</span> <span class="o">${</span><span class="nv">LLVM_DEFINITIONS</span><span class="o">}</span><span class="p">)</span>
<span class="nb">add_definitions</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_DEFINITIONS_LIST</span><span class="o">}</span><span class="p">)</span>
<span class="nb">include_directories</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_INCLUDE_DIRS</span><span class="o">}</span><span class="p">)</span>
<span class="nb">add_subdirectory</span><span class="p">(</span><span class="s"><pass</span> <span class="s">name></span><span class="p">)</span>
</pre></div>
</div>
<p>Contents of <code class="docutils literal notranslate"><span class="pre"><project</span> <span class="pre">dir>/<pass</span> <span class="pre">name>/CMakeLists.txt</span></code>:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">add_library</span><span class="p">(</span><span class="s">LLVMPassname</span> <span class="s">MODULE</span> <span class="s">Pass.cpp</span><span class="p">)</span>
</pre></div>
</div>
<p>Note if you intend for this pass to be merged into the LLVM source tree at some
point in the future it might make more sense to use LLVM’s internal
<code class="docutils literal notranslate"><span class="pre">add_llvm_library</span></code> function with the MODULE argument instead by…</p>
<p>Adding the following to <code class="docutils literal notranslate"><span class="pre"><project</span> <span class="pre">dir>/CMakeLists.txt</span></code> (after
<code class="docutils literal notranslate"><span class="pre">find_package(LLVM</span> <span class="pre">...)</span></code>)</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">list</span><span class="p">(</span><span class="s">APPEND</span> <span class="s">CMAKE_MODULE_PATH</span> <span class="s2">"${LLVM_CMAKE_DIR}"</span><span class="p">)</span>
<span class="nb">include</span><span class="p">(</span><span class="s">AddLLVM</span><span class="p">)</span>
</pre></div>
</div>
<p>And then changing <code class="docutils literal notranslate"><span class="pre"><project</span> <span class="pre">dir>/<pass</span> <span class="pre">name>/CMakeLists.txt</span></code> to</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">add_llvm_library</span><span class="p">(</span><span class="s">LLVMPassname</span> <span class="s">MODULE</span>
<span class="s">Pass.cpp</span>
<span class="p">)</span>
</pre></div>
</div>
<p>When you are done developing your pass, you may wish to integrate it
into the LLVM source tree. You can achieve it in two easy steps:</p>
<ol class="arabic simple">
<li><p>Copying <code class="docutils literal notranslate"><span class="pre"><pass</span> <span class="pre">name></span></code> folder into <code class="docutils literal notranslate"><span class="pre"><LLVM</span> <span class="pre">root>/lib/Transform</span></code> directory.</p></li>
<li><p>Adding <code class="docutils literal notranslate"><span class="pre">add_subdirectory(<pass</span> <span class="pre">name>)</span></code> line into
<code class="docutils literal notranslate"><span class="pre"><LLVM</span> <span class="pre">root>/lib/Transform/CMakeLists.txt</span></code>.</p></li>
</ol>
</div>
</div>
<div class="section" id="compiler-platform-specific-topics">
<h2><a class="toc-backref" href="#id20">Compiler/Platform-specific topics</a><a class="headerlink" href="#compiler-platform-specific-topics" title="Permalink to this headline">¶</a></h2>
<p>Notes for specific compilers and/or platforms.</p>
<div class="section" id="microsoft-visual-c">
<h3><a class="toc-backref" href="#id21">Microsoft Visual C++</a><a class="headerlink" href="#microsoft-visual-c" title="Permalink to this headline">¶</a></h3>
<dl class="simple">
<dt><strong>LLVM_COMPILER_JOBS</strong>:STRING</dt><dd><p>Specifies the maximum number of parallel compiler jobs to use per project
when building with msbuild or Visual Studio. Only supported for the Visual
Studio 2010 CMake generator. 0 means use all processors. Default is 0.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="CMakePrimer.html" title="CMake Primer"
>next</a> |</li>
<li class="right" >
<a href="CFIVerify.html" title="Control Flow Verification Tool Design Document"
>previous</a> |</li>
<li><a href="https://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li class="nav-item nav-item-1"><a href="UserGuides.html" >User Guides</a> »</li>
<li class="nav-item nav-item-this"><a href="">Building LLVM with CMake</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2003-2021, LLVM Project.
Last updated on 2021-09-18.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.5.4.
</div>
</body>
</html>
|