@@ -19,15 +19,15 @@ The LLVM project and many of the core projects built on LLVM build using CMake.
19
19
This document aims to provide a brief overview of CMake for developers modifying
20
20
LLVM projects or building their own projects on top of LLVM.
21
21
22
- The official CMake language references is available in the cmake-language
22
+ The official CMake language reference is available in the cmake-language
23
23
manpage and `cmake-language online documentation
24
24
<https://cmake.org/cmake/help/v3.4/manual/cmake-language.7.html> `_.
25
25
26
26
10,000 ft View
27
27
==============
28
28
29
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
30
+ software project builds. As CMake evaluates the scripts, it constructs an
31
31
internal representation of the software project. Once the scripts have been
32
32
fully processed, if there are no errors, CMake will generate build files to
33
33
actually build the project. CMake supports generating build files for a variety
@@ -58,8 +58,8 @@ program. The example uses only CMake language-defined functions.
58
58
project(HelloWorld)
59
59
add_executable(HelloWorld HelloWorld.cpp)
60
60
61
- The CMake language provides control flow constructs in the form of foreach loops
62
- and if blocks. To make the example above more complicated you could add an if
61
+ The CMake language provides control flow constructs in the form of `` foreach `` loops
62
+ and `` if `` blocks. To make the example above more complicated you could add an if
63
63
block to define "APPLE" when targeting Apple platforms:
64
64
65
65
.. code-block :: cmake
@@ -77,7 +77,7 @@ Variables, Types, and Scope
77
77
Dereferencing
78
78
-------------
79
79
80
- In CMake variables are "stringly" typed. All variables are represented as
80
+ In CMake, variables are "stringly" typed. All variables are represented as
81
81
strings throughout evaluation. Wrapping a variable in ``${} `` dereferences it
82
82
and results in a literal substitution of the name for the value. CMake refers to
83
83
this as "variable evaluation" in their documentation. Dereferences are performed
@@ -115,8 +115,8 @@ evaluated as empty before add_executable is given its arguments.
115
115
Lists
116
116
-----
117
117
118
- In CMake lists are semi-colon delimited strings, and it is strongly advised that
119
- you avoid using semi-colons in lists; it doesn't go smoothly. A few examples of
118
+ In CMake, lists are semicolon- delimited strings, and it is strongly advised that
119
+ you avoid using semicolons in lists; it doesn't go smoothly. A few examples of
120
120
defining lists:
121
121
122
122
.. code-block :: cmake
@@ -132,7 +132,7 @@ Lists of Lists
132
132
--------------
133
133
134
134
One of the more complicated patterns in CMake is lists of lists. Because a list
135
- cannot contain an element with a semi-colon to construct a list of lists you
135
+ cannot contain an element with a semicolon to construct a list of lists you
136
136
make a list of variable names that refer to other lists. For example:
137
137
138
138
.. code-block :: cmake
@@ -160,15 +160,15 @@ the list.
160
160
161
161
This pattern is used throughout CMake, the most common example is the compiler
162
162
flags options, which CMake refers to using the following variable expansions:
163
- CMAKE_${LANGUAGE}_FLAGS and CMAKE_${LANGUAGE}_FLAGS_${CMAKE_BUILD_TYPE}.
163
+ `` CMAKE_${LANGUAGE}_FLAGS `` and `` CMAKE_${LANGUAGE}_FLAGS_${CMAKE_BUILD_TYPE} `` .
164
164
165
165
Other Types
166
166
-----------
167
167
168
168
Variables that are cached or specified on the command line can have types
169
169
associated with them. The variable's type is used by CMake's UI tool to display
170
- the right input field. A variable's type generally doesn't impact evaluation,
171
- however CMake does have special handling for some variables such as PATH.
170
+ the right input field. A variable's type generally doesn't impact evaluation;
171
+ however, CMake does have special handling for some variables such as `` PATH `` .
172
172
You can read more about the special handling in `CMake's set documentation
173
173
<https://cmake.org/cmake/help/v3.5/command/set.html#set-cache-entry> `_.
174
174
@@ -183,11 +183,11 @@ set in the scope they are included from, and all subdirectories.
183
183
When a variable that is already set is set again in a subdirectory it overrides
184
184
the value in that scope and any deeper subdirectories.
185
185
186
- The CMake set command provides two scope-related options. PARENT_SCOPE sets a
187
- variable into the parent scope, and not the current scope. The CACHE option sets
186
+ The CMake set command provides two scope-related options. `` PARENT_SCOPE `` sets a
187
+ variable into the parent scope, and not the current scope. The `` CACHE `` option sets
188
188
the variable in the CMakeCache, which results in it being set in all scopes. The
189
- CACHE option will not set a variable that already exists in the CACHE unless the
190
- FORCE option is specified.
189
+ `` CACHE `` option will not set a variable that already exists in the `` CACHE `` unless the
190
+ `` FORCE `` option is specified.
191
191
192
192
In addition to directory-based scope, CMake functions also have their own scope.
193
193
This means variables set inside functions do not bleed into the parent scope.
@@ -213,7 +213,7 @@ If, ElseIf, Else
213
213
`here <https://cmake.org/cmake/help/v3.4/command/if.html >`_. That resource is
214
214
far more complete.
215
215
216
- In general CMake if blocks work the way you'd expect:
216
+ In general, CMake `` if `` blocks work the way you'd expect:
217
217
218
218
.. code-block :: cmake
219
219
@@ -225,7 +225,7 @@ In general CMake if blocks work the way you'd expect:
225
225
message("do other other stuff")
226
226
endif()
227
227
228
- The single most important thing to know about CMake's if blocks coming from a C
228
+ The single most important thing to know about CMake's `` if `` blocks coming from a C
229
229
background is that they do not have their own scope. Variables set inside
230
230
conditional blocks persist after the ``endif() ``.
231
231
@@ -317,20 +317,20 @@ Modules are CMake's vehicle for enabling code reuse. CMake modules are just
317
317
CMake script files. They can contain code to execute on include as well as
318
318
definitions for commands.
319
319
320
- In CMake macros and functions are universally referred to as commands, and they
320
+ In CMake, macros and functions are universally referred to as commands, and they
321
321
are the primary method of defining code that can be called multiple times.
322
322
323
323
In LLVM we have several CMake modules that are included as part of our
324
324
distribution for developers who don't build our project from source. Those
325
325
modules are the fundamental pieces needed to build LLVM-based projects with
326
326
CMake. We also rely on modules as a way of organizing the build system's
327
- functionality for maintainability and re-use within LLVM projects.
327
+ functionality for maintainability and reuse within LLVM projects.
328
328
329
329
Argument Handling
330
330
-----------------
331
331
332
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
333
+ in this section will all use the CMake ``function `` block, but this also applies
334
334
to the ``macro `` block as well.
335
335
336
336
CMake commands can have named arguments that are required at every call site. In
@@ -395,7 +395,7 @@ result in some unexpected behavior if using unreferenced variables. For example:
395
395
# c
396
396
# d
397
397
398
- Generally speaking this issue is uncommon because it requires using
398
+ Generally speaking, this issue is uncommon because it requires using
399
399
non-dereferenced variables with names that overlap in the parent scope, but it
400
400
is important to be aware of because it can lead to subtle bugs.
401
401
@@ -424,7 +424,7 @@ LLVM.
424
424
Useful Built-in Commands
425
425
========================
426
426
427
- CMake has a bunch of useful built-in commands. This document isn't going to
427
+ CMake has a collection of useful built-in commands. This document isn't going to
428
428
go into details about them because The CMake project has excellent
429
429
documentation. To highlight a few useful functions see:
430
430
0 commit comments