Lines Matching full:cmake
2 CMake Primer
10 anyone affiliated with the CMake project. This document may contain
18 The LLVM project and many of the core projects built on LLVM build using CMake.
19 This document aims to provide a brief overview of CMake for developers modifying
22 The official CMake language references is available in the cmake-language
23 manpage and `cmake-language online documentation
24 <https://cmake.org/cmake/help/v3.4/manual/cmake-language.7.html>`_.
29 CMake is a tool that reads script files in its own language that describe how a
30 software project builds. As CMake evaluates the scripts it constructs an
32 fully processed, if there are no errors, CMake will generate build files to
33 actually build the project. CMake supports generating build files for a variety
36 When a user runs CMake it performs a variety of checks similar to how autoconf
38 description scripts CMake caches values into the CMakeCache. This is useful
40 incremental development. CMake caching also has some drawbacks, but that will be
46 CMake's scripting language has a very simple grammar. Every language construct
48 primary types: language-defined (commands implemented in C++ in CMake), defined
49 functions, and defined macros. The CMake distribution also contains a suite of
50 CMake modules that contain definitions for useful functionality.
52 The example below is the full CMake build for building a C++ "Hello World"
53 program. The example uses only CMake language-defined functions.
55 .. code-block:: cmake
61 The CMake language provides control flow constructs in the form of foreach loops
65 .. code-block:: cmake
80 In CMake variables are "stringly" typed. All variables are represented as
82 and results in a literal substitution of the name for the value. CMake refers to
91 .. code-block:: cmake
98 pattern in CMake to conditionally set variables knowing that it will be used in
100 the LLVM CMake build system.
104 .. code-block:: cmake
118 In CMake lists are semi-colon delimited strings, and it is strongly advised that
122 .. code-block:: cmake
134 One of the more complicated patterns in CMake is lists of lists. Because a list
138 .. code-block:: cmake
148 .. code-block:: cmake
161 This pattern is used throughout CMake, the most common example is the compiler
162 flags options, which CMake refers to using the following variable expansions:
169 associated with them. The variable's type is used by CMake's UI tool to display
171 however CMake does have special handling for some variables such as PATH.
172 You can read more about the special handling in `CMake's set documentation
173 <https://cmake.org/cmake/help/v3.5/command/set.html#set-cache-entry>`_.
178 CMake inherently has a directory-based scoping. Setting a variable in a
180 Variables set in a CMake module that is included in a CMakeLists file will be
186 The CMake set command provides two scope-related options. PARENT_SCOPE sets a
192 In addition to directory-based scope, CMake functions also have their own scope.
198 Unlike C-based languages, CMake's loop and control flow blocks do not have
204 CMake features the same basic control flow constructs you would expect in any
206 CMake, control flow constructs are commands.
212 For the full documentation on the CMake if command go
213 `here <https://cmake.org/cmake/help/v3.4/command/if.html>`_. That resource is
216 In general CMake if blocks work the way you'd expect:
218 .. code-block:: cmake
228 The single most important thing to know about CMake's if blocks coming from a C
235 The most common form of the CMake ``foreach`` block is:
237 .. code-block:: cmake
246 .. code-block:: cmake
274 There is also a more modern CMake foreach syntax. The code below is equivalent
277 .. code-block:: cmake
308 CMake also supports ``while`` loops, although they are not widely used in LLVM.
316 Modules are CMake's vehicle for enabling code reuse. CMake modules are just
317 CMake script files. They can contain code to execute on include as well as
320 In CMake macros and functions are universally referred to as commands, and they
323 In LLVM we have several CMake modules that are included as part of our
326 CMake. We also rely on modules as a way of organizing the build system's
332 When defining a CMake command handling arguments is very useful. The examples
333 in this section will all use the CMake ``function`` block, but this all applies
336 CMake commands can have named arguments that are requried at every call site. In
339 invoked with extra arguments (beyond the named ones) CMake will store the full
342 providing a wrapper function for CMake's built in function ``add_dependencies``.
344 .. code-block:: cmake
354 CMake provides a module ``CMakeParseArguments`` which provides an implementation
357 arguments. CMake's official documentation for the module is in the
358 ``cmake-modules`` manpage, and is also available at the
359 `cmake-modules online documentation
360 <https://cmake.org/cmake/help/v3.4/module/CMakeParseArguments.html>`_.
363 As of CMake 3.5 the cmake_parse_arguments command has become a native command
376 The other difference between CMake functions and macros is how arguments are
381 .. code-block:: cmake
405 LLVM projects provide lots of wrappers around critical CMake built-in commands.
414 all defined in ``AddLLVM.cmake`` which is installed as part of the LLVM
427 CMake has a bunch of useful built-in commands. This document isn't going to
428 go into details about them because The CMake project has excellent
431 * `add_custom_command <https://cmake.org/cmake/help/v3.4/command/add_custom_command.html>`_
432 * `add_custom_target <https://cmake.org/cmake/help/v3.4/command/add_custom_target.html>`_
433 * `file <https://cmake.org/cmake/help/v3.4/command/file.html>`_
434 * `list <https://cmake.org/cmake/help/v3.4/command/list.html>`_
435 * `math <https://cmake.org/cmake/help/v3.4/command/math.html>`_
436 * `string <https://cmake.org/cmake/help/v3.4/command/string.html>`_
438 The full documentation for CMake commands is in the ``cmake-commands`` manpage
439 and available on `CMake's website <https://cmake.org/cmake/help/v3.4/manual/cmake-commands.7.html>`_