This file is indexed.

/usr/share/doc/llvm-6.0-doc/html/CMake.html is in llvm-6.0-doc 1:6.0-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Building LLVM with CMake &#8212; LLVM 6 documentation</title>
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '6',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" 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="LLVM Language Reference Manual" href="LangRef.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="LangRef.html" title="LLVM Language Reference Manual"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>


    <div class="document">
      <div class="documentwrapper">
          <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><a class="reference internal" href="#introduction" id="id5">Introduction</a></li>
<li><a class="reference internal" href="#quick-start" id="id6">Quick start</a></li>
<li><a class="reference internal" href="#usage" id="id7">Basic CMake usage</a></li>
<li><a class="reference internal" href="#options-and-variables" id="id8">Options and variables</a><ul>
<li><a class="reference internal" href="#frequently-used-cmake-variables" id="id9">Frequently-used CMake variables</a></li>
<li><a class="reference internal" href="#llvm-specific-variables" id="id10">LLVM-specific variables</a></li>
</ul>
</li>
<li><a class="reference internal" href="#cmake-caches" id="id11">CMake Caches</a></li>
<li><a class="reference internal" href="#executing-the-test-suite" id="id12">Executing the test suite</a></li>
<li><a class="reference internal" href="#cross-compiling" id="id13">Cross compiling</a></li>
<li><a class="reference internal" href="#embedding-llvm-in-your-project" id="id14">Embedding LLVM in your project</a><ul>
<li><a class="reference internal" href="#developing-llvm-passes-out-of-source" id="id15">Developing LLVM passes out of source</a></li>
</ul>
</li>
<li><a class="reference internal" href="#compiler-platform-specific-topics" id="id16">Compiler/Platform-specific topics</a><ul>
<li><a class="reference internal" href="#microsoft-visual-c" id="id17">Microsoft Visual C++</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id5">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="#id6">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 class="first"><a class="reference external" href="http://www.cmake.org/cmake/resources/software.html">Download</a> and install
CMake. Version 3.4.3 is the minimum required.</p>
</li>
<li><p class="first">Open a shell. Your development tools must be reachable from this shell
through the PATH environment variable.</p>
</li>
<li><p class="first">Create a build directory. Building LLVM in the source
directory is not supported. cd to this directory:</p>
<div class="highlight-console"><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 class="first">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"><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.</p>
</li>
<li><p class="first">After CMake has finished running, proceed to use IDE project files, or start
the build from the build directory:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake --build .
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">--build</span></code> option tells <code class="docutils literal"><span class="pre">cmake</span></code> to invoke the underlying build
tool (<code class="docutils literal"><span class="pre">make</span></code>, <code class="docutils literal"><span class="pre">ninja</span></code>, <code class="docutils literal"><span class="pre">xcodebuild</span></code>, <code class="docutils literal"><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"><span class="pre">--build</span></code> option is portable.</p>
</li>
<li><p class="first">After LLVM has finished building, install it from the build directory:</p>
<div class="highlight-console"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake --build . --target install
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">--target</span></code> option with <code class="docutils literal"><span class="pre">install</span></code> parameter in addition to
the <code class="docutils literal"><span class="pre">--build</span></code> option tells <code class="docutils literal"><span class="pre">cmake</span></code> to build the <code class="docutils literal"><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"><span class="pre">cmake_install.cmake</span></code> script generated in the
build directory:</p>
<div class="highlight-console"><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="#id7">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"><span class="pre">cmake</span></code> executable itself. Execute <code class="docutils literal"><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"><span class="pre">-G</span> <span class="pre">&quot;Name</span> <span class="pre">of</span> <span class="pre">the</span>
<span class="pre">generator&quot;</span></code>. To see a list of the available generators on your system, execute</p>
<div class="highlight-console"><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"><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"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -G <span class="s2">&quot;Visual Studio 12&quot;</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"><span class="pre">-G</span></code> option.</p>
</div>
<div class="section" id="options-and-variables">
<span id="id3"></span><h2><a class="toc-backref" href="#id8">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"><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"><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"><span class="pre">CMakeCache.txt</span></code>
stored at the root of your build directory that is generated by <code class="docutils literal"><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"><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="#id9">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 and LLVM-specific notes. For full documentation, consult the
CMake manual, or execute <code class="docutils literal"><span class="pre">cmake</span> <span class="pre">--help-variable</span> <span class="pre">VARIABLE_NAME</span></code>.</p>
<dl class="docutils">
<dt><strong>CMAKE_BUILD_TYPE</strong>:STRING</dt>
<dd>Sets the build type for <code class="docutils literal"><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.</dd>
<dt><strong>CMAKE_INSTALL_PREFIX</strong>:PATH</dt>
<dd>Path where LLVM will be installed if “make install” is invoked or the
“install” target is built.</dd>
<dt><strong>LLVM_LIBDIR_SUFFIX</strong>:STRING</dt>
<dd>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"><span class="pre">-DLLVM_LIBDIR_SUFFIX=64</span></code>
to install libraries to <code class="docutils literal"><span class="pre">/usr/lib64</span></code>.</dd>
<dt><strong>CMAKE_C_FLAGS</strong>:STRING</dt>
<dd>Extra flags to use when compiling C source files.</dd>
<dt><strong>CMAKE_CXX_FLAGS</strong>:STRING</dt>
<dd>Extra flags to use when compiling C++ source files.</dd>
</dl>
</div>
<div class="section" id="llvm-specific-variables">
<span id="id4"></span><h3><a class="toc-backref" href="#id10">LLVM-specific variables</a><a class="headerlink" href="#llvm-specific-variables" title="Permalink to this headline"></a></h3>
<dl class="docutils">
<dt><strong>LLVM_TARGETS_TO_BUILD</strong>:STRING</dt>
<dd>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"><span class="pre">-DLLVM_TARGETS_TO_BUILD=&quot;X86;PowerPC&quot;</span></code>.</dd>
<dt><strong>LLVM_BUILD_TOOLS</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_INCLUDE_TOOLS</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_INSTALL_BINUTILS_SYMLINKS</strong>:BOOL</dt>
<dd>Install symlinks from the binutils tool names to the corresponding LLVM tools.
For example, ar will be symlinked to llvm-ar.</dd>
<dt><strong>LLVM_BUILD_EXAMPLES</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_INCLUDE_EXAMPLES</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_BUILD_TESTS</strong>:BOOL</dt>
<dd>Build LLVM unit tests. 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"><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>.</dd>
<dt><strong>LLVM_INCLUDE_TESTS</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_APPEND_VC_REV</strong>:BOOL</dt>
<dd>Embed version control revision info (svn revision number or Git revision id).
The version info is provided by the <code class="docutils literal"><span class="pre">LLVM_REVISION</span></code> macro in
<code class="docutils literal"><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.</dd>
<dt><strong>LLVM_ENABLE_THREADS</strong>:BOOL</dt>
<dd>Build with threads support, if available. Defaults to ON.</dd>
<dt><strong>LLVM_ENABLE_CXX1Y</strong>:BOOL</dt>
<dd>Build in C++1y mode, if available. Defaults to OFF.</dd>
<dt><strong>LLVM_ENABLE_ASSERTIONS</strong>:BOOL</dt>
<dd>Enables code assertions. Defaults to ON if and only if <code class="docutils literal"><span class="pre">CMAKE_BUILD_TYPE</span></code>
is <em>Debug</em>.</dd>
<dt><strong>LLVM_ENABLE_EH</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_ENABLE_EXPENSIVE_CHECKS</strong>:BOOL</dt>
<dd>Enable additional time/memory expensive checking. Defaults to OFF.</dd>
<dt><strong>LLVM_ENABLE_PIC</strong>:BOOL</dt>
<dd>Add the <code class="docutils literal"><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.</dd>
<dt><strong>LLVM_ENABLE_RTTI</strong>:BOOL</dt>
<dd>Build LLVM with run-time type information. Defaults to OFF.</dd>
<dt><strong>LLVM_ENABLE_WARNINGS</strong>:BOOL</dt>
<dd>Enable all compiler warnings. Defaults to ON.</dd>
<dt><strong>LLVM_ENABLE_PEDANTIC</strong>:BOOL</dt>
<dd>Enable pedantic mode. This disables compiler-specific extensions, if
possible. Defaults to ON.</dd>
<dt><strong>LLVM_ENABLE_WERROR</strong>:BOOL</dt>
<dd>Stop and fail the build, if a compiler warning is triggered. Defaults to OFF.</dd>
<dt><strong>LLVM_ABI_BREAKING_CHECKS</strong>:STRING</dt>
<dd>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.</dd>
<dt><strong>LLVM_BUILD_32_BITS</strong>:BOOL</dt>
<dd>Build 32-bit executables and libraries on 64-bit systems. This option is
available only on some 64-bit Unix systems. Defaults to OFF.</dd>
<dt><strong>LLVM_TARGET_ARCH</strong>:STRING</dt>
<dd>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.</dd>
<dt><strong>LLVM_TABLEGEN</strong>:STRING</dt>
<dd>Full path to a native TableGen executable (usually named <code class="docutils literal"><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.</dd>
<dt><strong>LLVM_LIT_ARGS</strong>:STRING</dt>
<dd>Arguments given to lit.  <code class="docutils literal"><span class="pre">make</span> <span class="pre">check</span></code> and <code class="docutils literal"><span class="pre">make</span> <span class="pre">clang-test</span></code> are affected.
By default, <code class="docutils literal"><span class="pre">'-sv</span> <span class="pre">--no-progress-bar'</span></code> on Visual C++ and Xcode, <code class="docutils literal"><span class="pre">'-sv'</span></code> on
others.</dd>
<dt><strong>LLVM_LIT_TOOLS_DIR</strong>:PATH</dt>
<dd>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"><span class="pre">grep</span></code>, <code class="docutils literal"><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.</dd>
<dt><strong>LLVM_ENABLE_FFI</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_EXTERNAL_{CLANG,LLD,POLLY}_SOURCE_DIR</strong>:PATH</dt>
<dd>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.</dd>
<dt><strong>LLVM_ENABLE_PROJECTS</strong>:STRING</dt>
<dd>Semicolon-separated list of projects to build, or <em>all</em> for building all
(clang, libcxx, libcxxabi, lldb, compiler-rt, lld, polly) 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.</dd>
<dt><strong>LLVM_EXTERNAL_PROJECTS</strong>:STRING</dt>
<dd>Semicolon-separated list of additional external projects to build as part of
llvm. For each project LLVM_EXTERNAL_&lt;NAME&gt;_SOURCE_DIR have to be specified
with the path for the source code of the project. Example:
<code class="docutils literal"><span class="pre">-DLLVM_EXTERNAL_PROJECTS=&quot;Foo;Bar&quot;</span>
<span class="pre">-DLLVM_EXTERNAL_FOO_SOURCE_DIR=/src/foo</span>
<span class="pre">-DLLVM_EXTERNAL_BAR_SOURCE_DIR=/src/bar</span></code>.</dd>
<dt><strong>LLVM_USE_OPROFILE</strong>:BOOL</dt>
<dd>Enable building OProfile JIT support. Defaults to OFF.</dd>
<dt><strong>LLVM_PROFDATA_FILE</strong>:PATH</dt>
<dd>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.</dd>
<dt><strong>LLVM_USE_INTEL_JITEVENTS</strong>:BOOL</dt>
<dd>Enable building support for Intel JIT Events API. Defaults to OFF.</dd>
<dt><strong>LLVM_ENABLE_ZLIB</strong>:BOOL</dt>
<dd>Enable building with zlib to support compression/uncompression in LLVM tools.
Defaults to ON.</dd>
<dt><strong>LLVM_ENABLE_DIA_SDK</strong>:BOOL</dt>
<dd>Enable building with MSVC DIA SDK for PDB debugging support. Available
only with MSVC. Defaults to ON.</dd>
<dt><strong>LLVM_USE_SANITIZER</strong>:STRING</dt>
<dd>Define the sanitizer used to build LLVM binaries and tests. Possible values
are <code class="docutils literal"><span class="pre">Address</span></code>, <code class="docutils literal"><span class="pre">Memory</span></code>, <code class="docutils literal"><span class="pre">MemoryWithOrigins</span></code>, <code class="docutils literal"><span class="pre">Undefined</span></code>, <code class="docutils literal"><span class="pre">Thread</span></code>,
and <code class="docutils literal"><span class="pre">Address;Undefined</span></code>. Defaults to empty string.</dd>
<dt><strong>LLVM_ENABLE_LTO</strong>:STRING</dt>
<dd>Add <code class="docutils literal"><span class="pre">-flto</span></code> or <code class="docutils literal"><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"><span class="pre">Off</span></code>,
<code class="docutils literal"><span class="pre">On</span></code>, <code class="docutils literal"><span class="pre">Thin</span></code> and <code class="docutils literal"><span class="pre">Full</span></code>. Defaults to OFF.</dd>
<dt><strong>LLVM_USE_LINKER</strong>:STRING</dt>
<dd>Add <code class="docutils literal"><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"><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"><span class="pre">-DLLVM_USE_LINKER=gold</span></code>.</dd>
<dt><strong>LLVM_ENABLE_LLD</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_PARALLEL_COMPILE_JOBS</strong>:STRING</dt>
<dd>Define the maximum number of concurrent compilation jobs.</dd>
<dt><strong>LLVM_PARALLEL_LINK_JOBS</strong>:STRING</dt>
<dd>Define the maximum number of concurrent link jobs.</dd>
<dt><strong>LLVM_BUILD_DOCS</strong>:BOOL</dt>
<dd>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"><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.</dd>
<dt><strong>LLVM_ENABLE_DOXYGEN</strong>:BOOL</dt>
<dd>Enables the generation of browsable HTML documentation using doxygen.
Defaults to OFF.</dd>
<dt><strong>LLVM_ENABLE_DOXYGEN_QT_HELP</strong>:BOOL</dt>
<dd>Enables the generation of a Qt Compressed Help file. Defaults to OFF.
This affects the make target <code class="docutils literal"><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"><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"><span class="pre">-DLLVM_ENABLE_DOXYGEN=ON</span></code>;
otherwise this has no effect.</dd>
<dt><strong>LLVM_DOXYGEN_QCH_FILENAME</strong>:STRING</dt>
<dd>The filename of the Qt Compressed Help file that will be generated when
<code class="docutils literal"><span class="pre">-DLLVM_ENABLE_DOXYGEN=ON</span></code> and
<code class="docutils literal"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code> are given. Defaults to
<code class="docutils literal"><span class="pre">org.llvm.qch</span></code>.
This option is only useful in combination with
<code class="docutils literal"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>;
otherwise it has no effect.</dd>
<dt><strong>LLVM_DOXYGEN_QHP_NAMESPACE</strong>:STRING</dt>
<dd>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"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>; otherwise
it has no effect.</dd>
<dt><strong>LLVM_DOXYGEN_QHP_CUST_FILTER_NAME</strong>:STRING</dt>
<dd>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"><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"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>;
otherwise it has no effect.</dd>
</dl>
<dl class="docutils">
<dt><strong>LLVM_DOXYGEN_QHELPGENERATOR_PATH</strong>:STRING</dt>
<dd>The path to the <code class="docutils literal"><span class="pre">qhelpgenerator</span></code> executable. Defaults to whatever CMake’s
<code class="docutils literal"><span class="pre">find_program()</span></code> can find. This option is only useful in combination with
<code class="docutils literal"><span class="pre">-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON</span></code>; otherwise it has no
effect.</dd>
<dt><strong>LLVM_DOXYGEN_SVG</strong>:BOOL</dt>
<dd>Uses .svg files instead of .png files for graphs in the Doxygen output.
Defaults to OFF.</dd>
<dt><strong>LLVM_INSTALL_DOXYGEN_HTML_DIR</strong>:STRING</dt>
<dd>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>.</dd>
<dt><strong>LLVM_ENABLE_SPHINX</strong>:BOOL</dt>
<dd>If specified, CMake will search for the <code class="docutils literal"><span class="pre">sphinx-build</span></code> executable and will make
the <code class="docutils literal"><span class="pre">SPHINX_OUTPUT_HTML</span></code> and <code class="docutils literal"><span class="pre">SPHINX_OUTPUT_MAN</span></code> CMake options available.
Defaults to OFF.</dd>
<dt><strong>SPHINX_EXECUTABLE</strong>:STRING</dt>
<dd>The path to the <code class="docutils literal"><span class="pre">sphinx-build</span></code> executable detected by CMake.
For installation instructions, see
<a class="reference external" href="http://www.sphinx-doc.org/en/latest/install.html">http://www.sphinx-doc.org/en/latest/install.html</a></dd>
<dt><strong>SPHINX_OUTPUT_HTML</strong>:BOOL</dt>
<dd>If enabled (and <code class="docutils literal"><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"><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"><span class="pre">docs-llvm-html</span></code>, <code class="docutils literal"><span class="pre">docs-clang-html</span></code>
and <code class="docutils literal"><span class="pre">docs-lld-html</span></code>). Defaults to ON.</dd>
<dt><strong>SPHINX_OUTPUT_MAN</strong>:BOOL</dt>
<dd>If enabled (and <code class="docutils literal"><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"><span class="pre">LLVM_BUILD_DOCS</span></code>
is enabled). Currently the only target added is <code class="docutils literal"><span class="pre">docs-llvm-man</span></code>. Defaults
to ON.</dd>
<dt><strong>SPHINX_WARNINGS_AS_ERRORS</strong>:BOOL</dt>
<dd>If enabled then sphinx documentation warnings will be treated as
errors. Defaults to ON.</dd>
<dt><strong>LLVM_INSTALL_SPHINX_HTML_DIR</strong>:STRING</dt>
<dd>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>.</dd>
<dt><strong>LLVM_INSTALL_OCAMLDOC_HTML_DIR</strong>:STRING</dt>
<dd>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>.</dd>
<dt><strong>LLVM_CREATE_XCODE_TOOLCHAIN</strong>:BOOL</dt>
<dd>OS X 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.</dd>
<dt><strong>LLVM_BUILD_LLVM_DYLIB</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_LINK_LLVM_DYLIB</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>BUILD_SHARED_LIBS</strong>:BOOL</dt>
<dd><p class="first">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="last admonition note">
<p class="first admonition-title">Note</p>
<p class="last">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"><span class="pre">LLVM_BUILD_LLVM_DYLIB</span></code> option.</p>
</div>
</dd>
<dt><strong>LLVM_OPTIMIZED_TABLEGEN</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_REVERSE_ITERATION</strong>:BOOL</dt>
<dd>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.</dd>
<dt><strong>LLVM_BUILD_INSTRUMENTED_COVERAGE</strong>:BOOL</dt>
<dd>If enabled, <a class="reference external" href="http://clang.llvm.org/docs/SourceBasedCodeCoverage.html">source-based code coverage</a> instrumentation
is enabled while building llvm.</dd>
</dl>
</div>
</div>
<div class="section" id="cmake-caches">
<h2><a class="toc-backref" href="#id11">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"><div class="highlight"><pre><span></span><span class="gp">$</span> cmake -C &lt;path to cache file&gt; &lt;path to sources&gt;
</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>Order of command line arguments is important<ul>
<li>-D arguments specified before -C are set before the cache is processed and
can be read inside the cache file</li>
<li>-D arguments specified after -C are set after the cache is processed and
are unset inside the cache file</li>
</ul>
</li>
<li>All -D arguments will override cache file settings</li>
<li>CMAKE_TOOLCHAIN_FILE is evaluated after both the cache file and the command
line arguments</li>
<li>It is recommended that all -D options should be specified <em>before</em> -C</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-test-suite">
<h2><a class="toc-backref" href="#id12">Executing the test suite</a><a class="headerlink" href="#executing-the-test-suite" 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"><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="#id13">Cross compiling</a><a class="headerlink" href="#cross-compiling" title="Permalink to this headline"></a></h2>
<p>See <a class="reference external" href="http://www.vtk.org/Wiki/CMake_Cross_Compiling">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 <a class="reference external" href="http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains">this section</a>
for a quick solution.</p>
<p>Also see the <a class="reference internal" href="#llvm-specific-variables">LLVM-specific 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="#id14">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 both the CMake and autoconf/Makefile build systems export
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"><span class="pre">simple-tool</span></code>.</p>
<div class="highlight-cmake"><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.4.3</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">&quot;Found LLVM ${LLVM_PACKAGE_VERSION}&quot;</span><span class="p">)</span>
<span class="nb">message</span><span class="p">(</span><span class="s">STATUS</span> <span class="s2">&quot;Using LLVMConfig.cmake in: ${LLVM_DIR}&quot;</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">add_definitions</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_DEFINITIONS</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"><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"><span class="pre">LLVMConfig.cmake</span></code> file in various locations (see
cmake manual for details).  It creates a <code class="docutils literal"><span class="pre">LLVM_DIR</span></code> cache entry to save the
directory where <code class="docutils literal"><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"><span class="pre">-DLLVM_DIR=/usr/lib/cmake/llvm</span></code> to
the <code class="docutils literal"><span class="pre">cmake</span></code> command or by setting it directly in <code class="docutils literal"><span class="pre">ccmake</span></code> or <code class="docutils literal"><span class="pre">cmake-gui</span></code>).</p>
<p>This file is available in two different locations.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">&lt;INSTALL_PREFIX&gt;/lib/cmake/llvm/LLVMConfig.cmake</span></code> where
<code class="docutils literal"><span class="pre">&lt;INSTALL_PREFIX&gt;</span></code> is the install prefix of an installed version of LLVM.
On Linux typically this is <code class="docutils literal"><span class="pre">/usr/lib/cmake/llvm/LLVMConfig.cmake</span></code>.</li>
<li><code class="docutils literal"><span class="pre">&lt;LLVM_BUILD_ROOT&gt;/lib/cmake/llvm/LLVMConfig.cmake</span></code> where
<code class="docutils literal"><span class="pre">&lt;LLVM_BUILD_ROOT&gt;</span></code> is the root of the LLVM build tree. <strong>Note: this is only
available when building LLVM with CMake.</strong></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"><span class="pre">/usr/</span></code>) <code class="docutils literal"><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"><span class="pre">LLVM_DIR</span></code> as previously mentioned.</p>
<p>The <code class="docutils literal"><span class="pre">LLVMConfig.cmake</span></code> file sets various useful variables. Notable variables
include</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">LLVM_CMAKE_DIR</span></code></dt>
<dd>The path to the LLVM CMake directory (i.e. the directory containing
LLVMConfig.cmake).</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_DEFINITIONS</span></code></dt>
<dd>A list of preprocessor defines that should be used when building against LLVM.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_ENABLE_ASSERTIONS</span></code></dt>
<dd>This is set to ON if LLVM was built with assertions, otherwise OFF.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_ENABLE_EH</span></code></dt>
<dd>This is set to ON if LLVM was built with exception handling (EH) enabled,
otherwise OFF.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_ENABLE_RTTI</span></code></dt>
<dd>This is set to ON if LLVM was built with run time type information (RTTI),
otherwise OFF.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_INCLUDE_DIRS</span></code></dt>
<dd>A list of include paths to directories containing LLVM header files.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_PACKAGE_VERSION</span></code></dt>
<dd>The LLVM version. This string can be used with CMake conditionals, e.g., <code class="docutils literal"><span class="pre">if</span>
<span class="pre">(${LLVM_PACKAGE_VERSION}</span> <span class="pre">VERSION_LESS</span> <span class="pre">&quot;3.5&quot;)</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">LLVM_TOOLS_BINARY_DIR</span></code></dt>
<dd>The path to the directory containing the LLVM tools (e.g. <code class="docutils literal"><span class="pre">llvm-as</span></code>).</dd>
</dl>
<p>Notice that in the above example we link <code class="docutils literal"><span class="pre">simple-tool</span></code> against several LLVM
libraries. The list of libraries is determined by using the
<code class="docutils literal"><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"><span class="pre">llvm-config</span> <span class="pre">--components</span></code>.</p>
<p>Note that for LLVM &lt; 3.5 <code class="docutils literal"><span class="pre">llvm_map_components_to_libraries()</span></code> was
used instead of <code class="docutils literal"><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="#id15">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"><div class="highlight"><pre><span></span>&lt;project dir&gt;/
    |
    CMakeLists.txt
    &lt;pass name&gt;/
        |
        CMakeLists.txt
        Pass.cpp
        ...
</pre></div>
</div>
<p>Contents of <code class="docutils literal"><span class="pre">&lt;project</span> <span class="pre">dir&gt;/CMakeLists.txt</span></code>:</p>
<div class="highlight-cmake"><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">add_definitions</span><span class="p">(</span><span class="o">${</span><span class="nv">LLVM_DEFINITIONS</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">&lt;pass</span> <span class="s">name&gt;</span><span class="p">)</span>
</pre></div>
</div>
<p>Contents of <code class="docutils literal"><span class="pre">&lt;project</span> <span class="pre">dir&gt;/&lt;pass</span> <span class="pre">name&gt;/CMakeLists.txt</span></code>:</p>
<div class="highlight-cmake"><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"><span class="pre">add_llvm_loadable_module</span></code> function instead by…</p>
<p>Adding the following to <code class="docutils literal"><span class="pre">&lt;project</span> <span class="pre">dir&gt;/CMakeLists.txt</span></code> (after
<code class="docutils literal"><span class="pre">find_package(LLVM</span> <span class="pre">...)</span></code>)</p>
<div class="highlight-cmake"><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">&quot;${LLVM_CMAKE_DIR}&quot;</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"><span class="pre">&lt;project</span> <span class="pre">dir&gt;/&lt;pass</span> <span class="pre">name&gt;/CMakeLists.txt</span></code> to</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">add_llvm_loadable_module</span><span class="p">(</span><span class="s">LLVMPassname</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>Copying <code class="docutils literal"><span class="pre">&lt;pass</span> <span class="pre">name&gt;</span></code> folder into <code class="docutils literal"><span class="pre">&lt;LLVM</span> <span class="pre">root&gt;/lib/Transform</span></code> directory.</li>
<li>Adding <code class="docutils literal"><span class="pre">add_subdirectory(&lt;pass</span> <span class="pre">name&gt;)</span></code> line into
<code class="docutils literal"><span class="pre">&lt;LLVM</span> <span class="pre">root&gt;/lib/Transform/CMakeLists.txt</span></code>.</li>
</ol>
</div>
</div>
<div class="section" id="compiler-platform-specific-topics">
<h2><a class="toc-backref" href="#id16">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="#id17">Microsoft Visual C++</a><a class="headerlink" href="#microsoft-visual-c" title="Permalink to this headline"></a></h3>
<dl class="docutils">
<dt><strong>LLVM_COMPILER_JOBS</strong>:STRING</dt>
<dd>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.</dd>
</dl>
</div>
</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="LangRef.html" title="LLVM Language Reference Manual"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2003-2018, LLVM Project.
      Last updated on 2018-04-05.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
    </div>
  </body>
</html>