CMake.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. ========================
  2. Building LLVM with CMake
  3. ========================
  4. .. contents::
  5. :local:
  6. Introduction
  7. ============
  8. NOTE: this document describes the original LLVM project, not the DirectX
  9. Compiler. It's available only for informational purposes.
  10. `CMake <http://www.cmake.org/>`_ is a cross-platform build-generator tool. CMake
  11. does not build the project, it generates the files needed by your build tool
  12. (GNU make, Visual Studio, etc) for building LLVM.
  13. If you are really anxious about getting a functional LLVM build, go to the
  14. `Quick start`_ section. If you are a CMake novice, start on `Basic CMake usage`_
  15. and then go back to the `Quick start`_ once you know what you are doing. The
  16. `Options and variables`_ section is a reference for customizing your build. If
  17. you already have experience with CMake, this is the recommended starting point.
  18. .. _Quick start:
  19. Quick start
  20. ===========
  21. We use here the command-line, non-interactive CMake interface.
  22. #. `Download <http://www.cmake.org/cmake/resources/software.html>`_ and install
  23. CMake. Version 2.8.8 is the minimum required.
  24. #. Open a shell. Your development tools must be reachable from this shell
  25. through the PATH environment variable.
  26. #. Create a directory for containing the build. It is not supported to build
  27. LLVM on the source directory. cd to this directory:
  28. .. code-block:: console
  29. $ mkdir mybuilddir
  30. $ cd mybuilddir
  31. #. Execute this command on the shell replacing `path/to/llvm/source/root` with
  32. the path to the root of your LLVM source tree:
  33. .. code-block:: console
  34. $ cmake path/to/llvm/source/root
  35. CMake will detect your development environment, perform a series of test and
  36. generate the files required for building LLVM. CMake will use default values
  37. for all build parameters. See the `Options and variables`_ section for
  38. fine-tuning your build
  39. This can fail if CMake can't detect your toolset, or if it thinks that the
  40. environment is not sane enough. On this case make sure that the toolset that
  41. you intend to use is the only one reachable from the shell and that the shell
  42. itself is the correct one for you development environment. CMake will refuse
  43. to build MinGW makefiles if you have a POSIX shell reachable through the PATH
  44. environment variable, for instance. You can force CMake to use a given build
  45. tool, see the `Usage`_ section.
  46. #. After CMake has finished running, proceed to use IDE project files or start
  47. the build from the build directory:
  48. .. code-block:: console
  49. $ cmake --build .
  50. The ``--build`` option tells ``cmake`` to invoke the underlying build
  51. tool (``make``, ``ninja``, ``xcodebuild``, ``msbuild``, etc).
  52. The underlying build tool can be invoked directly either of course, but
  53. the ``--build`` option is portable.
  54. #. After LLVM has finished building, install it from the build directory:
  55. .. code-block:: console
  56. $ cmake --build . --target install
  57. The ``--target`` option with ``install`` parameter in addition to
  58. the ``--build`` option tells ``cmake`` to build the ``install`` target.
  59. It is possible to set a different install prefix at installation time
  60. by invoking the ``cmake_install.cmake`` script generated in the
  61. build directory:
  62. .. code-block:: console
  63. $ cmake -DCMAKE_INSTALL_PREFIX=/tmp/llvm -P cmake_install.cmake
  64. .. _Basic CMake usage:
  65. .. _Usage:
  66. Basic CMake usage
  67. =================
  68. This section explains basic aspects of CMake, mostly for explaining those
  69. options which you may need on your day-to-day usage.
  70. CMake comes with extensive documentation in the form of html files and on the
  71. cmake executable itself. Execute ``cmake --help`` for further help options.
  72. CMake requires to know for which build tool it shall generate files (GNU make,
  73. Visual Studio, Xcode, etc). If not specified on the command line, it tries to
  74. guess it based on you environment. Once identified the build tool, CMake uses
  75. the corresponding *Generator* for creating files for your build tool. You can
  76. explicitly specify the generator with the command line option ``-G "Name of the
  77. generator"``. For knowing the available generators on your platform, execute
  78. .. code-block:: console
  79. $ cmake --help
  80. This will list the generator's names at the end of the help text. Generator's
  81. names are case-sensitive. Example:
  82. .. code-block:: console
  83. $ cmake -G "Visual Studio 11" path/to/llvm/source/root
  84. For a given development platform there can be more than one adequate
  85. generator. If you use Visual Studio "NMake Makefiles" is a generator you can use
  86. for building with NMake. By default, CMake chooses the more specific generator
  87. supported by your development environment. If you want an alternative generator,
  88. you must tell this to CMake with the ``-G`` option.
  89. .. todo::
  90. Explain variables and cache. Move explanation here from #options section.
  91. .. _Options and variables:
  92. Options and variables
  93. =====================
  94. Variables customize how the build will be generated. Options are boolean
  95. variables, with possible values ON/OFF. Options and variables are defined on the
  96. CMake command line like this:
  97. .. code-block:: console
  98. $ cmake -DVARIABLE=value path/to/llvm/source
  99. You can set a variable after the initial CMake invocation for changing its
  100. value. You can also undefine a variable:
  101. .. code-block:: console
  102. $ cmake -UVARIABLE path/to/llvm/source
  103. Variables are stored on the CMake cache. This is a file named ``CMakeCache.txt``
  104. on the root of the build directory. Do not hand-edit it.
  105. Variables are listed here appending its type after a colon. It is correct to
  106. write the variable and the type on the CMake command line:
  107. .. code-block:: console
  108. $ cmake -DVARIABLE:TYPE=value path/to/llvm/source
  109. Frequently-used CMake variables
  110. -------------------------------
  111. Here are some of the CMake variables that are used often, along with a
  112. brief explanation and LLVM-specific notes. For full documentation, check the
  113. CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
  114. **CMAKE_BUILD_TYPE**:STRING
  115. Sets the build type for ``make`` based generators. Possible values are
  116. Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
  117. the user sets the build type with the IDE settings.
  118. **CMAKE_INSTALL_PREFIX**:PATH
  119. Path where LLVM will be installed if "make install" is invoked or the
  120. "INSTALL" target is built.
  121. **LLVM_LIBDIR_SUFFIX**:STRING
  122. Extra suffix to append to the directory where libraries are to be
  123. installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
  124. to install libraries to ``/usr/lib64``.
  125. **CMAKE_C_FLAGS**:STRING
  126. Extra flags to use when compiling C source files.
  127. **CMAKE_CXX_FLAGS**:STRING
  128. Extra flags to use when compiling C++ source files.
  129. **BUILD_SHARED_LIBS**:BOOL
  130. Flag indicating if shared libraries will be built. Its default value is
  131. OFF. Shared libraries are not supported on Windows and not recommended on the
  132. other OSes.
  133. .. _LLVM-specific variables:
  134. LLVM-specific variables
  135. -----------------------
  136. **LLVM_TARGETS_TO_BUILD**:STRING
  137. Semicolon-separated list of targets to build, or *all* for building all
  138. targets. Case-sensitive. Defaults to *all*. Example:
  139. ``-DLLVM_TARGETS_TO_BUILD="X86;PowerPC"``.
  140. **LLVM_BUILD_TOOLS**:BOOL
  141. Build LLVM tools. Defaults to ON. Targets for building each tool are generated
  142. in any case. You can build an tool separately by invoking its target. For
  143. example, you can build *llvm-as* with a makefile-based system executing *make
  144. llvm-as* on the root of your build directory.
  145. **LLVM_INCLUDE_TOOLS**:BOOL
  146. Generate build targets for the LLVM tools. Defaults to ON. You can use that
  147. option for disabling the generation of build targets for the LLVM tools.
  148. **LLVM_BUILD_EXAMPLES**:BOOL
  149. Build LLVM examples. Defaults to OFF. Targets for building each example are
  150. generated in any case. See documentation for *LLVM_BUILD_TOOLS* above for more
  151. details.
  152. **LLVM_INCLUDE_EXAMPLES**:BOOL
  153. Generate build targets for the LLVM examples. Defaults to ON. You can use that
  154. option for disabling the generation of build targets for the LLVM examples.
  155. **LLVM_BUILD_TESTS**:BOOL
  156. Build LLVM unit tests. Defaults to OFF. Targets for building each unit test
  157. are generated in any case. You can build a specific unit test with the target
  158. *UnitTestNameTests* (where at this time *UnitTestName* can be ADT, Analysis,
  159. ExecutionEngine, JIT, Support, Transform, VMCore; see the subdirectories of
  160. *unittests* for an updated list.) It is possible to build all unit tests with
  161. the target *UnitTests*.
  162. **LLVM_INCLUDE_TESTS**:BOOL
  163. Generate build targets for the LLVM unit tests. Defaults to ON. You can use
  164. that option for disabling the generation of build targets for the LLVM unit
  165. tests.
  166. **LLVM_APPEND_VC_REV**:BOOL
  167. Append version control revision info (svn revision number or Git revision id)
  168. to LLVM version string (stored in the PACKAGE_VERSION macro). For this to work
  169. cmake must be invoked before the build. Defaults to OFF.
  170. **LLVM_ENABLE_THREADS**:BOOL
  171. Build with threads support, if available. Defaults to ON.
  172. **LLVM_ENABLE_CXX1Y**:BOOL
  173. Build in C++1y mode, if available. Defaults to OFF.
  174. **LLVM_ENABLE_ASSERTIONS**:BOOL
  175. Enables code assertions. Defaults to ON if and only if ``CMAKE_BUILD_TYPE``
  176. is *Debug*.
  177. **LLVM_ENABLE_EH**:BOOL
  178. Build LLVM with exception handling support. This is necessary if you wish to
  179. link against LLVM libraries and make use of C++ exceptions in your own code
  180. that need to propagate through LLVM code. Defaults to OFF.
  181. **LLVM_ENABLE_PIC**:BOOL
  182. Add the ``-fPIC`` flag for the compiler command-line, if the compiler supports
  183. this flag. Some systems, like Windows, do not need this flag. Defaults to ON.
  184. **LLVM_ENABLE_RTTI**:BOOL
  185. Build LLVM with run time type information. Defaults to OFF.
  186. **LLVM_ENABLE_WARNINGS**:BOOL
  187. Enable all compiler warnings. Defaults to ON.
  188. **LLVM_ENABLE_PEDANTIC**:BOOL
  189. Enable pedantic mode. This disables compiler specific extensions, if
  190. possible. Defaults to ON.
  191. **LLVM_ENABLE_WERROR**:BOOL
  192. Stop and fail build, if a compiler warning is triggered. Defaults to OFF.
  193. **LLVM_ABI_BREAKING_CHECKS**:STRING
  194. Used to decide if LLVM should be built with ABI breaking checks or
  195. not. Allowed values are `WITH_ASSERTS` (default), `FORCE_ON` and
  196. `FORCE_OFF`. `WITH_ASSERTS` turns on ABI breaking checks in an
  197. assertion enabled build. `FORCE_ON` (`FORCE_OFF`) turns them on
  198. (off) irrespective of whether normal (`NDEBUG` based) assertions are
  199. enabled or not. A version of LLVM built with ABI breaking checks
  200. is not ABI compatible with a version built without it.
  201. **LLVM_BUILD_32_BITS**:BOOL
  202. Build 32-bits executables and libraries on 64-bits systems. This option is
  203. available only on some 64-bits unix systems. Defaults to OFF.
  204. **LLVM_TARGET_ARCH**:STRING
  205. LLVM target to use for native code generation. This is required for JIT
  206. generation. It defaults to "host", meaning that it shall pick the architecture
  207. of the machine where LLVM is being built. If you are cross-compiling, set it
  208. to the target architecture name.
  209. **LLVM_TABLEGEN**:STRING
  210. Full path to a native TableGen executable (usually named ``tblgen``). This is
  211. intended for cross-compiling: if the user sets this variable, no native
  212. TableGen will be created.
  213. **LLVM_LIT_ARGS**:STRING
  214. Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
  215. By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
  216. others.
  217. **LLVM_LIT_TOOLS_DIR**:PATH
  218. The path to GnuWin32 tools for tests. Valid on Windows host. Defaults to "",
  219. then Lit seeks tools according to %PATH%. Lit can find tools(eg. grep, sort,
  220. &c) on LLVM_LIT_TOOLS_DIR at first, without specifying GnuWin32 to %PATH%.
  221. **LLVM_ENABLE_FFI**:BOOL
  222. Indicates whether LLVM Interpreter will be linked with Foreign Function
  223. Interface library. If the library or its headers are installed on a custom
  224. location, you can set the variables FFI_INCLUDE_DIR and
  225. FFI_LIBRARY_DIR. Defaults to OFF.
  226. **LLVM_EXTERNAL_{CLANG,LLD,POLLY}_SOURCE_DIR**:PATH
  227. Path to ``{Clang,lld,Polly}``\'s source directory. Defaults to
  228. ``tools/{clang,lld,polly}``. ``{Clang,lld,Polly}`` will not be built when it
  229. is empty or it does not point to a valid path.
  230. **LLVM_USE_OPROFILE**:BOOL
  231. Enable building OProfile JIT support. Defaults to OFF
  232. **LLVM_USE_INTEL_JITEVENTS**:BOOL
  233. Enable building support for Intel JIT Events API. Defaults to OFF
  234. **LLVM_ENABLE_ZLIB**:BOOL
  235. Build with zlib to support compression/uncompression in LLVM tools.
  236. Defaults to ON.
  237. **LLVM_USE_SANITIZER**:STRING
  238. Define the sanitizer used to build LLVM binaries and tests. Possible values
  239. are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
  240. and ``Address;Undefined``. Defaults to empty string.
  241. **LLVM_PARALLEL_COMPILE_JOBS**:STRING
  242. Define the maximum number of concurrent compilation jobs.
  243. **LLVM_PARALLEL_LINK_JOBS**:STRING
  244. Define the maximum number of concurrent link jobs.
  245. **LLVM_BUILD_DOCS**:BOOL
  246. Enables all enabled documentation targets (i.e. Doxgyen and Sphinx targets) to
  247. be built as part of the normal build. If the ``install`` target is run then
  248. this also enables all built documentation targets to be installed. Defaults to
  249. OFF.
  250. **LLVM_ENABLE_DOXYGEN**:BOOL
  251. Enables the generation of browsable HTML documentation using doxygen.
  252. Defaults to OFF.
  253. **LLVM_ENABLE_DOXYGEN_QT_HELP**:BOOL
  254. Enables the generation of a Qt Compressed Help file. Defaults to OFF.
  255. This affects the make target ``doxygen-llvm``. When enabled, apart from
  256. the normal HTML output generated by doxygen, this will produce a QCH file
  257. named ``org.llvm.qch``. You can then load this file into Qt Creator.
  258. This option is only useful in combination with ``-DLLVM_ENABLE_DOXYGEN=ON``;
  259. otherwise this has no effect.
  260. **LLVM_DOXYGEN_QCH_FILENAME**:STRING
  261. The filename of the Qt Compressed Help file that will be generated when
  262. ``-DLLVM_ENABLE_DOXYGEN=ON`` and
  263. ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON`` are given. Defaults to
  264. ``org.llvm.qch``.
  265. This option is only useful in combination with
  266. ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``;
  267. otherwise this has no effect.
  268. **LLVM_DOXYGEN_QHP_NAMESPACE**:STRING
  269. Namespace under which the intermediate Qt Help Project file lives. See `Qt
  270. Help Project`_
  271. for more information. Defaults to "org.llvm". This option is only useful in
  272. combination with ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``; otherwise
  273. this has no effect.
  274. **LLVM_DOXYGEN_QHP_CUST_FILTER_NAME**:STRING
  275. See `Qt Help Project`_ for
  276. more information. Defaults to the CMake variable ``${PACKAGE_STRING}`` which
  277. is a combination of the package name and version string. This filter can then
  278. be used in Qt Creator to select only documentation from LLVM when browsing
  279. through all the help files that you might have loaded. This option is only
  280. useful in combination with ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``;
  281. otherwise this has no effect.
  282. .. _Qt Help Project: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters
  283. **LLVM_DOXYGEN_QHELPGENERATOR_PATH**:STRING
  284. The path to the ``qhelpgenerator`` executable. Defaults to whatever CMake's
  285. ``find_program()`` can find. This option is only useful in combination with
  286. ``-DLLVM_ENABLE_DOXYGEN_QT_HELP=ON``; otherwise this has no
  287. effect.
  288. **LLVM_DOXYGEN_SVG**:BOOL
  289. Uses .svg files instead of .png files for graphs in the Doxygen output.
  290. Defaults to OFF.
  291. **LLVM_ENABLE_SPHINX**:BOOL
  292. If enabled CMake will search for the ``sphinx-build`` executable and will make
  293. the ``SPHINX_OUTPUT_HTML`` and ``SPHINX_OUTPUT_MAN`` CMake options available.
  294. Defaults to OFF.
  295. **SPHINX_EXECUTABLE**:STRING
  296. The path to the ``sphinx-build`` executable detected by CMake.
  297. **SPHINX_OUTPUT_HTML**:BOOL
  298. If enabled (and ``LLVM_ENABLE_SPHINX`` is enabled) then the targets for
  299. building the documentation as html are added (but not built by default unless
  300. ``LLVM_BUILD_DOCS`` is enabled). There is a target for each project in the
  301. source tree that uses sphinx (e.g. ``docs-llvm-html``, ``docs-clang-html``
  302. and ``docs-lld-html``). Defaults to ON.
  303. **SPHINX_OUTPUT_MAN**:BOOL
  304. If enabled (and ``LLVM_ENABLE_SPHINX`` is enabled) the targets for building
  305. the man pages are added (but not built by default unless ``LLVM_BUILD_DOCS``
  306. is enabled). Currently the only target added is ``docs-llvm-man``. Defaults
  307. to ON.
  308. **SPHINX_WARNINGS_AS_ERRORS**:BOOL
  309. If enabled then sphinx documentation warnings will be treated as
  310. errors. Defaults to ON.
  311. Executing the test suite
  312. ========================
  313. Testing is performed when the *check* target is built. For instance, if you are
  314. using makefiles, execute this command while on the top level of your build
  315. directory:
  316. .. code-block:: console
  317. $ make check
  318. On Visual Studio, you may run tests to build the project "check".
  319. Cross compiling
  320. ===============
  321. See `this wiki page <http://www.vtk.org/Wiki/CMake_Cross_Compiling>`_ for
  322. generic instructions on how to cross-compile with CMake. It goes into detailed
  323. explanations and may seem daunting, but it is not. On the wiki page there are
  324. several examples including toolchain files. Go directly to `this section
  325. <http://www.vtk.org/Wiki/CMake_Cross_Compiling#Information_how_to_set_up_various_cross_compiling_toolchains>`_
  326. for a quick solution.
  327. Also see the `LLVM-specific variables`_ section for variables used when
  328. cross-compiling.
  329. Embedding LLVM in your project
  330. ==============================
  331. From LLVM 3.5 onwards both the CMake and autoconf/Makefile build systems export
  332. LLVM libraries as importable CMake targets. This means that clients of LLVM can
  333. now reliably use CMake to develop their own LLVM based projects against an
  334. installed version of LLVM regardless of how it was built.
  335. Here is a simple example of CMakeLists.txt file that imports the LLVM libraries
  336. and uses them to build a simple application ``simple-tool``.
  337. .. code-block:: cmake
  338. cmake_minimum_required(VERSION 2.8.8)
  339. project(SimpleProject)
  340. find_package(LLVM REQUIRED CONFIG)
  341. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  342. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  343. # Set your project compile flags.
  344. # E.g. if using the C++ header files
  345. # you will need to enable C++11 support
  346. # for your compiler.
  347. include_directories(${LLVM_INCLUDE_DIRS})
  348. add_definitions(${LLVM_DEFINITIONS})
  349. # Now build our tools
  350. add_executable(simple-tool tool.cpp)
  351. # Find the libraries that correspond to the LLVM components
  352. # that we wish to use
  353. llvm_map_components_to_libnames(llvm_libs support core irreader)
  354. # Link against LLVM libraries
  355. target_link_libraries(simple-tool ${llvm_libs})
  356. The ``find_package(...)`` directive when used in CONFIG mode (as in the above
  357. example) will look for the ``LLVMConfig.cmake`` file in various locations (see
  358. cmake manual for details). It creates a ``LLVM_DIR`` cache entry to save the
  359. directory where ``LLVMConfig.cmake`` is found or allows the user to specify the
  360. directory (e.g. by passing ``-DLLVM_DIR=/usr/share/llvm/cmake`` to
  361. the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``).
  362. This file is available in two different locations.
  363. * ``<INSTALL_PREFIX>/share/llvm/cmake/LLVMConfig.cmake`` where
  364. ``<INSTALL_PREFIX>`` is the install prefix of an installed version of LLVM.
  365. On Linux typically this is ``/usr/share/llvm/cmake/LLVMConfig.cmake``.
  366. * ``<LLVM_BUILD_ROOT>/share/llvm/cmake/LLVMConfig.cmake`` where
  367. ``<LLVM_BUILD_ROOT>`` is the root of the LLVM build tree. **Note this only
  368. available when building LLVM with CMake**
  369. If LLVM is installed in your operating system's normal installation prefix (e.g.
  370. on Linux this is usually ``/usr/``) ``find_package(LLVM ...)`` will
  371. automatically find LLVM if it is installed correctly. If LLVM is not installed
  372. or you wish to build directly against the LLVM build tree you can use
  373. ``LLVM_DIR`` as previously mentioned.
  374. The ``LLVMConfig.cmake`` file sets various useful variables. Notable variables
  375. include
  376. ``LLVM_CMAKE_DIR``
  377. The path to the LLVM CMake directory (i.e. the directory containing
  378. LLVMConfig.cmake).
  379. ``LLVM_DEFINITIONS``
  380. A list of preprocessor defines that should be used when building against LLVM.
  381. ``LLVM_ENABLE_ASSERTIONS``
  382. This is set to ON if LLVM was built with assertions, otherwise OFF.
  383. ``LLVM_ENABLE_EH``
  384. This is set to ON if LLVM was built with exception handling (EH) enabled,
  385. otherwise OFF.
  386. ``LLVM_ENABLE_RTTI``
  387. This is set to ON if LLVM was built with run time type information (RTTI),
  388. otherwise OFF.
  389. ``LLVM_INCLUDE_DIRS``
  390. A list of include paths to directories containing LLVM header files.
  391. ``LLVM_PACKAGE_VERSION``
  392. The LLVM version. This string can be used with CMake conditionals. E.g. ``if
  393. (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.5")``.
  394. ``LLVM_TOOLS_BINARY_DIR``
  395. The path to the directory containing the LLVM tools (e.g. ``llvm-as``).
  396. Notice that in the above example we link ``simple-tool`` against several LLVM
  397. libraries. The list of libraries is determined by using the
  398. ``llvm_map_components_to_libnames()`` CMake function. For a list of available
  399. components look at the output of running ``llvm-config --components``.
  400. Note that for LLVM < 3.5 ``llvm_map_components_to_libraries()`` was
  401. used instead of ``llvm_map_components_to_libnames()``. This is now deprecated
  402. and will be removed in a future version of LLVM.
  403. .. _cmake-out-of-source-pass:
  404. Developing LLVM passes out of source
  405. ------------------------------------
  406. It is possible to develop LLVM passes out of LLVM's source tree (i.e. against an
  407. installed or built LLVM). An example of a project layout is provided below.
  408. .. code-block:: none
  409. <project dir>/
  410. |
  411. CMakeLists.txt
  412. <pass name>/
  413. |
  414. CMakeLists.txt
  415. Pass.cpp
  416. ...
  417. Contents of ``<project dir>/CMakeLists.txt``:
  418. .. code-block:: cmake
  419. find_package(LLVM REQUIRED CONFIG)
  420. add_definitions(${LLVM_DEFINITIONS})
  421. include_directories(${LLVM_INCLUDE_DIRS})
  422. add_subdirectory(<pass name>)
  423. Contents of ``<project dir>/<pass name>/CMakeLists.txt``:
  424. .. code-block:: cmake
  425. add_library(LLVMPassname MODULE Pass.cpp)
  426. Note if you intend for this pass to be merged into the LLVM source tree at some
  427. point in the future it might make more sense to use LLVM's internal
  428. add_llvm_loadable_module function instead by...
  429. Adding the following to ``<project dir>/CMakeLists.txt`` (after
  430. ``find_package(LLVM ...)``)
  431. .. code-block:: cmake
  432. list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
  433. include(AddLLVM)
  434. And then changing ``<project dir>/<pass name>/CMakeLists.txt`` to
  435. .. code-block:: cmake
  436. add_llvm_loadable_module(LLVMPassname
  437. Pass.cpp
  438. )
  439. When you are done developing your pass, you may wish to integrate it
  440. into LLVM source tree. You can achieve it in two easy steps:
  441. #. Copying ``<pass name>`` folder into ``<LLVM root>/lib/Transform`` directory.
  442. #. Adding ``add_subdirectory(<pass name>)`` line into
  443. ``<LLVM root>/lib/Transform/CMakeLists.txt``.
  444. Compiler/Platform-specific topics
  445. =================================
  446. Notes for specific compilers and/or platforms.
  447. Microsoft Visual C++
  448. --------------------
  449. **LLVM_COMPILER_JOBS**:STRING
  450. Specifies the maximum number of parallell compiler jobs to use per project
  451. when building with msbuild or Visual Studio. Only supported for the Visual
  452. Studio 2010 CMake generator. 0 means use all processors. Default is 0.