xref: /aosp_15_r20/external/llvm/docs/CMake.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker========================
2*9880d681SAndroid Build Coastguard WorkerBuilding LLVM with CMake
3*9880d681SAndroid Build Coastguard Worker========================
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker.. contents::
6*9880d681SAndroid Build Coastguard Worker   :local:
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard WorkerIntroduction
9*9880d681SAndroid Build Coastguard Worker============
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker`CMake <http://www.cmake.org/>`_ is a cross-platform build-generator tool. CMake
12*9880d681SAndroid Build Coastguard Workerdoes not build the project, it generates the files needed by your build tool
13*9880d681SAndroid Build Coastguard Worker(GNU make, Visual Studio, etc.) for building LLVM.
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard WorkerIf **you are a new contributor**, please start with the :doc:`GettingStarted`
16*9880d681SAndroid Build Coastguard Workerpage.  This page is geared for existing contributors moving from the
17*9880d681SAndroid Build Coastguard Workerlegacy configure/make system.
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard WorkerIf you are really anxious about getting a functional LLVM build, go to the
20*9880d681SAndroid Build Coastguard Worker`Quick start`_ section. If you are a CMake novice, start with `Basic CMake usage`_
21*9880d681SAndroid Build Coastguard Workerand then go back to the `Quick start`_ section once you know what you are doing. The
22*9880d681SAndroid Build Coastguard Worker`Options and variables`_ section is a reference for customizing your build. If
23*9880d681SAndroid Build Coastguard Workeryou already have experience with CMake, this is the recommended starting point.
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard WorkerThis page is geared towards users of the LLVM CMake build. If you're looking for
26*9880d681SAndroid Build Coastguard Workerinformation about modifying the LLVM CMake build system you may want to see the
27*9880d681SAndroid Build Coastguard Worker:doc:`CMakePrimer` page. It has a basic overview of the CMake language.
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker.. _Quick start:
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard WorkerQuick start
32*9880d681SAndroid Build Coastguard Worker===========
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard WorkerWe use here the command-line, non-interactive CMake interface.
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker#. `Download <http://www.cmake.org/cmake/resources/software.html>`_ and install
37*9880d681SAndroid Build Coastguard Worker   CMake. Version 3.4.3 is the minimum required.
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Worker#. Open a shell. Your development tools must be reachable from this shell
40*9880d681SAndroid Build Coastguard Worker   through the PATH environment variable.
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker#. Create a build directory. Building LLVM in the source
43*9880d681SAndroid Build Coastguard Worker   directory is not supported. cd to this directory:
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker   .. code-block:: console
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker     $ mkdir mybuilddir
48*9880d681SAndroid Build Coastguard Worker     $ cd mybuilddir
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Worker#. Execute this command in the shell replacing `path/to/llvm/source/root` with
51*9880d681SAndroid Build Coastguard Worker   the path to the root of your LLVM source tree:
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker   .. code-block:: console
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Worker     $ cmake path/to/llvm/source/root
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker   CMake will detect your development environment, perform a series of tests, and
58*9880d681SAndroid Build Coastguard Worker   generate the files required for building LLVM. CMake will use default values
59*9880d681SAndroid Build Coastguard Worker   for all build parameters. See the `Options and variables`_ section for
60*9880d681SAndroid Build Coastguard Worker   a list of build parameters that you can modify.
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker   This can fail if CMake can't detect your toolset, or if it thinks that the
63*9880d681SAndroid Build Coastguard Worker   environment is not sane enough. In this case, make sure that the toolset that
64*9880d681SAndroid Build Coastguard Worker   you intend to use is the only one reachable from the shell, and that the shell
65*9880d681SAndroid Build Coastguard Worker   itself is the correct one for your development environment. CMake will refuse
66*9880d681SAndroid Build Coastguard Worker   to build MinGW makefiles if you have a POSIX shell reachable through the PATH
67*9880d681SAndroid Build Coastguard Worker   environment variable, for instance. You can force CMake to use a given build
68*9880d681SAndroid Build Coastguard Worker   tool; for instructions, see the `Usage`_ section, below.
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker#. After CMake has finished running, proceed to use IDE project files, or start
71*9880d681SAndroid Build Coastguard Worker   the build from the build directory:
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker   .. code-block:: console
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Worker     $ cmake --build .
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Worker   The ``--build`` option tells ``cmake`` to invoke the underlying build
78*9880d681SAndroid Build Coastguard Worker   tool (``make``, ``ninja``, ``xcodebuild``, ``msbuild``, etc.)
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker   The underlying build tool can be invoked directly, of course, but
81*9880d681SAndroid Build Coastguard Worker   the ``--build`` option is portable.
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker#. After LLVM has finished building, install it from the build directory:
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker   .. code-block:: console
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Worker     $ cmake --build . --target install
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker   The ``--target`` option with ``install`` parameter in addition to
90*9880d681SAndroid Build Coastguard Worker   the ``--build`` option tells ``cmake`` to build the ``install`` target.
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Worker   It is possible to set a different install prefix at installation time
93*9880d681SAndroid Build Coastguard Worker   by invoking the ``cmake_install.cmake`` script generated in the
94*9880d681SAndroid Build Coastguard Worker   build directory:
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker   .. code-block:: console
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Worker     $ cmake -DCMAKE_INSTALL_PREFIX=/tmp/llvm -P cmake_install.cmake
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard Worker.. _Basic CMake usage:
101*9880d681SAndroid Build Coastguard Worker.. _Usage:
102*9880d681SAndroid Build Coastguard Worker
103*9880d681SAndroid Build Coastguard WorkerBasic CMake usage
104*9880d681SAndroid Build Coastguard Worker=================
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard WorkerThis section explains basic aspects of CMake
107*9880d681SAndroid Build Coastguard Workerwhich you may need in your day-to-day usage.
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard WorkerCMake comes with extensive documentation, in the form of html files, and as
110*9880d681SAndroid Build Coastguard Workeronline help accessible via the ``cmake`` executable itself. Execute ``cmake
111*9880d681SAndroid Build Coastguard Worker--help`` for further help options.
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard WorkerCMake allows you to specify a build tool (e.g., GNU make, Visual Studio,
114*9880d681SAndroid Build Coastguard Workeror Xcode). If not specified on the command line, CMake tries to guess which
115*9880d681SAndroid Build Coastguard Workerbuild tool to use, based on your environment. Once it has identified your
116*9880d681SAndroid Build Coastguard Workerbuild tool, CMake uses the corresponding *Generator* to create files for your
117*9880d681SAndroid Build Coastguard Workerbuild tool (e.g., Makefiles or Visual Studio or Xcode project files). You can
118*9880d681SAndroid Build Coastguard Workerexplicitly specify the generator with the command line option ``-G "Name of the
119*9880d681SAndroid Build Coastguard Workergenerator"``. To see a list of the available generators on your system, execute
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker.. code-block:: console
122*9880d681SAndroid Build Coastguard Worker
123*9880d681SAndroid Build Coastguard Worker  $ cmake --help
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard WorkerThis will list the generator names at the end of the help text.
126*9880d681SAndroid Build Coastguard Worker
127*9880d681SAndroid Build Coastguard WorkerGenerators' names are case-sensitive, and may contain spaces. For this reason,
128*9880d681SAndroid Build Coastguard Workeryou should enter them exactly as they are listed in the ``cmake --help``
129*9880d681SAndroid Build Coastguard Workeroutput, in quotes. For example, to generate project files specifically for
130*9880d681SAndroid Build Coastguard WorkerVisual Studio 12, you can execute:
131*9880d681SAndroid Build Coastguard Worker
132*9880d681SAndroid Build Coastguard Worker.. code-block:: console
133*9880d681SAndroid Build Coastguard Worker
134*9880d681SAndroid Build Coastguard Worker  $ cmake -G "Visual Studio 12" path/to/llvm/source/root
135*9880d681SAndroid Build Coastguard Worker
136*9880d681SAndroid Build Coastguard WorkerFor a given development platform there can be more than one adequate
137*9880d681SAndroid Build Coastguard Workergenerator. If you use Visual Studio, "NMake Makefiles" is a generator you can use
138*9880d681SAndroid Build Coastguard Workerfor building with NMake. By default, CMake chooses the most specific generator
139*9880d681SAndroid Build Coastguard Workersupported by your development environment. If you want an alternative generator,
140*9880d681SAndroid Build Coastguard Workeryou must tell this to CMake with the ``-G`` option.
141*9880d681SAndroid Build Coastguard Worker
142*9880d681SAndroid Build Coastguard Worker.. todo::
143*9880d681SAndroid Build Coastguard Worker
144*9880d681SAndroid Build Coastguard Worker  Explain variables and cache. Move explanation here from #options section.
145*9880d681SAndroid Build Coastguard Worker
146*9880d681SAndroid Build Coastguard Worker.. _Options and variables:
147*9880d681SAndroid Build Coastguard Worker
148*9880d681SAndroid Build Coastguard WorkerOptions and variables
149*9880d681SAndroid Build Coastguard Worker=====================
150*9880d681SAndroid Build Coastguard Worker
151*9880d681SAndroid Build Coastguard WorkerVariables customize how the build will be generated. Options are boolean
152*9880d681SAndroid Build Coastguard Workervariables, with possible values ON/OFF. Options and variables are defined on the
153*9880d681SAndroid Build Coastguard WorkerCMake command line like this:
154*9880d681SAndroid Build Coastguard Worker
155*9880d681SAndroid Build Coastguard Worker.. code-block:: console
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Worker  $ cmake -DVARIABLE=value path/to/llvm/source
158*9880d681SAndroid Build Coastguard Worker
159*9880d681SAndroid Build Coastguard WorkerYou can set a variable after the initial CMake invocation to change its
160*9880d681SAndroid Build Coastguard Workervalue. You can also undefine a variable:
161*9880d681SAndroid Build Coastguard Worker
162*9880d681SAndroid Build Coastguard Worker.. code-block:: console
163*9880d681SAndroid Build Coastguard Worker
164*9880d681SAndroid Build Coastguard Worker  $ cmake -UVARIABLE path/to/llvm/source
165*9880d681SAndroid Build Coastguard Worker
166*9880d681SAndroid Build Coastguard WorkerVariables are stored in the CMake cache. This is a file named ``CMakeCache.txt``
167*9880d681SAndroid Build Coastguard Workerstored at the root of your build directory that is generated by ``cmake``.
168*9880d681SAndroid Build Coastguard WorkerEditing it yourself is not recommended.
169*9880d681SAndroid Build Coastguard Worker
170*9880d681SAndroid Build Coastguard WorkerVariables are listed in the CMake cache and later in this document with
171*9880d681SAndroid Build Coastguard Workerthe variable name and type separated by a colon. You can also specify the
172*9880d681SAndroid Build Coastguard Workervariable and type on the CMake command line:
173*9880d681SAndroid Build Coastguard Worker
174*9880d681SAndroid Build Coastguard Worker.. code-block:: console
175*9880d681SAndroid Build Coastguard Worker
176*9880d681SAndroid Build Coastguard Worker  $ cmake -DVARIABLE:TYPE=value path/to/llvm/source
177*9880d681SAndroid Build Coastguard Worker
178*9880d681SAndroid Build Coastguard WorkerFrequently-used CMake variables
179*9880d681SAndroid Build Coastguard Worker-------------------------------
180*9880d681SAndroid Build Coastguard Worker
181*9880d681SAndroid Build Coastguard WorkerHere are some of the CMake variables that are used often, along with a
182*9880d681SAndroid Build Coastguard Workerbrief explanation and LLVM-specific notes. For full documentation, consult the
183*9880d681SAndroid Build Coastguard WorkerCMake manual, or execute ``cmake --help-variable VARIABLE_NAME``.
184*9880d681SAndroid Build Coastguard Worker
185*9880d681SAndroid Build Coastguard Worker**CMAKE_BUILD_TYPE**:STRING
186*9880d681SAndroid Build Coastguard Worker  Sets the build type for ``make``-based generators. Possible values are
187*9880d681SAndroid Build Coastguard Worker  Release, Debug, RelWithDebInfo and MinSizeRel. If you are using an IDE such as
188*9880d681SAndroid Build Coastguard Worker  Visual Studio, you should use the IDE settings to set the build type.
189*9880d681SAndroid Build Coastguard Worker
190*9880d681SAndroid Build Coastguard Worker**CMAKE_INSTALL_PREFIX**:PATH
191*9880d681SAndroid Build Coastguard Worker  Path where LLVM will be installed if "make install" is invoked or the
192*9880d681SAndroid Build Coastguard Worker  "install" target is built.
193*9880d681SAndroid Build Coastguard Worker
194*9880d681SAndroid Build Coastguard Worker**LLVM_LIBDIR_SUFFIX**:STRING
195*9880d681SAndroid Build Coastguard Worker  Extra suffix to append to the directory where libraries are to be
196*9880d681SAndroid Build Coastguard Worker  installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
197*9880d681SAndroid Build Coastguard Worker  to install libraries to ``/usr/lib64``.
198*9880d681SAndroid Build Coastguard Worker
199*9880d681SAndroid Build Coastguard Worker**CMAKE_C_FLAGS**:STRING
200*9880d681SAndroid Build Coastguard Worker  Extra flags to use when compiling C source files.
201*9880d681SAndroid Build Coastguard Worker
202*9880d681SAndroid Build Coastguard Worker**CMAKE_CXX_FLAGS**:STRING
203*9880d681SAndroid Build Coastguard Worker  Extra flags to use when compiling C++ source files.
204*9880d681SAndroid Build Coastguard Worker
205*9880d681SAndroid Build Coastguard Worker.. _LLVM-specific variables:
206*9880d681SAndroid Build Coastguard Worker
207*9880d681SAndroid Build Coastguard WorkerLLVM-specific variables
208*9880d681SAndroid Build Coastguard Worker-----------------------
209*9880d681SAndroid Build Coastguard Worker
210*9880d681SAndroid Build Coastguard Worker**LLVM_TARGETS_TO_BUILD**:STRING
211*9880d681SAndroid Build Coastguard Worker  Semicolon-separated list of targets to build, or *all* for building all
212*9880d681SAndroid Build Coastguard Worker  targets. Case-sensitive. Defaults to *all*. Example:
213*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_TARGETS_TO_BUILD="X86;PowerPC"``.
214*9880d681SAndroid Build Coastguard Worker
215*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_TOOLS**:BOOL
216*9880d681SAndroid Build Coastguard Worker  Build LLVM tools. Defaults to ON. Targets for building each tool are generated
217*9880d681SAndroid Build Coastguard Worker  in any case. You can build a tool separately by invoking its target. For
218*9880d681SAndroid Build Coastguard Worker  example, you can build *llvm-as* with a Makefile-based system by executing *make
219*9880d681SAndroid Build Coastguard Worker  llvm-as* at the root of your build directory.
220*9880d681SAndroid Build Coastguard Worker
221*9880d681SAndroid Build Coastguard Worker**LLVM_INCLUDE_TOOLS**:BOOL
222*9880d681SAndroid Build Coastguard Worker  Generate build targets for the LLVM tools. Defaults to ON. You can use this
223*9880d681SAndroid Build Coastguard Worker  option to disable the generation of build targets for the LLVM tools.
224*9880d681SAndroid Build Coastguard Worker
225*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_EXAMPLES**:BOOL
226*9880d681SAndroid Build Coastguard Worker  Build LLVM examples. Defaults to OFF. Targets for building each example are
227*9880d681SAndroid Build Coastguard Worker  generated in any case. See documentation for *LLVM_BUILD_TOOLS* above for more
228*9880d681SAndroid Build Coastguard Worker  details.
229*9880d681SAndroid Build Coastguard Worker
230*9880d681SAndroid Build Coastguard Worker**LLVM_INCLUDE_EXAMPLES**:BOOL
231*9880d681SAndroid Build Coastguard Worker  Generate build targets for the LLVM examples. Defaults to ON. You can use this
232*9880d681SAndroid Build Coastguard Worker  option to disable the generation of build targets for the LLVM examples.
233*9880d681SAndroid Build Coastguard Worker
234*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_TESTS**:BOOL
235*9880d681SAndroid Build Coastguard Worker  Build LLVM unit tests. Defaults to OFF. Targets for building each unit test
236*9880d681SAndroid Build Coastguard Worker  are generated in any case. You can build a specific unit test using the
237*9880d681SAndroid Build Coastguard Worker  targets defined under *unittests*, such as ADTTests, IRTests, SupportTests,
238*9880d681SAndroid Build Coastguard Worker  etc. (Search for ``add_llvm_unittest`` in the subdirectories of *unittests*
239*9880d681SAndroid Build Coastguard Worker  for a complete list of unit tests.) It is possible to build all unit tests
240*9880d681SAndroid Build Coastguard Worker  with the target *UnitTests*.
241*9880d681SAndroid Build Coastguard Worker
242*9880d681SAndroid Build Coastguard Worker**LLVM_INCLUDE_TESTS**:BOOL
243*9880d681SAndroid Build Coastguard Worker  Generate build targets for the LLVM unit tests. Defaults to ON. You can use
244*9880d681SAndroid Build Coastguard Worker  this option to disable the generation of build targets for the LLVM unit
245*9880d681SAndroid Build Coastguard Worker  tests.
246*9880d681SAndroid Build Coastguard Worker
247*9880d681SAndroid Build Coastguard Worker**LLVM_APPEND_VC_REV**:BOOL
248*9880d681SAndroid Build Coastguard Worker  Append version control revision info (svn revision number or Git revision id)
249*9880d681SAndroid Build Coastguard Worker  to LLVM version string (stored in the PACKAGE_VERSION macro). For this to work
250*9880d681SAndroid Build Coastguard Worker  cmake must be invoked before the build. Defaults to OFF.
251*9880d681SAndroid Build Coastguard Worker
252*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_THREADS**:BOOL
253*9880d681SAndroid Build Coastguard Worker  Build with threads support, if available. Defaults to ON.
254*9880d681SAndroid Build Coastguard Worker
255*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_CXX1Y**:BOOL
256*9880d681SAndroid Build Coastguard Worker  Build in C++1y mode, if available. Defaults to OFF.
257*9880d681SAndroid Build Coastguard Worker
258*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_ASSERTIONS**:BOOL
259*9880d681SAndroid Build Coastguard Worker  Enables code assertions. Defaults to ON if and only if ``CMAKE_BUILD_TYPE``
260*9880d681SAndroid Build Coastguard Worker  is *Debug*.
261*9880d681SAndroid Build Coastguard Worker
262*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_EH**:BOOL
263*9880d681SAndroid Build Coastguard Worker  Build LLVM with exception-handling support. This is necessary if you wish to
264*9880d681SAndroid Build Coastguard Worker  link against LLVM libraries and make use of C++ exceptions in your own code
265*9880d681SAndroid Build Coastguard Worker  that need to propagate through LLVM code. Defaults to OFF.
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_EXPENSIVE_CHECKS**:BOOL
268*9880d681SAndroid Build Coastguard Worker  Enable additional time/memory expensive checking. Defaults to OFF.
269*9880d681SAndroid Build Coastguard Worker
270*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_PIC**:BOOL
271*9880d681SAndroid Build Coastguard Worker  Add the ``-fPIC`` flag to the compiler command-line, if the compiler supports
272*9880d681SAndroid Build Coastguard Worker  this flag. Some systems, like Windows, do not need this flag. Defaults to ON.
273*9880d681SAndroid Build Coastguard Worker
274*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_RTTI**:BOOL
275*9880d681SAndroid Build Coastguard Worker  Build LLVM with run-time type information. Defaults to OFF.
276*9880d681SAndroid Build Coastguard Worker
277*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_WARNINGS**:BOOL
278*9880d681SAndroid Build Coastguard Worker  Enable all compiler warnings. Defaults to ON.
279*9880d681SAndroid Build Coastguard Worker
280*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_PEDANTIC**:BOOL
281*9880d681SAndroid Build Coastguard Worker  Enable pedantic mode. This disables compiler-specific extensions, if
282*9880d681SAndroid Build Coastguard Worker  possible. Defaults to ON.
283*9880d681SAndroid Build Coastguard Worker
284*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_WERROR**:BOOL
285*9880d681SAndroid Build Coastguard Worker  Stop and fail the build, if a compiler warning is triggered. Defaults to OFF.
286*9880d681SAndroid Build Coastguard Worker
287*9880d681SAndroid Build Coastguard Worker**LLVM_ABI_BREAKING_CHECKS**:STRING
288*9880d681SAndroid Build Coastguard Worker  Used to decide if LLVM should be built with ABI breaking checks or
289*9880d681SAndroid Build Coastguard Worker  not.  Allowed values are `WITH_ASSERTS` (default), `FORCE_ON` and
290*9880d681SAndroid Build Coastguard Worker  `FORCE_OFF`.  `WITH_ASSERTS` turns on ABI breaking checks in an
291*9880d681SAndroid Build Coastguard Worker  assertion enabled build.  `FORCE_ON` (`FORCE_OFF`) turns them on
292*9880d681SAndroid Build Coastguard Worker  (off) irrespective of whether normal (`NDEBUG`-based) assertions are
293*9880d681SAndroid Build Coastguard Worker  enabled or not.  A version of LLVM built with ABI breaking checks
294*9880d681SAndroid Build Coastguard Worker  is not ABI compatible with a version built without it.
295*9880d681SAndroid Build Coastguard Worker
296*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_32_BITS**:BOOL
297*9880d681SAndroid Build Coastguard Worker  Build 32-bit executables and libraries on 64-bit systems. This option is
298*9880d681SAndroid Build Coastguard Worker  available only on some 64-bit Unix systems. Defaults to OFF.
299*9880d681SAndroid Build Coastguard Worker
300*9880d681SAndroid Build Coastguard Worker**LLVM_TARGET_ARCH**:STRING
301*9880d681SAndroid Build Coastguard Worker  LLVM target to use for native code generation. This is required for JIT
302*9880d681SAndroid Build Coastguard Worker  generation. It defaults to "host", meaning that it shall pick the architecture
303*9880d681SAndroid Build Coastguard Worker  of the machine where LLVM is being built. If you are cross-compiling, set it
304*9880d681SAndroid Build Coastguard Worker  to the target architecture name.
305*9880d681SAndroid Build Coastguard Worker
306*9880d681SAndroid Build Coastguard Worker**LLVM_TABLEGEN**:STRING
307*9880d681SAndroid Build Coastguard Worker  Full path to a native TableGen executable (usually named ``llvm-tblgen``). This is
308*9880d681SAndroid Build Coastguard Worker  intended for cross-compiling: if the user sets this variable, no native
309*9880d681SAndroid Build Coastguard Worker  TableGen will be created.
310*9880d681SAndroid Build Coastguard Worker
311*9880d681SAndroid Build Coastguard Worker**LLVM_LIT_ARGS**:STRING
312*9880d681SAndroid Build Coastguard Worker  Arguments given to lit.  ``make check`` and ``make clang-test`` are affected.
313*9880d681SAndroid Build Coastguard Worker  By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
314*9880d681SAndroid Build Coastguard Worker  others.
315*9880d681SAndroid Build Coastguard Worker
316*9880d681SAndroid Build Coastguard Worker**LLVM_LIT_TOOLS_DIR**:PATH
317*9880d681SAndroid Build Coastguard Worker  The path to GnuWin32 tools for tests. Valid on Windows host.  Defaults to
318*9880d681SAndroid Build Coastguard Worker  the empty string, in which case lit will look for tools needed for tests
319*9880d681SAndroid Build Coastguard Worker  (e.g. ``grep``, ``sort``, etc.) in your %PATH%. If GnuWin32 is not in your
320*9880d681SAndroid Build Coastguard Worker  %PATH%, then you can set this variable to the GnuWin32 directory so that
321*9880d681SAndroid Build Coastguard Worker  lit can find tools needed for tests in that directory.
322*9880d681SAndroid Build Coastguard Worker
323*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_FFI**:BOOL
324*9880d681SAndroid Build Coastguard Worker  Indicates whether the LLVM Interpreter will be linked with the Foreign Function
325*9880d681SAndroid Build Coastguard Worker  Interface library (libffi) in order to enable calling external functions.
326*9880d681SAndroid Build Coastguard Worker  If the library or its headers are installed in a custom
327*9880d681SAndroid Build Coastguard Worker  location, you can also set the variables FFI_INCLUDE_DIR and
328*9880d681SAndroid Build Coastguard Worker  FFI_LIBRARY_DIR to the directories where ffi.h and libffi.so can be found,
329*9880d681SAndroid Build Coastguard Worker  respectively. Defaults to OFF.
330*9880d681SAndroid Build Coastguard Worker
331*9880d681SAndroid Build Coastguard Worker**LLVM_EXTERNAL_{CLANG,LLD,POLLY}_SOURCE_DIR**:PATH
332*9880d681SAndroid Build Coastguard Worker  These variables specify the path to the source directory for the external
333*9880d681SAndroid Build Coastguard Worker  LLVM projects Clang, lld, and Polly, respectively, relative to the top-level
334*9880d681SAndroid Build Coastguard Worker  source directory.  If the in-tree subdirectory for an external project
335*9880d681SAndroid Build Coastguard Worker  exists (e.g., llvm/tools/clang for Clang), then the corresponding variable
336*9880d681SAndroid Build Coastguard Worker  will not be used.  If the variable for an external project does not point
337*9880d681SAndroid Build Coastguard Worker  to a valid path, then that project will not be built.
338*9880d681SAndroid Build Coastguard Worker
339*9880d681SAndroid Build Coastguard Worker**LLVM_EXTERNAL_PROJECTS**:STRING
340*9880d681SAndroid Build Coastguard Worker  Semicolon-separated list of additional external projects to build as part of
341*9880d681SAndroid Build Coastguard Worker  llvm. For each project LLVM_EXTERNAL_<NAME>_SOURCE_DIR have to be specified
342*9880d681SAndroid Build Coastguard Worker  with the path for the source code of the project. Example:
343*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_EXTERNAL_PROJECTS="Foo;Bar"
344*9880d681SAndroid Build Coastguard Worker  -DLLVM_EXTERNAL_FOO_SOURCE_DIR=/src/foo
345*9880d681SAndroid Build Coastguard Worker  -DLLVM_EXTERNAL_BAR_SOURCE_DIR=/src/bar``.
346*9880d681SAndroid Build Coastguard Worker
347*9880d681SAndroid Build Coastguard Worker**LLVM_USE_OPROFILE**:BOOL
348*9880d681SAndroid Build Coastguard Worker  Enable building OProfile JIT support. Defaults to OFF.
349*9880d681SAndroid Build Coastguard Worker
350*9880d681SAndroid Build Coastguard Worker**LLVM_PROFDATA_FILE**:PATH
351*9880d681SAndroid Build Coastguard Worker  Path to a profdata file to pass into clang's -fprofile-instr-use flag. This
352*9880d681SAndroid Build Coastguard Worker  can only be specified if you're building with clang.
353*9880d681SAndroid Build Coastguard Worker
354*9880d681SAndroid Build Coastguard Worker**LLVM_USE_INTEL_JITEVENTS**:BOOL
355*9880d681SAndroid Build Coastguard Worker  Enable building support for Intel JIT Events API. Defaults to OFF.
356*9880d681SAndroid Build Coastguard Worker
357*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_ZLIB**:BOOL
358*9880d681SAndroid Build Coastguard Worker  Enable building with zlib to support compression/uncompression in LLVM tools.
359*9880d681SAndroid Build Coastguard Worker  Defaults to ON.
360*9880d681SAndroid Build Coastguard Worker
361*9880d681SAndroid Build Coastguard Worker**LLVM_USE_SANITIZER**:STRING
362*9880d681SAndroid Build Coastguard Worker  Define the sanitizer used to build LLVM binaries and tests. Possible values
363*9880d681SAndroid Build Coastguard Worker  are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
364*9880d681SAndroid Build Coastguard Worker  and ``Address;Undefined``. Defaults to empty string.
365*9880d681SAndroid Build Coastguard Worker
366*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_LTO**:STRING
367*9880d681SAndroid Build Coastguard Worker  Add ``-flto`` or ``-flto=`` flags to the compile and link command
368*9880d681SAndroid Build Coastguard Worker  lines, enabling link-time optimization. Possible values are ``Off``,
369*9880d681SAndroid Build Coastguard Worker  ``On``, ``Thin`` and ``Full``. Defaults to OFF.
370*9880d681SAndroid Build Coastguard Worker
371*9880d681SAndroid Build Coastguard Worker**LLVM_PARALLEL_COMPILE_JOBS**:STRING
372*9880d681SAndroid Build Coastguard Worker  Define the maximum number of concurrent compilation jobs.
373*9880d681SAndroid Build Coastguard Worker
374*9880d681SAndroid Build Coastguard Worker**LLVM_PARALLEL_LINK_JOBS**:STRING
375*9880d681SAndroid Build Coastguard Worker  Define the maximum number of concurrent link jobs.
376*9880d681SAndroid Build Coastguard Worker
377*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_DOCS**:BOOL
378*9880d681SAndroid Build Coastguard Worker  Adds all *enabled* documentation targets (i.e. Doxgyen and Sphinx targets) as
379*9880d681SAndroid Build Coastguard Worker  dependencies of the default build targets.  This results in all of the (enabled)
380*9880d681SAndroid Build Coastguard Worker  documentation targets being as part of a normal build.  If the ``install``
381*9880d681SAndroid Build Coastguard Worker  target is run then this also enables all built documentation targets to be
382*9880d681SAndroid Build Coastguard Worker  installed. Defaults to OFF.  To enable a particular documentation target, see
383*9880d681SAndroid Build Coastguard Worker  see LLVM_ENABLE_SPHINX and LLVM_ENABLE_DOXYGEN.
384*9880d681SAndroid Build Coastguard Worker
385*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_DOXYGEN**:BOOL
386*9880d681SAndroid Build Coastguard Worker  Enables the generation of browsable HTML documentation using doxygen.
387*9880d681SAndroid Build Coastguard Worker  Defaults to OFF.
388*9880d681SAndroid Build Coastguard Worker
389*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_DOXYGEN_QT_HELP**:BOOL
390*9880d681SAndroid Build Coastguard Worker  Enables the generation of a Qt Compressed Help file. Defaults to OFF.
391*9880d681SAndroid Build Coastguard Worker  This affects the make target ``doxygen-llvm``. When enabled, apart from
392*9880d681SAndroid Build Coastguard Worker  the normal HTML output generated by doxygen, this will produce a QCH file
393*9880d681SAndroid Build Coastguard Worker  named ``org.llvm.qch``. You can then load this file into Qt Creator.
394*9880d681SAndroid Build Coastguard Worker  This option is only useful in combination with ``-DLLVM_ENABLE_DOXYGEN=ON``;
395*9880d681SAndroid Build Coastguard Worker  otherwise this has no effect.
396*9880d681SAndroid Build Coastguard Worker
397*9880d681SAndroid Build Coastguard Worker**LLVM_DOXYGEN_QCH_FILENAME**:STRING
398*9880d681SAndroid Build Coastguard Worker  The filename of the Qt Compressed Help file that will be generated when
399*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_ENABLE_DOXYGEN=ON`` and
400*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON`` are given. Defaults to
401*9880d681SAndroid Build Coastguard Worker  ``org.llvm.qch``.
402*9880d681SAndroid Build Coastguard Worker  This option is only useful in combination with
403*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``;
404*9880d681SAndroid Build Coastguard Worker  otherwise it has no effect.
405*9880d681SAndroid Build Coastguard Worker
406*9880d681SAndroid Build Coastguard Worker**LLVM_DOXYGEN_QHP_NAMESPACE**:STRING
407*9880d681SAndroid Build Coastguard Worker  Namespace under which the intermediate Qt Help Project file lives. See `Qt
408*9880d681SAndroid Build Coastguard Worker  Help Project`_
409*9880d681SAndroid Build Coastguard Worker  for more information. Defaults to "org.llvm". This option is only useful in
410*9880d681SAndroid Build Coastguard Worker  combination with ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``; otherwise
411*9880d681SAndroid Build Coastguard Worker  it has no effect.
412*9880d681SAndroid Build Coastguard Worker
413*9880d681SAndroid Build Coastguard Worker**LLVM_DOXYGEN_QHP_CUST_FILTER_NAME**:STRING
414*9880d681SAndroid Build Coastguard Worker  See `Qt Help Project`_ for
415*9880d681SAndroid Build Coastguard Worker  more information. Defaults to the CMake variable ``${PACKAGE_STRING}`` which
416*9880d681SAndroid Build Coastguard Worker  is a combination of the package name and version string. This filter can then
417*9880d681SAndroid Build Coastguard Worker  be used in Qt Creator to select only documentation from LLVM when browsing
418*9880d681SAndroid Build Coastguard Worker  through all the help files that you might have loaded. This option is only
419*9880d681SAndroid Build Coastguard Worker  useful in combination with ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``;
420*9880d681SAndroid Build Coastguard Worker  otherwise it has no effect.
421*9880d681SAndroid Build Coastguard Worker
422*9880d681SAndroid Build Coastguard Worker.. _Qt Help Project: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters
423*9880d681SAndroid Build Coastguard Worker
424*9880d681SAndroid Build Coastguard Worker**LLVM_DOXYGEN_QHELPGENERATOR_PATH**:STRING
425*9880d681SAndroid Build Coastguard Worker  The path to the ``qhelpgenerator`` executable. Defaults to whatever CMake's
426*9880d681SAndroid Build Coastguard Worker  ``find_program()`` can find. This option is only useful in combination with
427*9880d681SAndroid Build Coastguard Worker  ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``; otherwise it has no
428*9880d681SAndroid Build Coastguard Worker  effect.
429*9880d681SAndroid Build Coastguard Worker
430*9880d681SAndroid Build Coastguard Worker**LLVM_DOXYGEN_SVG**:BOOL
431*9880d681SAndroid Build Coastguard Worker  Uses .svg files instead of .png files for graphs in the Doxygen output.
432*9880d681SAndroid Build Coastguard Worker  Defaults to OFF.
433*9880d681SAndroid Build Coastguard Worker
434*9880d681SAndroid Build Coastguard Worker**LLVM_ENABLE_SPHINX**:BOOL
435*9880d681SAndroid Build Coastguard Worker  If specified, CMake will search for the ``sphinx-build`` executable and will make
436*9880d681SAndroid Build Coastguard Worker  the ``SPHINX_OUTPUT_HTML`` and ``SPHINX_OUTPUT_MAN`` CMake options available.
437*9880d681SAndroid Build Coastguard Worker  Defaults to OFF.
438*9880d681SAndroid Build Coastguard Worker
439*9880d681SAndroid Build Coastguard Worker**SPHINX_EXECUTABLE**:STRING
440*9880d681SAndroid Build Coastguard Worker  The path to the ``sphinx-build`` executable detected by CMake.
441*9880d681SAndroid Build Coastguard Worker
442*9880d681SAndroid Build Coastguard Worker**SPHINX_OUTPUT_HTML**:BOOL
443*9880d681SAndroid Build Coastguard Worker  If enabled (and ``LLVM_ENABLE_SPHINX`` is enabled) then the targets for
444*9880d681SAndroid Build Coastguard Worker  building the documentation as html are added (but not built by default unless
445*9880d681SAndroid Build Coastguard Worker  ``LLVM_BUILD_DOCS`` is enabled). There is a target for each project in the
446*9880d681SAndroid Build Coastguard Worker  source tree that uses sphinx (e.g.  ``docs-llvm-html``, ``docs-clang-html``
447*9880d681SAndroid Build Coastguard Worker  and ``docs-lld-html``). Defaults to ON.
448*9880d681SAndroid Build Coastguard Worker
449*9880d681SAndroid Build Coastguard Worker**SPHINX_OUTPUT_MAN**:BOOL
450*9880d681SAndroid Build Coastguard Worker  If enabled (and ``LLVM_ENABLE_SPHINX`` is enabled) the targets for building
451*9880d681SAndroid Build Coastguard Worker  the man pages are added (but not built by default unless ``LLVM_BUILD_DOCS``
452*9880d681SAndroid Build Coastguard Worker  is enabled). Currently the only target added is ``docs-llvm-man``. Defaults
453*9880d681SAndroid Build Coastguard Worker  to ON.
454*9880d681SAndroid Build Coastguard Worker
455*9880d681SAndroid Build Coastguard Worker**SPHINX_WARNINGS_AS_ERRORS**:BOOL
456*9880d681SAndroid Build Coastguard Worker  If enabled then sphinx documentation warnings will be treated as
457*9880d681SAndroid Build Coastguard Worker  errors. Defaults to ON.
458*9880d681SAndroid Build Coastguard Worker
459*9880d681SAndroid Build Coastguard Worker**LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL
460*9880d681SAndroid Build Coastguard Worker  OS X Only: If enabled CMake will generate a target named
461*9880d681SAndroid Build Coastguard Worker  'install-xcode-toolchain'. This target will create a directory at
462*9880d681SAndroid Build Coastguard Worker  $CMAKE_INSTALL_PREFIX/Toolchains containing an xctoolchain directory which can
463*9880d681SAndroid Build Coastguard Worker  be used to override the default system tools.
464*9880d681SAndroid Build Coastguard Worker
465*9880d681SAndroid Build Coastguard Worker**LLVM_BUILD_LLVM_DYLIB**:BOOL
466*9880d681SAndroid Build Coastguard Worker  If enabled, the target for building the libLLVM shared library is added.
467*9880d681SAndroid Build Coastguard Worker  This library contains all of LLVM's components in a single shared library.
468*9880d681SAndroid Build Coastguard Worker  Defaults to OFF. This cannot be used in conjunction with BUILD_SHARED_LIBS.
469*9880d681SAndroid Build Coastguard Worker  Tools will only be linked to the libLLVM shared library if LLVM_LINK_LLVM_DYLIB
470*9880d681SAndroid Build Coastguard Worker  is also ON.
471*9880d681SAndroid Build Coastguard Worker  The components in the library can be customised by setting LLVM_DYLIB_COMPONENTS
472*9880d681SAndroid Build Coastguard Worker  to a list of the desired components.
473*9880d681SAndroid Build Coastguard Worker
474*9880d681SAndroid Build Coastguard Worker**LLVM_LINK_LLVM_DYLIB**:BOOL
475*9880d681SAndroid Build Coastguard Worker  If enabled, tools will be linked with the libLLVM shared library. Defaults
476*9880d681SAndroid Build Coastguard Worker  to OFF. Setting LLVM_LINK_LLVM_DYLIB to ON also sets LLVM_BUILD_LLVM_DYLIB
477*9880d681SAndroid Build Coastguard Worker  to ON.
478*9880d681SAndroid Build Coastguard Worker
479*9880d681SAndroid Build Coastguard Worker**BUILD_SHARED_LIBS**:BOOL
480*9880d681SAndroid Build Coastguard Worker  Flag indicating if each LLVM component (e.g. Support) is built as a shared
481*9880d681SAndroid Build Coastguard Worker  library (ON) or as a static library (OFF). Its default value is OFF. On
482*9880d681SAndroid Build Coastguard Worker  Windows, shared libraries may be used when building with MinGW, including
483*9880d681SAndroid Build Coastguard Worker  mingw-w64, but not when building with the Microsoft toolchain.
484*9880d681SAndroid Build Coastguard Worker
485*9880d681SAndroid Build Coastguard Worker  .. note:: BUILD_SHARED_LIBS is only recommended for use by LLVM developers.
486*9880d681SAndroid Build Coastguard Worker            If you want to build LLVM as a shared library, you should use the
487*9880d681SAndroid Build Coastguard Worker            ``LLVM_BUILD_LLVM_DYLIB`` option.
488*9880d681SAndroid Build Coastguard Worker
489*9880d681SAndroid Build Coastguard Worker**LLVM_OPTIMIZED_TABLEGEN**:BOOL
490*9880d681SAndroid Build Coastguard Worker  If enabled and building a debug or asserts build the CMake build system will
491*9880d681SAndroid Build Coastguard Worker  generate a Release build tree to build a fully optimized tablegen for use
492*9880d681SAndroid Build Coastguard Worker  during the build. Enabling this option can significantly speed up build times
493*9880d681SAndroid Build Coastguard Worker  especially when building LLVM in Debug configurations.
494*9880d681SAndroid Build Coastguard Worker
495*9880d681SAndroid Build Coastguard WorkerCMake Caches
496*9880d681SAndroid Build Coastguard Worker============
497*9880d681SAndroid Build Coastguard Worker
498*9880d681SAndroid Build Coastguard WorkerRecently LLVM and Clang have been adding some more complicated build system
499*9880d681SAndroid Build Coastguard Workerfeatures. Utilizing these new features often involves a complicated chain of
500*9880d681SAndroid Build Coastguard WorkerCMake variables passed on the command line. Clang provides a collection of CMake
501*9880d681SAndroid Build Coastguard Workercache scripts to make these features more approachable.
502*9880d681SAndroid Build Coastguard Worker
503*9880d681SAndroid Build Coastguard WorkerCMake cache files are utilized using CMake's -C flag:
504*9880d681SAndroid Build Coastguard Worker
505*9880d681SAndroid Build Coastguard Worker.. code-block:: console
506*9880d681SAndroid Build Coastguard Worker
507*9880d681SAndroid Build Coastguard Worker  $ cmake -C <path to cache file> <path to sources>
508*9880d681SAndroid Build Coastguard Worker
509*9880d681SAndroid Build Coastguard WorkerCMake cache scripts are processed in an isolated scope, only cached variables
510*9880d681SAndroid Build Coastguard Workerremain set when the main configuration runs. CMake cached variables do not reset
511*9880d681SAndroid Build Coastguard Workervariables that are already set unless the FORCE option is specified.
512*9880d681SAndroid Build Coastguard Worker
513*9880d681SAndroid Build Coastguard WorkerA few notes about CMake Caches:
514*9880d681SAndroid Build Coastguard Worker
515*9880d681SAndroid Build Coastguard Worker- Order of command line arguments is important
516*9880d681SAndroid Build Coastguard Worker
517*9880d681SAndroid Build Coastguard Worker  - -D arguments specified before -C are set before the cache is processed and
518*9880d681SAndroid Build Coastguard Worker    can be read inside the cache file
519*9880d681SAndroid Build Coastguard Worker  - -D arguments specified after -C are set after the cache is processed and
520*9880d681SAndroid Build Coastguard Worker    are unset inside the cache file
521*9880d681SAndroid Build Coastguard Worker
522*9880d681SAndroid Build Coastguard Worker- All -D arguments will override cache file settings
523*9880d681SAndroid Build Coastguard Worker- CMAKE_TOOLCHAIN_FILE is evaluated after both the cache file and the command
524*9880d681SAndroid Build Coastguard Worker  line arguments
525*9880d681SAndroid Build Coastguard Worker- It is recommended that all -D options should be specified *before* -C
526*9880d681SAndroid Build Coastguard Worker
527*9880d681SAndroid Build Coastguard WorkerFor more information about some of the advanced build configurations supported
528*9880d681SAndroid Build Coastguard Workervia Cache files see :doc:`AdvancedBuilds`.
529*9880d681SAndroid Build Coastguard Worker
530*9880d681SAndroid Build Coastguard WorkerExecuting the test suite
531*9880d681SAndroid Build Coastguard Worker========================
532*9880d681SAndroid Build Coastguard Worker
533*9880d681SAndroid Build Coastguard WorkerTesting is performed when the *check-all* target is built. For instance, if you are
534*9880d681SAndroid Build Coastguard Workerusing Makefiles, execute this command in the root of your build directory:
535*9880d681SAndroid Build Coastguard Worker
536*9880d681SAndroid Build Coastguard Worker.. code-block:: console
537*9880d681SAndroid Build Coastguard Worker
538*9880d681SAndroid Build Coastguard Worker  $ make check-all
539*9880d681SAndroid Build Coastguard Worker
540*9880d681SAndroid Build Coastguard WorkerOn Visual Studio, you may run tests by building the project "check-all".
541*9880d681SAndroid Build Coastguard WorkerFor more information about testing, see the :doc:`TestingGuide`.
542*9880d681SAndroid Build Coastguard Worker
543*9880d681SAndroid Build Coastguard WorkerCross compiling
544*9880d681SAndroid Build Coastguard Worker===============
545*9880d681SAndroid Build Coastguard Worker
546*9880d681SAndroid Build Coastguard WorkerSee `this wiki page <http://www.vtk.org/Wiki/CMake_Cross_Compiling>`_ for
547*9880d681SAndroid Build Coastguard Workergeneric instructions on how to cross-compile with CMake. It goes into detailed
548*9880d681SAndroid Build Coastguard Workerexplanations and may seem daunting, but it is not. On the wiki page there are
549*9880d681SAndroid Build Coastguard Workerseveral examples including toolchain files. Go directly to `this section
550*9880d681SAndroid Build Coastguard Worker<http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains>`_
551*9880d681SAndroid Build Coastguard Workerfor a quick solution.
552*9880d681SAndroid Build Coastguard Worker
553*9880d681SAndroid Build Coastguard WorkerAlso see the `LLVM-specific variables`_ section for variables used when
554*9880d681SAndroid Build Coastguard Workercross-compiling.
555*9880d681SAndroid Build Coastguard Worker
556*9880d681SAndroid Build Coastguard WorkerEmbedding LLVM in your project
557*9880d681SAndroid Build Coastguard Worker==============================
558*9880d681SAndroid Build Coastguard Worker
559*9880d681SAndroid Build Coastguard WorkerFrom LLVM 3.5 onwards both the CMake and autoconf/Makefile build systems export
560*9880d681SAndroid Build Coastguard WorkerLLVM libraries as importable CMake targets. This means that clients of LLVM can
561*9880d681SAndroid Build Coastguard Workernow reliably use CMake to develop their own LLVM-based projects against an
562*9880d681SAndroid Build Coastguard Workerinstalled version of LLVM regardless of how it was built.
563*9880d681SAndroid Build Coastguard Worker
564*9880d681SAndroid Build Coastguard WorkerHere is a simple example of a CMakeLists.txt file that imports the LLVM libraries
565*9880d681SAndroid Build Coastguard Workerand uses them to build a simple application ``simple-tool``.
566*9880d681SAndroid Build Coastguard Worker
567*9880d681SAndroid Build Coastguard Worker.. code-block:: cmake
568*9880d681SAndroid Build Coastguard Worker
569*9880d681SAndroid Build Coastguard Worker  cmake_minimum_required(VERSION 3.4.3)
570*9880d681SAndroid Build Coastguard Worker  project(SimpleProject)
571*9880d681SAndroid Build Coastguard Worker
572*9880d681SAndroid Build Coastguard Worker  find_package(LLVM REQUIRED CONFIG)
573*9880d681SAndroid Build Coastguard Worker
574*9880d681SAndroid Build Coastguard Worker  message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
575*9880d681SAndroid Build Coastguard Worker  message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
576*9880d681SAndroid Build Coastguard Worker
577*9880d681SAndroid Build Coastguard Worker  # Set your project compile flags.
578*9880d681SAndroid Build Coastguard Worker  # E.g. if using the C++ header files
579*9880d681SAndroid Build Coastguard Worker  # you will need to enable C++11 support
580*9880d681SAndroid Build Coastguard Worker  # for your compiler.
581*9880d681SAndroid Build Coastguard Worker
582*9880d681SAndroid Build Coastguard Worker  include_directories(${LLVM_INCLUDE_DIRS})
583*9880d681SAndroid Build Coastguard Worker  add_definitions(${LLVM_DEFINITIONS})
584*9880d681SAndroid Build Coastguard Worker
585*9880d681SAndroid Build Coastguard Worker  # Now build our tools
586*9880d681SAndroid Build Coastguard Worker  add_executable(simple-tool tool.cpp)
587*9880d681SAndroid Build Coastguard Worker
588*9880d681SAndroid Build Coastguard Worker  # Find the libraries that correspond to the LLVM components
589*9880d681SAndroid Build Coastguard Worker  # that we wish to use
590*9880d681SAndroid Build Coastguard Worker  llvm_map_components_to_libnames(llvm_libs support core irreader)
591*9880d681SAndroid Build Coastguard Worker
592*9880d681SAndroid Build Coastguard Worker  # Link against LLVM libraries
593*9880d681SAndroid Build Coastguard Worker  target_link_libraries(simple-tool ${llvm_libs})
594*9880d681SAndroid Build Coastguard Worker
595*9880d681SAndroid Build Coastguard WorkerThe ``find_package(...)`` directive when used in CONFIG mode (as in the above
596*9880d681SAndroid Build Coastguard Workerexample) will look for the ``LLVMConfig.cmake`` file in various locations (see
597*9880d681SAndroid Build Coastguard Workercmake manual for details).  It creates a ``LLVM_DIR`` cache entry to save the
598*9880d681SAndroid Build Coastguard Workerdirectory where ``LLVMConfig.cmake`` is found or allows the user to specify the
599*9880d681SAndroid Build Coastguard Workerdirectory (e.g. by passing ``-DLLVM_DIR=/usr/lib/cmake/llvm`` to
600*9880d681SAndroid Build Coastguard Workerthe ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
601*9880d681SAndroid Build Coastguard Worker
602*9880d681SAndroid Build Coastguard WorkerThis file is available in two different locations.
603*9880d681SAndroid Build Coastguard Worker
604*9880d681SAndroid Build Coastguard Worker* ``<INSTALL_PREFIX>/lib/cmake/llvm/LLVMConfig.cmake`` where
605*9880d681SAndroid Build Coastguard Worker  ``<INSTALL_PREFIX>`` is the install prefix of an installed version of LLVM.
606*9880d681SAndroid Build Coastguard Worker  On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``.
607*9880d681SAndroid Build Coastguard Worker
608*9880d681SAndroid Build Coastguard Worker* ``<LLVM_BUILD_ROOT>/lib/cmake/llvm/LLVMConfig.cmake`` where
609*9880d681SAndroid Build Coastguard Worker  ``<LLVM_BUILD_ROOT>`` is the root of the LLVM build tree. **Note: this is only
610*9880d681SAndroid Build Coastguard Worker  available when building LLVM with CMake.**
611*9880d681SAndroid Build Coastguard Worker
612*9880d681SAndroid Build Coastguard WorkerIf LLVM is installed in your operating system's normal installation prefix (e.g.
613*9880d681SAndroid Build Coastguard Workeron Linux this is usually ``/usr/``) ``find_package(LLVM ...)`` will
614*9880d681SAndroid Build Coastguard Workerautomatically find LLVM if it is installed correctly. If LLVM is not installed
615*9880d681SAndroid Build Coastguard Workeror you wish to build directly against the LLVM build tree you can use
616*9880d681SAndroid Build Coastguard Worker``LLVM_DIR`` as previously mentioned.
617*9880d681SAndroid Build Coastguard Worker
618*9880d681SAndroid Build Coastguard WorkerThe ``LLVMConfig.cmake`` file sets various useful variables. Notable variables
619*9880d681SAndroid Build Coastguard Workerinclude
620*9880d681SAndroid Build Coastguard Worker
621*9880d681SAndroid Build Coastguard Worker``LLVM_CMAKE_DIR``
622*9880d681SAndroid Build Coastguard Worker  The path to the LLVM CMake directory (i.e. the directory containing
623*9880d681SAndroid Build Coastguard Worker  LLVMConfig.cmake).
624*9880d681SAndroid Build Coastguard Worker
625*9880d681SAndroid Build Coastguard Worker``LLVM_DEFINITIONS``
626*9880d681SAndroid Build Coastguard Worker  A list of preprocessor defines that should be used when building against LLVM.
627*9880d681SAndroid Build Coastguard Worker
628*9880d681SAndroid Build Coastguard Worker``LLVM_ENABLE_ASSERTIONS``
629*9880d681SAndroid Build Coastguard Worker  This is set to ON if LLVM was built with assertions, otherwise OFF.
630*9880d681SAndroid Build Coastguard Worker
631*9880d681SAndroid Build Coastguard Worker``LLVM_ENABLE_EH``
632*9880d681SAndroid Build Coastguard Worker  This is set to ON if LLVM was built with exception handling (EH) enabled,
633*9880d681SAndroid Build Coastguard Worker  otherwise OFF.
634*9880d681SAndroid Build Coastguard Worker
635*9880d681SAndroid Build Coastguard Worker``LLVM_ENABLE_RTTI``
636*9880d681SAndroid Build Coastguard Worker  This is set to ON if LLVM was built with run time type information (RTTI),
637*9880d681SAndroid Build Coastguard Worker  otherwise OFF.
638*9880d681SAndroid Build Coastguard Worker
639*9880d681SAndroid Build Coastguard Worker``LLVM_INCLUDE_DIRS``
640*9880d681SAndroid Build Coastguard Worker  A list of include paths to directories containing LLVM header files.
641*9880d681SAndroid Build Coastguard Worker
642*9880d681SAndroid Build Coastguard Worker``LLVM_PACKAGE_VERSION``
643*9880d681SAndroid Build Coastguard Worker  The LLVM version. This string can be used with CMake conditionals, e.g., ``if
644*9880d681SAndroid Build Coastguard Worker  (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")``.
645*9880d681SAndroid Build Coastguard Worker
646*9880d681SAndroid Build Coastguard Worker``LLVM_TOOLS_BINARY_DIR``
647*9880d681SAndroid Build Coastguard Worker  The path to the directory containing the LLVM tools (e.g. ``llvm-as``).
648*9880d681SAndroid Build Coastguard Worker
649*9880d681SAndroid Build Coastguard WorkerNotice that in the above example we link ``simple-tool`` against several LLVM
650*9880d681SAndroid Build Coastguard Workerlibraries. The list of libraries is determined by using the
651*9880d681SAndroid Build Coastguard Worker``llvm_map_components_to_libnames()`` CMake function. For a list of available
652*9880d681SAndroid Build Coastguard Workercomponents look at the output of running ``llvm-config --components``.
653*9880d681SAndroid Build Coastguard Worker
654*9880d681SAndroid Build Coastguard WorkerNote that for LLVM < 3.5 ``llvm_map_components_to_libraries()`` was
655*9880d681SAndroid Build Coastguard Workerused instead of ``llvm_map_components_to_libnames()``. This is now deprecated
656*9880d681SAndroid Build Coastguard Workerand will be removed in a future version of LLVM.
657*9880d681SAndroid Build Coastguard Worker
658*9880d681SAndroid Build Coastguard Worker.. _cmake-out-of-source-pass:
659*9880d681SAndroid Build Coastguard Worker
660*9880d681SAndroid Build Coastguard WorkerDeveloping LLVM passes out of source
661*9880d681SAndroid Build Coastguard Worker------------------------------------
662*9880d681SAndroid Build Coastguard Worker
663*9880d681SAndroid Build Coastguard WorkerIt is possible to develop LLVM passes out of LLVM's source tree (i.e. against an
664*9880d681SAndroid Build Coastguard Workerinstalled or built LLVM). An example of a project layout is provided below.
665*9880d681SAndroid Build Coastguard Worker
666*9880d681SAndroid Build Coastguard Worker.. code-block:: none
667*9880d681SAndroid Build Coastguard Worker
668*9880d681SAndroid Build Coastguard Worker  <project dir>/
669*9880d681SAndroid Build Coastguard Worker      |
670*9880d681SAndroid Build Coastguard Worker      CMakeLists.txt
671*9880d681SAndroid Build Coastguard Worker      <pass name>/
672*9880d681SAndroid Build Coastguard Worker          |
673*9880d681SAndroid Build Coastguard Worker          CMakeLists.txt
674*9880d681SAndroid Build Coastguard Worker          Pass.cpp
675*9880d681SAndroid Build Coastguard Worker          ...
676*9880d681SAndroid Build Coastguard Worker
677*9880d681SAndroid Build Coastguard WorkerContents of ``<project dir>/CMakeLists.txt``:
678*9880d681SAndroid Build Coastguard Worker
679*9880d681SAndroid Build Coastguard Worker.. code-block:: cmake
680*9880d681SAndroid Build Coastguard Worker
681*9880d681SAndroid Build Coastguard Worker  find_package(LLVM REQUIRED CONFIG)
682*9880d681SAndroid Build Coastguard Worker
683*9880d681SAndroid Build Coastguard Worker  add_definitions(${LLVM_DEFINITIONS})
684*9880d681SAndroid Build Coastguard Worker  include_directories(${LLVM_INCLUDE_DIRS})
685*9880d681SAndroid Build Coastguard Worker
686*9880d681SAndroid Build Coastguard Worker  add_subdirectory(<pass name>)
687*9880d681SAndroid Build Coastguard Worker
688*9880d681SAndroid Build Coastguard WorkerContents of ``<project dir>/<pass name>/CMakeLists.txt``:
689*9880d681SAndroid Build Coastguard Worker
690*9880d681SAndroid Build Coastguard Worker.. code-block:: cmake
691*9880d681SAndroid Build Coastguard Worker
692*9880d681SAndroid Build Coastguard Worker  add_library(LLVMPassname MODULE Pass.cpp)
693*9880d681SAndroid Build Coastguard Worker
694*9880d681SAndroid Build Coastguard WorkerNote if you intend for this pass to be merged into the LLVM source tree at some
695*9880d681SAndroid Build Coastguard Workerpoint in the future it might make more sense to use LLVM's internal
696*9880d681SAndroid Build Coastguard Worker``add_llvm_loadable_module`` function instead by...
697*9880d681SAndroid Build Coastguard Worker
698*9880d681SAndroid Build Coastguard Worker
699*9880d681SAndroid Build Coastguard WorkerAdding the following to ``<project dir>/CMakeLists.txt`` (after
700*9880d681SAndroid Build Coastguard Worker``find_package(LLVM ...)``)
701*9880d681SAndroid Build Coastguard Worker
702*9880d681SAndroid Build Coastguard Worker.. code-block:: cmake
703*9880d681SAndroid Build Coastguard Worker
704*9880d681SAndroid Build Coastguard Worker  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
705*9880d681SAndroid Build Coastguard Worker  include(AddLLVM)
706*9880d681SAndroid Build Coastguard Worker
707*9880d681SAndroid Build Coastguard WorkerAnd then changing ``<project dir>/<pass name>/CMakeLists.txt`` to
708*9880d681SAndroid Build Coastguard Worker
709*9880d681SAndroid Build Coastguard Worker.. code-block:: cmake
710*9880d681SAndroid Build Coastguard Worker
711*9880d681SAndroid Build Coastguard Worker  add_llvm_loadable_module(LLVMPassname
712*9880d681SAndroid Build Coastguard Worker    Pass.cpp
713*9880d681SAndroid Build Coastguard Worker    )
714*9880d681SAndroid Build Coastguard Worker
715*9880d681SAndroid Build Coastguard WorkerWhen you are done developing your pass, you may wish to integrate it
716*9880d681SAndroid Build Coastguard Workerinto the LLVM source tree. You can achieve it in two easy steps:
717*9880d681SAndroid Build Coastguard Worker
718*9880d681SAndroid Build Coastguard Worker#. Copying ``<pass name>`` folder into ``<LLVM root>/lib/Transform`` directory.
719*9880d681SAndroid Build Coastguard Worker
720*9880d681SAndroid Build Coastguard Worker#. Adding ``add_subdirectory(<pass name>)`` line into
721*9880d681SAndroid Build Coastguard Worker   ``<LLVM root>/lib/Transform/CMakeLists.txt``.
722*9880d681SAndroid Build Coastguard Worker
723*9880d681SAndroid Build Coastguard WorkerCompiler/Platform-specific topics
724*9880d681SAndroid Build Coastguard Worker=================================
725*9880d681SAndroid Build Coastguard Worker
726*9880d681SAndroid Build Coastguard WorkerNotes for specific compilers and/or platforms.
727*9880d681SAndroid Build Coastguard Worker
728*9880d681SAndroid Build Coastguard WorkerMicrosoft Visual C++
729*9880d681SAndroid Build Coastguard Worker--------------------
730*9880d681SAndroid Build Coastguard Worker
731*9880d681SAndroid Build Coastguard Worker**LLVM_COMPILER_JOBS**:STRING
732*9880d681SAndroid Build Coastguard Worker  Specifies the maximum number of parallel compiler jobs to use per project
733*9880d681SAndroid Build Coastguard Worker  when building with msbuild or Visual Studio. Only supported for the Visual
734*9880d681SAndroid Build Coastguard Worker  Studio 2010 CMake generator. 0 means use all processors. Default is 0.
735